Use commandline options
parent
a019fa6da5
commit
64b8ee7aaa
|
@ -1,17 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"github.com/serverwentdown/bypass"
|
"github.com/serverwentdown/bypass"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var listen string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.StringVar(&listen, "listen", ":8000", "listen on ip and port")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
conf := &socks5.Config{}
|
conf := &socks5.Config{}
|
||||||
server, err := socks5.New(conf)
|
server, err := socks5.New(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := server.ListenAndServe("tcp", "127.0.0.1:8000"); err != nil {
|
if err := server.ListenAndServe("tcp", listen); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
33
request.go
33
request.go
|
@ -1,13 +1,14 @@
|
||||||
package socks5
|
package socks5
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"math/big"
|
|
||||||
"bytes"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -372,8 +373,8 @@ func copyAndModify(dst io.Writer, src io.Reader) (written int64, err error) {
|
||||||
for {
|
for {
|
||||||
nr, er := src.Read(buf)
|
nr, er := src.Read(buf)
|
||||||
if written == 0 && nr > 0 {
|
if written == 0 && nr > 0 {
|
||||||
if (buf[0] == 0x16 && buf[5] == 0x01) {// && buf[1] == 0x03 && buf[2] == 0x01) {
|
if buf[0] == 0x16 && buf[5] == 0x01 { // && buf[1] == 0x03 && buf[2] == 0x01) {
|
||||||
modifyHello(buf);
|
modifyHello(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nr > 0 {
|
if nr > 0 {
|
||||||
|
@ -428,7 +429,7 @@ func modifyHello(buf []byte) {
|
||||||
|
|
||||||
// 2 byte cipher suites length (in bytes)
|
// 2 byte cipher suites length (in bytes)
|
||||||
suitesLength := big.NewInt(0)
|
suitesLength := big.NewInt(0)
|
||||||
suitesLength.SetBytes(buf[44+sessionLength.Uint64():44+sessionLength.Uint64()+2])
|
suitesLength.SetBytes(buf[44+sessionLength.Uint64() : 44+sessionLength.Uint64()+2])
|
||||||
|
|
||||||
// cipher suites
|
// cipher suites
|
||||||
|
|
||||||
|
@ -438,49 +439,49 @@ func modifyHello(buf []byte) {
|
||||||
|
|
||||||
// 2 byte extensions length
|
// 2 byte extensions length
|
||||||
extensionsLength := big.NewInt(0)
|
extensionsLength := big.NewInt(0)
|
||||||
extensionsLength.SetBytes(buf[48+sessionLength.Uint64()+suitesLength.Uint64():48+sessionLength.Uint64()+suitesLength.Uint64()+2])
|
extensionsLength.SetBytes(buf[48+sessionLength.Uint64()+suitesLength.Uint64() : 48+sessionLength.Uint64()+suitesLength.Uint64()+2])
|
||||||
|
|
||||||
// extensions:
|
// extensions:
|
||||||
|
|
||||||
extensionsStart := 50 + sessionLength.Uint64() + suitesLength.Uint64()
|
extensionsStart := 50 + sessionLength.Uint64() + suitesLength.Uint64()
|
||||||
extensionsEnd := extensionsStart + extensionsLength.Uint64()
|
extensionsEnd := extensionsStart + extensionsLength.Uint64()
|
||||||
cur := extensionsStart
|
cur := extensionsStart
|
||||||
for cur + 4 < extensionsEnd {
|
for cur+4 < extensionsEnd {
|
||||||
if (buf[cur] != 0x00 || buf[cur + 1] != 0x00) {
|
if buf[cur] != 0x00 || buf[cur+1] != 0x00 {
|
||||||
extensionLength := big.NewInt(0)
|
extensionLength := big.NewInt(0)
|
||||||
extensionLength.SetBytes(buf[cur+2:cur+4])
|
extensionLength.SetBytes(buf[cur+2 : cur+4])
|
||||||
cur += 4 + extensionLength.Uint64()
|
cur += 4 + extensionLength.Uint64()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// yay is sni header!
|
// yay is sni header!
|
||||||
extensionLength := big.NewInt(0)
|
extensionLength := big.NewInt(0)
|
||||||
extensionLength.SetBytes(buf[cur+2:cur+4])
|
extensionLength.SetBytes(buf[cur+2 : cur+4])
|
||||||
|
|
||||||
// 2 byte sni list length
|
// 2 byte sni list length
|
||||||
listLength := big.NewInt(0)
|
listLength := big.NewInt(0)
|
||||||
listLength.SetBytes(buf[cur+4:cur+6])
|
listLength.SetBytes(buf[cur+4 : cur+6])
|
||||||
|
|
||||||
var list []string
|
var list []string
|
||||||
|
|
||||||
listStart := cur + 6
|
listStart := cur + 6
|
||||||
listEnd := cur + 6 + listLength.Uint64()
|
listEnd := cur + 6 + listLength.Uint64()
|
||||||
lcur := listStart
|
lcur := listStart
|
||||||
for lcur + 3 < listEnd {
|
for lcur+3 < listEnd {
|
||||||
// 1 byte type
|
// 1 byte type
|
||||||
// 2 byte length
|
// 2 byte length
|
||||||
nameLength := big.NewInt(0)
|
nameLength := big.NewInt(0)
|
||||||
nameLength.SetBytes(buf[lcur+1:lcur+3])
|
nameLength.SetBytes(buf[lcur+1 : lcur+3])
|
||||||
//buf[lcur+3] = 'x'
|
//buf[lcur+3] = 'x'
|
||||||
// name
|
// name
|
||||||
var name bytes.Buffer
|
var name bytes.Buffer
|
||||||
name.Write(buf[lcur+3:lcur+3+nameLength.Uint64()])
|
name.Write(buf[lcur+3 : lcur+3+nameLength.Uint64()])
|
||||||
name.WriteByte(0)
|
name.WriteByte(0)
|
||||||
// append to list
|
// append to list
|
||||||
list = append(list, name.String())
|
list = append(list, name.String())
|
||||||
lcur += 3 + nameLength.Uint64()
|
lcur += 3 + nameLength.Uint64()
|
||||||
}
|
}
|
||||||
fmt.Println(list)
|
log.Println(list)
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -488,5 +489,5 @@ func modifyHello(buf []byte) {
|
||||||
// 2 byte extension type
|
// 2 byte extension type
|
||||||
// 2 byte extension length
|
// 2 byte extension length
|
||||||
// extension data
|
// extension data
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue