/
tcp_frp.go
55 lines (48 loc) · 1.19 KB
/
tcp_frp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package judge
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/zhzyker/dismap/internal/proxy"
"github.com/zhzyker/dismap/pkg/logger"
"strings"
)
func TcpFrp(result map[string]interface{}, Args map[string]interface{}) bool {
timeout := Args["FlagTimeout"].(int)
host := result["host"].(string)
port := result["port"].(int)
conn, err := proxy.ConnProxyTcp(host, port, timeout)
if logger.DebugError(err) {
return false
}
msg := "\x00\x01\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00"
_, err = conn.Write([]byte(msg))
if logger.DebugError(err) {
return false
}
reply := make([]byte, 256)
_, _ = conn.Read(reply)
if conn != nil {
_ = conn.Close()
}
var buffer [256]byte
if bytes.Equal(reply[:], buffer[:]) {
return false
} else if hex.EncodeToString(reply[0:12]) != "000100020000000100000000" {
return false
}
result["protocol"] = "frp"
result["banner.string"] = frpByteToStringParse(reply[0:12])
result["banner.byte"] = reply
return true
}
func frpByteToStringParse(p []byte) string {
var w []string
var res string
for i := 0; i < len(p); i++ {
asciiTo16 := fmt.Sprintf("\\x%s", hex.EncodeToString(p[i:i+1]))
w = append(w,asciiTo16)
}
res = strings.Join(w, "")
return res
}