owasp-modsecurity / ModSecurity

ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
https://www.modsecurity.org
Apache License 2.0
8.16k stars 1.6k forks source link

modsecurity v3 ,Centos 7, the lua not work #2409

Closed HL123 closed 4 years ago

HL123 commented 4 years ago

Describe the bug i use nginx modsecurity ,want to support lua .while i have edit modsecurity.conf as follows

SecRuleScript "/usr/local/lua/exec.lua" "block"

OR

SecRule ARGS:testparam "@contains test" "phase:2,id:113,pass,exec:/usr/local/lua/exec.lua,auditlog"

OR

SecRule ARGS:p attack "phase:2,id:113,block,exec:/usr/local/lua/exec.lua" .

the exec lua as follows :

!/usr/local/bin/lua

function main() m.log(1,"Starting script execution \n") local fileHandle = assert(io.open('/usr/local/lua/test.lua','a')) fileHandle:write("---MODSECURITY ---\n") m.log(1,"Script execution finished\n")

file = io.open("test.lua", "a")
file:write("--test")
file:close()

end

while the exec.lua not work ,and there have no error . so I hava no idea about it.

And

I have compile nginx and modsecurity as follows

./configure \ --prefix=/usr/local/nginx \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-pcre \ --with-pcre-jit \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-debug \ --add-module=/usr/local/src//ngx_devel_kit-0.3.0 \ --add-module=/usr/local/src/lua-nginx-module-0.10.9rc7 \ --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" ;

ModSecurity - for Linux

Mandatory dependencies

and i have upgrade the lua to 5.2

thanks.

HL123 commented 4 years ago

i have know throw debug ,thanks .

and i will try do it .

[1601277762] [/?testparam=test] [2] Failed to execute lua script: /usr/local/lua/exec.lua (before main) - /usr/local/lua/exec.lua:20: attempt to index global 'file' (a nil value)

swzaaaaaaa commented 1 year ago

May I ask how you resolved this issue? Mine, too. The instructions were written but did not take effect.