Skip to content

Commit 9612110

Browse files
authored
add SSH forward
1 parent e0859c4 commit 9612110

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type Config struct {
2525
Address string `json:"address"`
2626
Host string `json:"host"`
2727
} `json:"forward"`
28+
SSH string `json:"ssh"`
2829
}
2930

3031
var c Config
@@ -79,6 +80,12 @@ func handler(conn net.Conn) {
7980
fmt.Println("fail to get first packet")
8081
return
8182
}
83+
84+
if ( string(p)[:3] == "SSH" ) {
85+
fmt.Println("SSH packet")
86+
sshForward(conn, p)
87+
return
88+
}
8289
if ( strings.Index(string(p), "Host") < 0) {
8390
fmt.Println("not a http packet")
8491
return
@@ -116,6 +123,19 @@ func handler(conn net.Conn) {
116123
}
117124
}
118125

126+
func sshForward(conn net.Conn, p []byte) {
127+
forward, err := net.Dial("tcp", c.SSH)
128+
if err != nil {
129+
fmt.Println("connect failed: ", err)
130+
return
131+
}
132+
defer forward.Close()
133+
conn.SetReadDeadline(time.Time{})
134+
forward.Write(p)
135+
go io.Copy(forward, conn)
136+
io.Copy(conn, forward)
137+
}
138+
119139
func HostInject(p []byte, host string) []byte {
120140
var i int
121141
flag := 0
@@ -164,7 +184,6 @@ func readJson() {
164184
}
165185

166186
func getJson() {
167-
// url := "http://rss.1m.ee/porter.html"
168187
timeout := time.Duration(10 * time.Second)
169188
client := &http.Client{Timeout: timeout}
170189
req, _ := http.NewRequest("GET", config, nil)

porter

7.05 MB
Binary file not shown.

0 commit comments

Comments
 (0)