Skip to content

Commit

Permalink
V2.0 (#3)
Browse files Browse the repository at this point in the history
https support
  • Loading branch information
ls0f authored Mar 25, 2017
1 parent 9643ad6 commit bd31eb3
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: go

#branches:
# only:
# - master

go:
- 1.7
env:
- "PATH=/home/travis/gopath/bin:$PATH"

before_install:
- go get github.com/mitchellh/gox
- go get github.com/tcnksm/ghr

script:
- make vendor
- make test

after_success:
- sh ./deploy.sh
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ build:
cd $(PWD)/$$m && go build ${LDFLAGS} -o ../bin/$$m --race ; \
done
echo ==================================; \
cd $(PWD) && cp gen_key_cert.sh ./bin

install: vendor build

deploy:
for m in $(BIN); do \
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="linux/amd64" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -os="windows" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
cd $(PWD)/$$m && gox ${LDFLAGS} -osarch="darwin/amd64" -output ../dist/{{.OS}}_{{.Arch}}_{{.Dir}};\
done
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,72 @@
socks5 proxy over http

![](https://github.com/lovedboy/cracker/blob/master/read.png?raw=true)

# Install

Download the latest binaries from this [release page](https://github.com/lovedboy/cracker/releases).

You can also install from source if you have go installed.

```
git clone https://github.com/lovedboy/cracker
cd cracker
make install
cd bin
list
```
# Usage

## Server side (Run on your vps or other application container platform)

```
./server -addr :8080 -secret <password>
```

## Local side (Run on your local pc)

```
./local -laddr 127.0.0.1:1080 -raddr http://example.com:8080 -secret <password>
```

## https

It is strongly recommended to open the https option on the server side.

### Notice

The file name of certificate and private key must be `cert.pem` and `key.pem` and with the server bin under the same folder.

If you have a ssl certificate, It would be easy.

copy the certificate and private key into the same folder with server bin

```
./server -addr :8080 -secret <password> -https
```

```
./local -laddr 127.0.0.1:1080 -raddr https://example.com:8080 -secret <password>
```

Of Course, you can create a self-signed ssl certificate by openssl.

```
openssl req -subj '/CN=*/' -x509 -sha256 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1024 -nodes
```

```
./server -addr :8080 -secret <password> -https
```
copy the certificate into the same folder with local bin and bind the ip and hostname(not domain !!!)

```
echo "<your server ip> <hostname>" >> /etc/hosts
./local -laddr 127.0.0.1:1080 -raddr https://<hostname>:8080 -secret <password>
```

## Next

Play with [SwitchyOmega](https://github.com/FelisCatus/SwitchyOmega/releases)


14 changes: 14 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -ve

if [ ! -z "$TRAVIS_TAG" ];then
echo "the tag is $TRAVIS_TAG, will deploy...."
else
echo "will not deploy..."
exit 0
fi

make deploy

ghr -u lovedboy -t $GITHUB_TOKEN -r cracker --replace --debug $TRAVIS_TAG dist/
3 changes: 3 additions & 0 deletions gen_key_cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

openssl req -subj '/CN=*/' -x509 -sha256 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1024 -nodes
5 changes: 4 additions & 1 deletion local/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"logger"
"os"
"socks"
"proxy"

)

var (
Expand All @@ -15,7 +17,7 @@ var (

func main() {
laddr := flag.String("laddr", "", "listen addr")
raddr := flag.String("raddr", "", "remote http url")
raddr := flag.String("raddr", "", "remote http url(e.g, https://example.com)")
secret := flag.String("secret", "", "secret key")
debug := flag.Bool("debug", false, "debug mode")
version := flag.Bool("v", false, "version")
Expand All @@ -27,5 +29,6 @@ func main() {
os.Exit(0)
}
logger.InitLogger(*debug)
proxy.Init()
socks.NewSocks5(*laddr, *raddr, *secret)
}
21 changes: 19 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,31 @@ func main() {
secret := flag.String("secret", "", "secret")
debug := flag.Bool("debug", false, "debug mode")
version := flag.Bool("v", false, "version")
https := flag.Bool("https", false, "https")
flag.Parse()
logger.InitLogger(*debug)
if *version {
fmt.Printf("GitTag: %s \n", GitTag)
fmt.Printf("BuildTime: %s \n", BuildTime)
os.Exit(0)
}
logger.InitLogger(*debug)
p := proxy.NewHttpProxy(*addr, *secret)
if *https {
f, err := os.Stat("cert.pem")
if err != nil {
g.Fatal(err)
}
if f.IsDir() {
g.Fatal("cert.pem should be file")
}
f, err = os.Stat("key.pem")
if err != nil {
g.Fatal(err)
}
if f.IsDir() {
g.Fatal("key.pem should be file")
}
}
p := proxy.NewHttpProxy(*addr, *secret, *https)
p.Listen()

}
12 changes: 10 additions & 2 deletions src/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ type httpProxy struct {
secret string
proxyMap map[string]*proxyConn
sync.Mutex
https bool
}

func NewHttpProxy(addr, secret string) *httpProxy {
func NewHttpProxy(addr, secret string, https bool) *httpProxy {
return &httpProxy{addr: addr,
secret: secret,
proxyMap: make(map[string]*proxyConn),
https: https,

}
}

Expand All @@ -61,7 +64,12 @@ func (hp *httpProxy) Listen() {
http.HandleFunc(PING, hp.ping)
http.HandleFunc("/debug", hp.debug)
g.Infof("listen at:[%s]", hp.addr)
err := http.ListenAndServe(hp.addr, nil)
var err error
if hp.https {
err = http.ListenAndServeTLS(hp.addr, "cert.pem", "key.pem", nil)
} else {
err = http.ListenAndServe(hp.addr, nil)
}
if err != nil {
g.Fatal("ListenAndServe: ", err)
}
Expand Down
21 changes: 18 additions & 3 deletions src/proxy/local.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package proxy

import (
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
"sync"
"time"

"io"

"os"
"gopkg.in/bufio.v1"
)

Expand All @@ -25,6 +26,21 @@ var tr = &http.Transport{
MaxIdleConnsPerHost: PerHostNum,
}

func Init() {
if f, err := os.Stat("cert.pem"); err == nil && !f.IsDir() {
CAPOOL := x509.NewCertPool()
serverCert, err := ioutil.ReadFile("cert.pem")
if err != nil {
g.Errorf("read cert.pem err:%s ", err)
return
}
CAPOOL.AppendCertsFromPEM(serverCert)
config := &tls.Config{RootCAs: CAPOOL}
tr.TLSClientConfig = config
g.Info("load cert.pem success ... ")
}
}

type localProxyConn struct {
uuid string
server string
Expand Down Expand Up @@ -132,7 +148,6 @@ func Connect(server, remote, secret string) (*localProxyConn, error) {
conn := localProxyConn{server: server, secret: secret}
host := strings.Split(remote, ":")[0]
port := strings.Split(remote, ":")[1]

uuid, err := conn.connect(host, port)
if err != nil {
return nil, err
Expand Down

0 comments on commit bd31eb3

Please sign in to comment.