Last active
December 15, 2021 18:23
-
-
Save silkentrance/0aa9f9e5be445181c5745d8a6281ef97 to your computer and use it in GitHub Desktop.
Anti Log4Shell Nginx Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
... | |
include anti_log4shell.conf; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment