ngx_http_js_challenge_module
ngx_http_js_challenge_module copied to clipboard
Build errors with GCC 4.8.5
sir make error .
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_challenge_string’:
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:261:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration]
SHA1((unsigned char *) buf, (size_t) (sizeof(int32_t) + addr.len + secret.len), md);
^~~~
cc1: all warnings being treated as errors
objs/Makefile:1203: recipe for target 'objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o' failed
make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1
make[1]: Leaving directory '/root/nginx-1.16.1'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2
Hi, can you give me the output of nginx -V please?
before error , i fix 。 but not this error
/root/ngx_http_js_challenge_module/ngx_http_js_challenge.c: In function ‘get_cookie’: /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:306:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for (ngx_uint_t i = 0; i < r->headers_in.cookies.nelts; i++) {
how to use c99 mode make ?
this error is fix
just add
CFLAGS=-std=c99
To the top of your makefile, or you can make the code compliant with C90 (as LukeN suggests.)
I modified the build script with the CFLAGS=-std=c99 variable, thank you
use c99 mode i have make no pass
[root@nginx-test nginx-1.16.1]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
[root@nginx-test nginx-1.16.1]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-openssl=openssl-1.1.1d --add-module=/root/ngx_http_js_challenge_module
/root/ngx_http_js_challenge_module/ngx_http_js_challenge.c: In function ‘ngx_http_js_challenge_handler’: src/core/ngx_string.h:40:57: error: expected expression before ‘)’ token #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:56: error: invalid operands to binary * (have ‘struct ngx_command_t *’ and ‘struct ngx_command_t *’) #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: initialization from incompatible pointer type [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: (near initialization for ‘(anonymous).data’) [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ src/core/ngx_string.h:40:57: warning: passing argument 2 of ‘get_cookie’ from incompatible pointer type [enabled by default] #define ngx_string(str) { sizeof(str) - 1, (u_char *) str } ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:344:43: note: in expansion of macro ‘ngx_string’ int ret = get_cookie(r, &((ngx_str_t) ngx_string("res")), &response); ^ /root/ngx_http_js_challenge_module/ngx_http_js_challenge.c:301:5: note: expected ‘struct ngx_str_t ’ but argument is of type ‘struct ngx_command_t ()[1]’ int get_cookie(ngx_http_request_t *r, ngx_str_t *name, ngx_str_t *value) { ^ make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-1.16.1' make: *** [build] Error 2
@w796933 please let me know if you can build with the latest commit
yes . latest commit build
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:54:17: error: initializer element is not constant str_js_challenge, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:54:17: error: (near initialization for ‘ngx_http_js_challenge_commands[0].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:62:17: error: initializer element is not constant str_js_challenge_bucket_duration, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:62:17: error: (near initialization for ‘ngx_http_js_challenge_commands[1].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:70:17: error: initializer element is not constant str_js_challenge_bucket_duration, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:70:17: error: (near initialization for ‘ngx_http_js_challenge_commands[2].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:78:17: error: initializer element is not constant str_js_challenge_html, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:78:17: error: (near initialization for ‘ngx_http_js_challenge_commands[3].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:86:17: error: initializer element is not constant str_js_challenge_title, ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:86:17: error: (near initialization for ‘ngx_http_js_challenge_commands[4].name’) /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_cookie’: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:303:5: error: ‘for’ loop initial declarations are only allowed in C99 mode for (ngx_uint_t i = 0; i < r->headers_in.cookies.nelts; i++) { ^ /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:303:5: note: use option -std=c99 or -std=gnu99 to compile your code /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: At top level: /root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:47:18: error: ‘str_js_challenge_secret’ defined but not used [-Werror=unused-variable] static ngx_str_t str_js_challenge_secret = ngx_string("js_challenge_secret"); ^ cc1: all warnings being treated as errors make[1]: *** [objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-1.16.1' make: *** [modules] Error 2 [root@nginx-test ngx_http_js_challenge_module]# cat build.sh #!/bin/bash
if [ -z ${NGINX_PATH+x} ]; then echo "Please set the NGINX_PATH variable"; exit fi
MODULE_PATH=$(pwd)/ CONFIG_ARGS=$(nginx -V 2>&1 | tail -n 1 | cut -c 21- | sed 's/--add-dynamic-module=.*//g') CONFIG_ARGS="${CONFIG_ARGS} --add-dynamic-module=${MODULE_PATH}" echo $CONFIG_ARGS
( cd ${NGINX_PATH} || exit bash -c "./configure ${CONFIG_ARGS}" CFLAGS=-std=c99 make modules -j "$(nproc)" )
Sorry about that, can you try again with the latest commit? I can't really test it myself because I don't have the same GCC version
my build os is centos 7 64bit
you build os is ?
i try other os build it .
I am building it with Debian testing (Debian 5.4.19-1 (2020-02-13) x86_64 GNU/Linux)
Debian 5.4.19-1 is to old os .
5.4.19-1 is the kernel version, I am using "bullseye" (Debian 11)
okay . i test debian 11 . so thanks .
I made the code C90 compatible, with the last commit, you should no longer see the C99 errors. @w796933 Please let me know if this works
okay . i test it . how can auto drop JavaScript challenge no pass ip address .
how can auto drop JavaScript challenge no pass ip address .
Can you reformulate the question? I don't understand what you mean at all
js verification failed attack IP. How to automatically block access ? how to use iptables auto drop access ?
how to use iptables auto drop access ?
I'm not sure, you would need to ask someone who is more experienced than me with iptables.
i use debian 11 run build.sh this error .
make -f objs/Makefile modules
make[1]: Entering directory '/root/nginx-1.16.1'
cc -c -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘get_challenge_string’:
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:253:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration]
SHA1((unsigned char *) buf, (size_t) (sizeof(int32_t) + addr.len + secret.len), md);
^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:1219: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1
make[1]: Leaving directory '/root/nginx-1.16.1'
make: *** [Makefile:14: modules] Error 2
@w796933 please let me know if you still have this error after the last commit
use last commit the some error .
make -f objs/Makefile modules
make[1]: Entering directory '/root/nginx-1.16.1'
cc -c -fPIC -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function ‘verify_response’:
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:287:5: error: implicit declaration of function ‘SHA1’ [-Werror=implicit-function-declaration]
SHA1((unsigned char *) response.data, response.len, md);
^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:1219: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1
make[1]: Leaving directory '/root/nginx-1.16.1'
make: *** [Makefile:14: modules] Error 2
Sorry about that. Can you retry with the latest commit?
sir . how to add white ip or url or ua ?
how to add white ip or url or ua ?
You can do that with basic nginx configuration, this is out of the scope of this project
i mean how to add white ip or url or ua . because if enabled js challenge module , will deny app load . and deny search engines to crawl.
The compilation has been unsuccessful, what versions of gcc and openssl?
The compilation has been unsuccessful
Please send the logs
what versions of gcc and openssl?
It should work with any recent version of GCC. OpenSSL is not required
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules
-o objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c: In function 'verify_response':
/root/ngx_http_js_challenge_module//ngx_http_js_challenge.c:285:5: error: implicit declaration of function 'SHA1' [-Werror=implicit-function-declaration]
SHA1((unsigned char *) response.data, response.len, md);
^~~~
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:1203: objs/addon/ngx_http_js_challenge_module/ngx_http_js_challenge.o] Error 1
make[1]: Leaving directory '/root/nginx-1.16.1'
make: *** [Makefile:8: build] Error 2