Skip to content
Snippets Groups Projects
Commit d2a8d120 authored by Silvan's avatar Silvan
Browse files

fix infinite loop&modify shell

parent d922fd1a
No related branches found
No related tags found
No related merge requests found
......@@ -42,7 +42,7 @@ sudo ./UnblockNeteaseMusic
本应用获取music.163.com的IP是通过本机直接查询,非nodejs版本请求music.httpdns.c.163.com获取
已知:
1. windows版本的网易云音乐需要在应用内设置代理 127.0.0.1 端口 80
1. windows版本的网易云音乐需要在应用内 设置代理 Http地址为「HttpProxy」下任意地址 端口 80
2. Linux 客户端 (1.2 版本以上需要在终端启动增加 --ignore-certificate-errors 参数)
3. 咪咕源貌似部分宽带无法使用
# 感谢
......
CurrentVersion=0.1.5
CurrentVersion=0.1.6
Project=github.com/cnsilvan/UnblockNeteaseMusic
Path="$Project/version"
ExecName="UnblockNeteaseMusic"
......
......@@ -9,12 +9,16 @@ caKey="$basepath/ca.key"
# 生成 CA 私钥
openssl genrsa -out "${caKey}" 2048
# 生成 CA 证书
openssl req -x509 -new -nodes -key "${caKey}" -sha256 -days 1825 -out "${caCrt}" -subj "/C=CN/CN=UnblockNeteaseMusic Root CA/O=UnblockNeteaseMusic"
openssl req -x509 -new -nodes -key "${caKey}" -sha256 -days 825 -out "${caCrt}" -subj "/C=CN/CN=UnblockNeteaseMusic Root CA/O=UnblockNeteaseMusic"
# 生成服务器私钥
openssl genrsa -out "${serverKey}" 2048
# 生成证书签发请求
openssl req -new -sha256 -key "${serverKey}" -out "${serverCsr}" -subj "/C=CN/L=Hangzhou/O=NetEase (Hangzhou) Network Co., Ltd/OU=IT Dept./CN=*.music.163.com"
# 使用 CA 签发服务器证书
touch "${extFile}"
echo "subjectAltName=DNS:music.163.com,DNS:*.music.163.com" >"${extFile}"
openssl x509 -req -extfile "${extFile}" -days 1825 -in "${serverCsr}" -CA "${caCrt}" -CAkey "${caKey}" -CAcreateserial -out "${serverCrt}"
echo "authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
extendedKeyUsage=serverAuth,OCSPSigning
subjectAltName=DNS:music.163.com,DNS:*.music.163.com" >"${extFile}"
openssl x509 -req -extfile "${extFile}" -days 825 -in "${serverCsr}" -CA "${caCrt}" -CAkey "${caKey}" -CAcreateserial -out "${serverCrt}"
......@@ -19,9 +19,31 @@ import (
type HttpHandler struct{}
var localhost = map[string]int{}
func InitProxy() {
fmt.Println("-------------------Init Proxy-------------------")
address := "0.0.0.0:"
addrs, err := net.InterfaceAddrs()
if err != nil {
panic(err)
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
localhost[ipnet.IP.String()] = 1
}
if ipnet.IP.To16() != nil {
localhost[ipnet.IP.To16().String()] = 1
}
}
}
var localhostKey []string
for k, _ := range localhost {
localhostKey = append(localhostKey, k)
}
fmt.Println("Http Proxy:")
fmt.Println(strings.Join(localhostKey, " , "))
go startTlsServer(address+strconv.Itoa(*config.TLSPort), *config.CertFile, *config.KeyFile, &HttpHandler{})
go startServer(address+strconv.Itoa(*config.Port), &HttpHandler{})
}
......@@ -47,7 +69,14 @@ func (h *HttpHandler) ServeHTTP(resp http.ResponseWriter, request *http.Request)
if len(request.URL.Scheme) > 0 {
scheme = request.URL.Scheme + "://"
}
if strings.Contains(hostStr, "localhost") || strings.Contains(hostStr, "127.0.0.1") || strings.Contains(hostStr, "0.0.0.0") || (len(path) > 1 && strings.Count(path, "/") > 1 && bytes.EqualFold(left, right)) {
infinite := false
for k, _ := range localhost {
if strings.Contains(hostStr, k) {
infinite = true
break
}
}
if infinite || strings.Contains(hostStr, "localhost") || strings.Contains(hostStr, "127.0.0.1") || strings.Contains(hostStr, "0.0.0.0") || (len(path) > 1 && strings.Count(path, "/") > 1 && bytes.EqualFold(left, right)) {
//cause infinite loop
requestURI = scheme + request.Host
if bytes.EqualFold(left, right) {
......@@ -162,6 +191,11 @@ func (h *HttpHandler) ServeHTTP(resp http.ResponseWriter, request *http.Request)
}
}
func proxyConnectLocalhost(rw http.ResponseWriter, req *http.Request) {
fmt.Printf("Local Received request %s %s %s\n",
req.Method,
req.Host,
req.RemoteAddr,
)
hij, ok := rw.(http.Hijacker)
if !ok {
fmt.Println("HTTP Server does not support hijacking")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment