Skip to content

Instantly share code, notes, and snippets.

@silkentrance
Last active December 15, 2021 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silkentrance/0aa9f9e5be445181c5745d8a6281ef97 to your computer and use it in GitHub Desktop.
Save silkentrance/0aa9f9e5be445181c5745d8a6281ef97 to your computer and use it in GitHub Desktop.
Anti Log4Shell Nginx Configuration
# Based Upon
This is a dumbed down version of the below provided code which seems to be overly complex to me.
https://www.infiniroot.com/blog/1155/using-nginx-lua-script-mitigate-log4shell-cve-2021-44228-vulnerability
lua_need_request_body on;
# simplified LUA block to detect, block and log Log4Shell attacks
rewrite_by_lua_block {
local h, err = ngx.req.get_headers()
if err then
ngx.log(ngx.ERR, "error: ", err)
return
end
for k, v in pairs(h) do
if v then
s = tostring(v)
if string.match(string.lower(s), "${") then
ngx.log(ngx.ERR, 'Found potential log4j attack in header ' .. k .. ':' .. tostring(v))
ngx.exit(ngx.HTTP_FORBIDDEN)
end
end
end
}
server {
...
include anti_log4shell.conf;
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment