• 當前位置:首頁 > IT技術 > Web編程 > 正文

    【web安全】隱藏nginx頭文件信息
    2021-10-11 15:06:56

    摘要

    Nginx作為開源web中間件,被廣泛應用。因此源編譯或者yum安裝,都會帶有其原有的nginx版本。很容易被針對,因此,通過修改nginx的源碼。隱藏nginx版本和頭部信息,保障nginx的安全。操作如下:

    1.修改nginx.h文件

    位置為:/nginx-1.20.0/src/core
    修改內容如下:

    #ifndef _NGINX_H_INCLUDED_
    #define _NGINX_H_INCLUDED_
    
    
    #define nginx_version      1020000
    #define NGINX_VERSION      "1.0"                        //我修改的內容
    #define NGINX_VER          "zsdweb/" NGINX_VERSION      //我修改的內容
    
    #ifdef NGX_BUILD
    #define NGINX_VER_BUILD    NGINX_VER " (" NGX_BUILD ")"
    #else
    #define NGINX_VER_BUILD    NGINX_VER
    #endif
    
    #define NGINX_VAR          "ZSDWEB"                       //我修改的內容
    #define NGX_OLDPID_EXT     ".oldbin"
    
    
    #endif /* _NGINX_H_INCLUDED_ */
    

    2.修改ngx_http_header_filter_module.c

    通過linux命令參看:

    [root@localhost http]# cat ngx_http_header_filter_module.c |grep server_string
    static u_char ngx_http_server_string[] = "Server: ZSDWEB" CRLF;
    

    上述可以看到我修改的version為zsdweb,版本為1.0

    3.源編譯和make

    ./configure --prefix=/opt/nginx --with-http_gunzip_module --with-http_gzip_static_module --with-pcre=/opt/soft/pcre-8.44 --with-zlib=/opt/soft/zlib-1.2.11 --with-http_ssl_module --with-openssl=/opt/soft/openssl-1.1.1l
    make
    

    4.生成的二進制文件

    [root@localhost objs]# pwd
    /opt/soft/nginx-1.20.0/objs
    您在 /var/spool/mail/root 中有郵件
    [root@localhost objs]# ls -lrt
    總用量 7924
    drwxr-xr-x 9 root root    4096 4月  27 14:42 src
    -rw-r--r-- 1 root root     657 10月 11 14:02 ngx_auto_headers.h
    -rw-r--r-- 1 root root   17671 10月 11 14:02 autoconf.err
    -rw-r--r-- 1 root root    6287 10月 11 14:02 ngx_modules.c
    -rw-r--r-- 1 root root   43098 10月 11 14:02 Makefile
    -rw-r--r-- 1 root root    7334 10月 11 14:02 ngx_auto_config.h
    -rw-r--r-- 1 root root   35312 10月 11 14:06 ngx_modules.o
    -rwxr-xr-x 1 root root 7967912 10月 11 14:06 nginx
    

    5.查看版本信息

    [root@localhost objs]# ./nginx -v
    nginx version: zsdweb/1.0
    

    至此,nginx編譯成功,替換原來的版本軟件即可。修改源碼也不是那么的困難,也都是一個個c語言文件組測。

    本文摘自 :https://www.cnblogs.com/

    開通會員,享受整站包年服務
    国产呦精品一区二区三区网站|久久www免费人咸|精品无码人妻一区二区|久99久热只有精品国产15|中文字幕亚洲无线码