zoukankan      html  css  js  c++  java
  • 【web安全】隐藏nginx头文件信息

    摘要

    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语言文件组测。

  • 相关阅读:
    Tomcat配置和Spring MVC配置
    Servlet学习总结
    Servlet 工作原理
    Spring MVC
    Spring的线程安全
    Struts的线程安全
    反射实现AOP动态代理
    Spring AOP的实现原理
    JAVA基础加强(张孝祥)_类加载器、分析代理类的作用与原理及AOP概念、分析JVM动态生成的类、实现类似Spring的可配置的AOP框架
    Spring bean初始化以及管理
  • 原文地址:https://www.cnblogs.com/zhangshengdong/p/15393213.html
Copyright © 2011-2022 走看看