Command Injection Writeup
PortSwigger
Last updated
PortSwigger
Last updated
Pham Quoc Trung
BurpSuite
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.
Ở bài này, đề bài đã gợi ý cho mình rằng có lỗi OS Command Injection ở trong chức năng check stock. Sau khi ấn vào details của một sản phẩm thì mình đã tìm ra chức năng này ở dưới
Mục tiêu là chúng ta phải chạy được câu lệnh whoami
thông qua chức năng này. Khi ấn vào nút , request gửi đi sẽ có dạng như này
Vì chức năng này bị lỗi command injection nên mình nghĩ phía server sẽ thực hiện câu lệnh dạng ./checkStock 2 1
. Mình sẽ thử điền storeId thành 1|whoami
, khi này thì câu lệnh sẽ có dạng kiểu ./checkStock 2 1|whoami
, và câu lệnh whoami
sẽ được khởi chạy.
Như dự đoán thì mình đã thấy được output của câu lệnh whoami
và bài lab đã được hoàn thành
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.
Ở đây, mình biết rằng có lỗi OS Command Injection ở trong chức năng feedback. Mục tiêu của mình là phải tạo ra 10 giây delay sử dụng lỗi này.
Thử submit một feedback lên, mình có được request như sau với thời gian response là 244ms
Nếu hệ thống sử dụng lệnh linux cho chức năng này thì name, subject và message khả năng cao sẽ định dạng string và khó có thể khai thác Command Injection. Mình sẽ thử inject vào email, và ở đây mình sử dụng lệnh sleep 10
để có thể làm server delay mất 10s response.
Response trả về đã mất hơn 10 giây, và mình hoàn thành được bài lab
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:
/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.
Ở lab này thì lỗi vẫn y như lab trước, chỉ khác là giờ mình phải đọc được output của lệnh whoami
. Ở đây mình sẽ sử dụng kĩ thuật redirect output bằng kí tự >
. Nôm na là khi mình chạy lệnh whoami > output.txt
, kết quả trả về sẽ được lưu vào file output.txt
. Tuy nhiên thì mình phải tìm ra đường dẫn để lưu file này sao cho mình có thể truy cập được trên trang web
Ở đây, khi tiến hành intercept và ấn vào một vật phẩm bất kì, mình thấy có một request sử dụng để get image của vật phẩm đó
Vậy mình có thể lưu output của lệnh whoami
vào thư mục chứa ảnh và sau đó sử dụng request trên để đọc nội dung của file output. Theo gợi ý đề bài thì thư mục chứa ảnh sẽ nằm ở /var/www/images/
. Mình sẽ tiến hành khai thác xem sao
Đọc file output.txt
Kia chính là nội dung của lệnh whoami
trả về. Mình đã hoàn thành được bài lab
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.
Note
To prevent the Academy platform being used to attack third parties, our firewall blocks interactions between the labs and arbitrary external systems. To solve the lab, you must use Burp Collaborator's default public server.
Ở lab này, việc redirect output là không thể làm được nữa, ta sẽ phải dùng kĩ thuật OAST. Mình sẽ sử dụng Burpsuite Collaborators để khai thác xem sao. Trước hết mình sẽ check xem hệ thống có thể gửi request tới Collaborators không
Ở phía Collaborator, mình đã thấy có các gói tin DNS được gửi tới
Vì lab này chỉ yêu cầu gửi lookup thôi nên mình đã hoàn thành bài lab
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.
Note
To prevent the Academy platform being used to attack third parties, our firewall blocks interactions between the labs and arbitrary external systems. To solve the lab, you must use Burp Collaborator's default public server.
Bài này thì vẫn y nguyên bài trước, chỉ là giờ mình phải lấy được tên của user hiện tại và submit để hoàn thành bài lab. Mình sẽ sử dụng kí tự backtick ` để có thể lấy được giá trị của một câu lệnh.
Sau khi gửi đi, đây là gói tin được gửi về Collaborator
Có thể thấy rằng giá trị của lệnh whoami
đã được in ra. Giờ chỉ cần submit là mình sẽ hoàn thành bài lab này
© 2024,Pham Quoc Trung. All rights reserved.