1
0
Fork 0

Use commandline options

logger
Ambrose Chua 2018-02-14 21:42:26 +08:00
parent a019fa6da5
commit 64b8ee7aaa
2 changed files with 24 additions and 17 deletions

View File

@ -1,17 +1,23 @@
package main
import (
"flag"
"github.com/serverwentdown/bypass"
)
var listen string
func main() {
flag.StringVar(&listen, "listen", ":8000", "listen on ip and port")
flag.Parse()
conf := &socks5.Config{}
server, err := socks5.New(conf)
if err != nil {
panic(err)
}
if err := server.ListenAndServe("tcp", "127.0.0.1:8000"); err != nil {
if err := server.ListenAndServe("tcp", listen); err != nil {
panic(err)
}
}

View File

@ -1,13 +1,14 @@
package socks5
import (
"bytes"
"fmt"
"io"
"log"
"math/big"
"net"
"strconv"
"strings"
"math/big"
"bytes"
"golang.org/x/net/context"
)
@ -372,8 +373,8 @@ func copyAndModify(dst io.Writer, src io.Reader) (written int64, err error) {
for {
nr, er := src.Read(buf)
if written == 0 && nr > 0 {
if (buf[0] == 0x16 && buf[5] == 0x01) {// && buf[1] == 0x03 && buf[2] == 0x01) {
modifyHello(buf);
if buf[0] == 0x16 && buf[5] == 0x01 { // && buf[1] == 0x03 && buf[2] == 0x01) {
modifyHello(buf)
}
}
if nr > 0 {
@ -428,7 +429,7 @@ func modifyHello(buf []byte) {
// 2 byte cipher suites length (in bytes)
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
@ -438,49 +439,49 @@ func modifyHello(buf []byte) {
// 2 byte extensions length
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:
extensionsStart := 50 + sessionLength.Uint64() + suitesLength.Uint64()
extensionsEnd := extensionsStart + extensionsLength.Uint64()
cur := extensionsStart
for cur + 4 < extensionsEnd {
if (buf[cur] != 0x00 || buf[cur + 1] != 0x00) {
for cur+4 < extensionsEnd {
if buf[cur] != 0x00 || buf[cur+1] != 0x00 {
extensionLength := big.NewInt(0)
extensionLength.SetBytes(buf[cur+2:cur+4])
extensionLength.SetBytes(buf[cur+2 : cur+4])
cur += 4 + extensionLength.Uint64()
continue
}
// yay is sni header!
extensionLength := big.NewInt(0)
extensionLength.SetBytes(buf[cur+2:cur+4])
extensionLength.SetBytes(buf[cur+2 : cur+4])
// 2 byte sni list length
listLength := big.NewInt(0)
listLength.SetBytes(buf[cur+4:cur+6])
listLength.SetBytes(buf[cur+4 : cur+6])
var list []string
listStart := cur + 6
listEnd := cur + 6 + listLength.Uint64()
lcur := listStart
for lcur + 3 < listEnd {
for lcur+3 < listEnd {
// 1 byte type
// 2 byte length
nameLength := big.NewInt(0)
nameLength.SetBytes(buf[lcur+1:lcur+3])
nameLength.SetBytes(buf[lcur+1 : lcur+3])
//buf[lcur+3] = 'x'
// name
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)
// append to list
list = append(list, name.String())
lcur += 3 + nameLength.Uint64()
}
fmt.Println(list)
log.Println(list)
break
}
@ -488,5 +489,5 @@ func modifyHello(buf []byte) {
// 2 byte extension type
// 2 byte extension length
// extension data
}