Hi!请登陆

nginx 自定义 Server Name 隐藏软件名 自定义版本

2021-3-19 111 3/19

How To Customize Your Nginx Server Name

  • src/core/nginx.h
    #define NGINX_VER "MYWS/“ NGINX_VERSION
  • http/ngx_http_special_response.c
    "<hr><center>MYWS</center>” CRLF
  • http/ngx_http_header_filter_module.c
    static u_char ngx_http_server_string[] = "Server: MYWS" CRLF;
  • src/http/v2/ngx_http_v2_filter_module.c
    static const u_char nginx[5] = "\x84\xd1\xcf\x96\xef";

第4点是为http2 做的修改.字节码生成:

package main

import (
    "fmt"
    "golang.org/x/net/http2/hpack"
)

func main() {
    fmt.Println("nginx", "→", Encode("ithothub"))
    fmt.Println("nginx", "→", Encode("nginx"))
    fmt.Println("apache", "→", Encode("apache"))
}

func Encode(s string) string {
    var result string

    hd := hpack.AppendHuffmanString(nil, s)
    hl := hpack.HuffmanEncodeLength(s) | 0x80

    result += RenderByte(byte(hl))

    for _, b := range hd {
        result += RenderByte(b)
    }

    return result
}

func Decode(s string) string {
    data := []byte(s)
    result, _ := hpack.HuffmanDecodeToString(data[1:])
    return result
}

func RenderByte(b byte) string {
    return fmt.Sprintf("\\x%x", b)
}

 

 

Tag:

相关推荐