-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ESNI-WorkSpace
committed
Nov 29, 2022
1 parent
9506952
commit 8f3617a
Showing
11 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"esni-shell-channel/util" | ||
"fmt" | ||
"io" | ||
"net" | ||
"os" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
func main() { | ||
|
||
conn, err := net.Dial("tcp", "1.15.135.178:"+os.Args[3]) | ||
if err != nil { | ||
fmt.Println("create connection failed: ", err) | ||
} | ||
defer conn.Close() | ||
|
||
sshConfig := util.GetSSHConf(os.Args[1], os.Args[2]) | ||
cli, err := ssh.Dial("tcp", "localhost:22", sshConfig) | ||
if err != nil { | ||
fmt.Println("client create failed: ", err) | ||
} | ||
defer cli.Close() | ||
|
||
session, err := cli.Dial("tcp", "localhost:22") | ||
if err != nil { | ||
fmt.Println("session create failed: ", err) | ||
} | ||
defer session.Close() | ||
|
||
go func() { | ||
for { | ||
io.Copy(conn, session) | ||
} | ||
}() | ||
|
||
go func() { | ||
for { | ||
io.Copy(session, conn) | ||
} | ||
}() | ||
|
||
for { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
func main() { | ||
|
||
fmt.Println("Enter your pwd") | ||
password, _ := terminal.ReadPassword(0) | ||
fmt.Println(password) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module esni-shell-channel | ||
|
||
go 1.13 | ||
|
||
require golang.org/x/crypto v0.3.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/crypto v0.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU= | ||
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= | ||
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE= | ||
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= | ||
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A= | ||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= | ||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= | ||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM= | ||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package main | ||
|
||
import ( | ||
"esni-shell-channel/util" | ||
"io" | ||
"log" | ||
"net" | ||
"os" | ||
|
||
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
var ( | ||
serverAddress = "www.zhanmabigdata.top" | ||
password = os.Args[2] | ||
user = os.Args[1] | ||
msgPort = "9658" | ||
cliport = "9656" | ||
) | ||
|
||
func handleMsg(conn net.Conn) { | ||
|
||
buffer := make([]byte, 1) | ||
log.Println("staring to wait message") | ||
|
||
for { | ||
n, err := conn.Read(buffer) | ||
if err != nil { | ||
log.Println("some problems occurred while handling message: ", err) | ||
return | ||
} | ||
|
||
if n != 0 { | ||
if 1 == int(buffer[0]) { | ||
|
||
log.Println("receiving a create request, staring to create local ssh connection") | ||
conn, err := net.Dial("tcp", serverAddress+":"+cliport) | ||
if err != nil { | ||
log.Println("some problems occurred while creating local ssh connection: ", err) | ||
return | ||
} | ||
defer conn.Close() | ||
log.Println("successfully created local ssh client") | ||
|
||
log.Println("staring to create local ssh client") | ||
sshConfig := util.GetSSHConf(user, password) | ||
cli, err := ssh.Dial("tcp", "localhost:22", sshConfig) | ||
if err != nil { | ||
log.Println("some problems occurred while creating local ssh client: ", err) | ||
} | ||
defer cli.Close() | ||
log.Println("successfully created local ssh client") | ||
|
||
log.Println("staring to listen connection from server") | ||
session, err := cli.Dial("tcp", "localhost:22") | ||
if err != nil { | ||
log.Println("some problems occurred while lisenling connection:", err) | ||
} | ||
defer session.Close() | ||
|
||
go func() { | ||
log.Printf("creating channel local to %s", conn.LocalAddr()) | ||
for { | ||
n, err := io.Copy(session, conn) | ||
if err != nil { | ||
log.Println("some error occurred during forwarding", err) | ||
session.Close() | ||
conn.Close() | ||
return | ||
|
||
} | ||
if n == 0 { | ||
log.Println("got 0 bytes from connection or local ssh client") | ||
log.Printf("try to close the channel local to %s", conn.LocalAddr()) | ||
session.Close() | ||
conn.Close() | ||
return | ||
} | ||
} | ||
|
||
}() | ||
|
||
go func() { | ||
for { | ||
log.Printf("creating channel %s to local", conn.LocalAddr()) | ||
n, err := io.Copy(conn, session) | ||
if err != nil { | ||
log.Println("some error occurred during forwarding", err) | ||
session.Close() | ||
conn.Close() | ||
return | ||
|
||
} | ||
if n == 0 { | ||
log.Println("got 0 bytes from connection or local ssh client") | ||
log.Printf("try to close the channel %s to local", conn.LocalAddr()) | ||
session.Close() | ||
conn.Close() | ||
return | ||
} | ||
} | ||
}() | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
func main() { | ||
|
||
log.Println("staring esni-shell-channel multi client now") | ||
|
||
msgConn, err := net.Dial("tcp", serverAddress+":"+msgPort) | ||
if err != nil { | ||
log.Println("error to created message connection: %v", err) | ||
return | ||
} | ||
log.Println("successfully created message connection") | ||
defer msgConn.Close() | ||
|
||
log.Println("starring to handle message connection") | ||
go handleMsg(msgConn) | ||
|
||
// lock | ||
for { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"net" | ||
"time" | ||
) | ||
|
||
func forward(conn1 net.Conn, conn2 net.Conn) { | ||
fmt.Printf("create channel forward %s to %s \n", conn1.LocalAddr(), conn2.LocalAddr()) | ||
for { | ||
n, err := io.Copy(conn1, conn2) | ||
if err != nil { | ||
fmt.Println("server forward error: ", err) | ||
fmt.Printf("try to close channel forward %s to %s \n", conn1.LocalAddr(), conn2.LocalAddr()) | ||
conn1.Close() | ||
conn2.Close() | ||
return | ||
} | ||
if n == 0 { | ||
fmt.Println("server forward got 0 bytes: ", err) | ||
fmt.Printf("try to close channel forward %s to %s \n", conn1.LocalAddr(), conn2.LocalAddr()) | ||
conn1.Close() | ||
conn2.Close() | ||
return | ||
} | ||
|
||
} | ||
} | ||
|
||
func handleSession(mconn net.Conn, sListener net.Listener, cListener net.Listener) { | ||
|
||
for { | ||
sccon, err := sListener.Accept() | ||
if err != nil { | ||
fmt.Println("got some error when listen server connection: ", err) | ||
continue | ||
} | ||
|
||
// send message | ||
n, err := mconn.Write([]byte{byte(1)}) | ||
if err != nil || n == 0 { | ||
fmt.Println("got some error when send message: ", err) | ||
continue | ||
} | ||
|
||
// create connection with client | ||
time.Sleep(1) | ||
conc, err := cListener.Accept() | ||
if err != nil { | ||
fmt.Println("create connection with client error: ", err) | ||
continue | ||
} | ||
|
||
// start forward | ||
go forward(sccon, conc) | ||
go forward(conc, sccon) | ||
|
||
} | ||
|
||
} | ||
|
||
// 9656 9657 9658 | ||
func main() { | ||
|
||
msgListener, err := net.Listen("tcp", "ESNI-Master:9658") | ||
if err != nil { | ||
log.Println("Fail to create message connection listener: ", err) | ||
return | ||
} | ||
defer msgListener.Close() | ||
fmt.Println("Establish message listener successfully") | ||
|
||
fmt.Println("Wating for first response from message connection") | ||
msgConn, err := msgListener.Accept() | ||
if err != nil { | ||
fmt.Println("Fail to establish message connection: ", err) | ||
return | ||
} | ||
defer msgConn.Close() | ||
|
||
fmt.Println("Establish session listener successfully") | ||
sessionListener, err := net.Listen("tcp", "ESNI-Master:9657") | ||
if err != nil { | ||
fmt.Println("create session listener error: ", err) | ||
return | ||
} | ||
defer sessionListener.Close() | ||
|
||
fmt.Println("create cli listener success") | ||
clilListener, err := net.Listen("tcp", "ESNI-Master:9656") | ||
if err != nil { | ||
fmt.Println("create client listener error: ", err) | ||
return | ||
} | ||
defer clilListener.Close() | ||
|
||
go handleSession(msgConn, sessionListener, clilListener) | ||
|
||
// lock | ||
for { | ||
} | ||
|
||
} |
Oops, something went wrong.