Skip to content
This repository was archived by the owner on Nov 1, 2025. It is now read-only.

Commit bc8a00e

Browse files
committed
switch to go module, removed hardcoded check for environment variables, fix build process
1 parent 5df2730 commit bc8a00e

File tree

11 files changed

+201
-62
lines changed

11 files changed

+201
-62
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/golang:1.9
5+
- image: circleci/golang:1.12
66

7-
working_directory: /go/src/github.com/dan-v/awslambdaproxy
7+
working_directory: /tmp
88

99
steps:
1010
- checkout
11-
11+
- run: wget https://bin.equinox.io/a/75VeNN6mcnk/github-com-kevinburke-go-bindata-go-bindata-linux-amd64.tar.gz
12+
- run: sudo tar xvf github-com-kevinburke-go-bindata-go-bindata-linux-amd64.tar.gz -C /usr/bin
1213
- run: make all-zip
13-
1414
- store_artifacts:
1515
path: build/zip/awslambdaproxy-linux-x86-64.zip
1616
destination: awslambdaproxy-linux-x86-64.zip

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ lambda:
55
zip -jr data/lambda data/lambda
66

77
bindata: lambda
8-
go get github.com/jteeuwen/go-bindata/...
98
go-bindata -nocompress -pkg awslambdaproxy -o bindata.go data/lambda.zip
109

1110
linux: bindata
@@ -25,4 +24,4 @@ all-zip: all
2524
zip -jr ./build/zip/awslambdaproxy-osx-x86-64 ./build/osx/x86-64/awslambdaproxy
2625
zip -jr ./build/zip/awslambdaproxy-linux-x86-64 ./build/linux/x86-64/awslambdaproxy
2726

28-
.PHONY: lambda bindata
27+
.PHONY: lambda bindata

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Current code status: <b>proof of concept</b>. This is the first Go application that I've ever written. It has no tests. It may not work. It may blow up. Use at your own risk.
1515

1616
## How it works
17-
At a high level, awslambdaproxy proxies TCP/UDP traffic through AWS Lambda regional endpoints. To do this, awslambdaproxy is setup on a publicly accessible host (e.g. EC2 instance) and it handles creating Lambda resources that run a proxy server ([ginuerzh/gost](https://github.com/ginuerzh/gost)). Since Lambda does not allow you to connect to bound ports in executing functions, a reverse SSH tunnel is established from the Lambda function to the host running awslambdaproxy. Once a tunnel connection is established, all user traffic is forwarded through this reverse tunnel to the proxy server. Lambda functions have a max execution time of 5 minutes, so there is a goroutine that continuously executes Lambda functions to ensure there is always a live tunnel in place. If multiple regions are specified, user traffic will be routed in a round robin fashion across these regions.
17+
At a high level, awslambdaproxy proxies TCP/UDP traffic through AWS Lambda regional endpoints. To do this, awslambdaproxy is setup on a publicly accessible host (e.g. EC2 instance) and it handles creating Lambda resources that run a proxy server ([ginuerzh/gost](https://github.com/ginuerzh/gost)). Since Lambda does not allow you to connect to bound ports in executing functions, a reverse SSH tunnel is established from the Lambda function to the host running awslambdaproxy. Once a tunnel connection is established, all user traffic is forwarded through this reverse tunnel to the proxy server. Lambda functions have a max execution time of 15 minutes, so there is a goroutine that continuously executes Lambda functions to ensure there is always a live tunnel in place. If multiple regions are specified, user traffic will be routed in a round robin fashion across these regions.
1818

1919
![](/images/how-it-works.png?raw=true)
2020

@@ -28,25 +28,27 @@ The easiest way is to download a pre-built binary from the [GitHub Releases](htt
2828
* Port 22 - functions executing in AWS Lambda will open SSH connections back to the host running `awslambdaproxy`, so this port needs to be open to the world. The SSH key used here is dynamically generated at startup and added to the running users authorized_keys file.
2929
* Port 8080 - the default configuration will start a HTTP/SOCKS proxy listener on this port with default user/password authentication. If you don't want to publicly expose the proxy server, one option is to setup your own VPN server (e.g. [dosxvpn](https://github.com/dan-v/dosxvpn) or [algo](https://github.com/trailofbits/algo)), connect to it, and just run awslambdaproxy with the proxy listener only on localhost (-l localhost:8080).
3030

31-
2. Optional, but I'd highly recommend taking a look at the Minimal IAM Policies section below. This will get you scoped access keys for running setup and run commands. Otherwise, if you don't care about security you can always use an access key with full administrator privileges.
31+
2. Optional, but I'd highly recommend taking a look at the Minimal IAM Policies section below. This will allow you to setup minimal permissions required to setup and run the project. Otherwise, if you don't care about security you can always use an access key with full administrator privileges.
3232

33-
2. Run `awslambdaproxy setup`.
33+
3. `awslambdaproxy` will need access to credentials for AWS in some form. This can be either through exporting environment variables (as shown below), shared crendential file, or an IAM role if assigned to the instance you are running it on. See [this](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html#specifying-credentials) for more details.
3434

3535
```sh
3636
export AWS_ACCESS_KEY_ID=XXXXXXXXXX
3737
export AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYY
38+
```
39+
4. Run `awslambdaproxy setup`.
40+
41+
```sh
3842
./awslambdaproxy setup
3943
```
4044

41-
3. Run `awslambdaproxy run`.
45+
5. Run `awslambdaproxy run`.
4246

4347
```sh
44-
export AWS_ACCESS_KEY_ID=XXXXXXXXXX
45-
export AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYY
4648
./awslambdaproxy run -r us-west-2,us-west-1,us-east-1,us-east-2
4749
```
4850

49-
3. Configure your web browser (or OS) to use the SOCKS5 proxy on the publicly accessible host running `awslambdaproxy` on port 8080.
51+
6. Configure your web browser (or OS) to use the SOCKS5 proxy on the publicly accessible host running `awslambdaproxy` on port 8080.
5052

5153
## Minimal IAM Policies
5254
* This assumes you have the AWS CLI setup with an admin user
@@ -88,21 +90,23 @@ aws iam create-access-key --user-name awslambdaproxy-run
8890
4. <b>Will this make me completely anonymous?</b> No, absolutely not. The goal of this project is just to obfuscate your web traffic by rotating your IP address. All of your traffic is going through AWS which could be traced back to your account. You can also be tracked still with [browser fingerprinting](https://panopticlick.eff.org/), etc. Your [IP address may still leak](https://ipleak.net/) due to WebRTC, Flash, etc.
8991
5. <b>How often will my external IP address change?</b> For each region specified, the IP address will change roughly every 4 hours. This of course is subject to change at any moment as this is not something that is documented by AWS Lambda.
9092
6. <b>How much does this cost?</b> awslambdaproxy should be able to run mostly on the [AWS free tier](https://aws.amazon.com/free/) minus bandwidth costs. It can run on a t2.micro instance and the default 128MB Lambda function that is constantly running should also fall in the free tier usage. The bandwidth is what will cost you money; you will pay for bandwidth usage for both EC2 and Lambda.
91-
7. <b>Why does my connection drop periodically?</b> AWS Lambda functions can currently only execute for a maximum of 5 minutes. In order to maintain an ongoing proxy a new function is executed and all new traffic is cut over to it. Any ongoing connections to the previous Lambda function will hard stop after a timeout period. You generally won't see any issues for normal web browsing as connections are very short lived, but for any long lived connections you may see issues.
93+
7. <b>Why does my connection drop periodically?</b> AWS Lambda functions can currently only execute for a maximum of 15 minutes. In order to maintain an ongoing proxy a new function is executed and all new traffic is cut over to it. Any ongoing connections to the previous Lambda function will hard stop after a timeout period. You generally won't see any issues for normal web browsing as connections are very short lived, but for any long lived connections you may see issues.
9294
9395
# Powered by
9496
* [gost](https://github.com/ginuerzh/gost) - A simple security tunnel written in Golang.
9597
* [yamux](https://github.com/hashicorp/yamux) - Golang connection multiplexing library.
9698
* [goad](https://github.com/goadapp/goad) - Code was borrowed from this project to handle AWS Lambda zip creation and function upload.
9799
98100
## Build From Source
99-
1. Fetch the project with `git clone`:
101+
1. Install [Go](https://golang.org/dl/) and [go-bindata](https://github.com/kevinburke/go-bindata)
102+
103+
2. Fetch the project with `git clone`:
100104
101105
```sh
102106
git clone git@github.com:dan-v/awslambdaproxy.git && cd awslambdaproxy
103107
```
104108

105-
2. Run make to build awslambdaproxy. You'll find your `awslambdaproxy` binary in the `build` folder.
109+
3. Run make to build awslambdaproxy. You'll find your `awslambdaproxy` binary in the `build` folder.
106110

107111
```sh
108112
make

cmd/awslambdaproxy/cmd/run.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ package cmd
22

33
import (
44
"fmt"
5-
"github.com/dan-v/awslambdaproxy"
6-
"github.com/spf13/cobra"
7-
"github.com/spf13/viper"
85
"os"
96
"os/user"
107
"strconv"
118
"strings"
129
"time"
10+
11+
"github.com/dan-v/awslambdaproxy"
12+
"github.com/spf13/cobra"
13+
"github.com/spf13/viper"
1314
)
1415

1516
var (
1617
frequency time.Duration
1718
memory int64
1819
sshUser, sshPort, regions, listeners string
19-
// Max execution time on lambda is 300 seconds currently
20-
lambdaMaxFrequency = time.Duration(290 * time.Second) // leave 10 seconds of leeway
20+
// Max execution time on lambda is 900 seconds currently
21+
lambdaMaxFrequency = time.Duration(890 * time.Second) // leave 10 seconds of leeway
2122
lambdaMinMemorySize = 128
2223
lambdaMaxMemorySize = 1536
2324
)
@@ -28,10 +29,6 @@ var runCmd = &cobra.Command{
2829
Short: "Run awslambdaproxy",
2930
Long: `This will execute awslambdaproxy in regions specified. Examples:
3031
31-
# Make sure credentials are exported
32-
export AWS_ACCESS_KEY_ID=XXXXXXXXXX
33-
export AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYY
34-
3532
# Example 1 - Execute proxy in four different regions with rotation happening every 60 seconds
3633
./awslambdaproxy run -r us-west-2,us-west-1,us-east-1,us-east-2 -f 60s
3734
@@ -66,18 +63,6 @@ export AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYY
6663
os.Exit(1)
6764
}
6865

69-
// check for required aws keys
70-
access := os.Getenv("AWS_ACCESS_KEY_ID")
71-
if access == "" {
72-
fmt.Println("Must specify environment variable AWS_ACCESS_KEY_ID")
73-
os.Exit(1)
74-
}
75-
secret := os.Getenv("AWS_SECRET_ACCESS_KEY")
76-
if secret == "" {
77-
fmt.Println("Must specify environment variable AWS_SECRET_ACCESS_KEY")
78-
os.Exit(1)
79-
}
80-
8166
awslambdaproxy.ServerInit(aSSHUser, aSSHPort, aRegions, aMemory, aFrequency, aListeners, aTimeout)
8267
},
8368
}
@@ -95,7 +80,7 @@ func init() {
9580

9681
runCmd.Flags().StringVarP(&regions, "regions", "r", "us-west-2", "Regions to "+
9782
"run proxy.")
98-
runCmd.Flags().DurationVarP(&frequency, "frequency", "f", time.Duration(time.Second*260), "Frequency "+
83+
runCmd.Flags().DurationVarP(&frequency, "frequency", "f", time.Duration(time.Second*860), "Frequency "+
9984
"to execute Lambda function. Maximum is "+lambdaMaxFrequency.String()+". If multiple "+
10085
"lambda-regions are specified, this will cause traffic to rotate round robin at the interval "+
10186
"specified here.")

cmd/awslambdaproxy/cmd/setup.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@ package cmd
22

33
import (
44
"fmt"
5+
"os"
6+
57
"github.com/dan-v/awslambdaproxy"
68
"github.com/spf13/cobra"
7-
"os"
89
)
910

1011
// setupCmd represents the setup command
1112
var setupCmd = &cobra.Command{
1213
Use: "setup",
1314
Short: "Setup awslambdaproxy AWS infrastructure",
14-
Long: `This will setup all required AWS infrastructure to run awslambdaproxy. Example:
15-
16-
export AWS_ACCESS_KEY_ID=XXXXXXXXXX
17-
export AWS_SECRET_ACCESS_KEY=YYYYYYYYYYYYYYYYYYYYYY
18-
./awslambdaproxy setup`,
15+
Long: `This will setup all required AWS infrastructure to run awslambdaproxy.`,
1916
Run: func(cmd *cobra.Command, args []string) {
2017
err := awslambdaproxy.SetupLambdaInfrastructure()
2118
if err != nil {
22-
fmt.Print("Failed to run setup for awslambdaproxy", err)
19+
fmt.Print("Failed to run setup for awslambdaproxy: ", err)
2320
os.Exit(1)
2421
}
2522
},

go.mod

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module github.com/dan-v/awslambdaproxy
2+
3+
go 1.12
4+
5+
require (
6+
github.com/Yawning/chacha20 v0.0.0-20170904085104-e3b1f968fc63
7+
github.com/aead/chacha20 v0.0.0-20170614051014-8d6ce0550041
8+
github.com/aws/aws-lambda-go v1.0.1
9+
github.com/aws/aws-sdk-go v1.12.62
10+
github.com/dan-v/gosocks5 v0.0.0-20171218225514-69190413d160
11+
github.com/dan-v/gost v0.0.0-20171218225532-25d135e41663
12+
github.com/dan-v/shadowsocks-go v0.0.0-20171218225457-a3924b5aead6
13+
github.com/fsnotify/fsnotify v1.4.7
14+
github.com/go-ini/ini v1.32.0
15+
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
16+
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad
17+
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb
18+
github.com/hashicorp/yamux v0.0.0-20171219165022-683f49123a33
19+
github.com/inconshreveable/mousetrap v1.0.0
20+
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8
21+
github.com/klauspost/compress v1.2.1
22+
github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5
23+
github.com/klauspost/reedsolomon v0.0.0-20171001120606-6bb6130ff6a7
24+
github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f
25+
github.com/lucas-clemente/fnv128a v0.0.0-20160504152609-393af48d3916
26+
github.com/lucas-clemente/quic-go v0.5.0
27+
github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced
28+
github.com/magiconair/properties v1.7.4
29+
github.com/mitchellh/mapstructure v0.0.0-20180111000720-b4575eea38cc
30+
github.com/pelletier/go-toml v1.0.1
31+
github.com/pkg/errors v0.8.0
32+
github.com/spf13/afero v1.0.2
33+
github.com/spf13/cast v1.1.0
34+
github.com/spf13/cobra v0.0.0-20180115160933-0c34d16c3123
35+
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec
36+
github.com/spf13/pflag v1.0.0
37+
github.com/spf13/viper v0.0.0-20171227194143-aafc9e6bc7b7
38+
github.com/stretchr/testify v1.3.0 // indirect
39+
golang.org/x/crypto v0.0.0-20180112200814-13931e22f9e7
40+
golang.org/x/net v0.0.0-20180112015858-5ccada7d0a7b
41+
golang.org/x/sys v0.0.0-20180115085844-fff93fa7cd27
42+
golang.org/x/text v0.0.0-20171227012246-e19ae1496984
43+
gopkg.in/gorilla/websocket.v1 v1.2.0
44+
gopkg.in/xtaci/kcp-go.v2 v2.0.0-20170304104302-bf95749e1be2
45+
gopkg.in/xtaci/smux.v1 v1.0.6
46+
gopkg.in/yaml.v2 v2.0.0
47+
)

0 commit comments

Comments
 (0)