|
| 1 | +# Ninja proxy |
| 2 | +<p align="center"> |
| 3 | + <img alt="ninja cat image" src="https://i.ibb.co/S54DPbc/ninja.png" /> |
| 4 | +</p> |
| 5 | + |
| 6 | +## Generate temporary URLs with a stateless service |
| 7 | +This project grew out of the need to share authenticated proxies with third-party services, so that they can all operate with the same IP. Several proxy-providers provide mechanisms for this, but they usually require sending your username and password to the third-party and this can be very risky. Ideally you want some temporary URL that opaquely routes the traffic from the third-party to your proxy provider, and that is exactly what this project provides. |
| 8 | + |
| 9 | +### Quick start |
| 10 | +Clone this repo and build the project. Assuming that golang is installed, you build the server using |
| 11 | + |
| 12 | +`make binary` |
| 13 | + |
| 14 | +that will put it into `./bin/ninja-proxy`. |
| 15 | + |
| 16 | +You can install the helper utilities by running |
| 17 | + |
| 18 | +```bash |
| 19 | +source activate.sh |
| 20 | +``` |
| 21 | + |
| 22 | +and load a key into your terminal with |
| 23 | + |
| 24 | +```bash |
| 25 | +KEY=$(ninja-key) |
| 26 | +``` |
| 27 | + |
| 28 | +Now you can run the service (in the background) using |
| 29 | + |
| 30 | +```bash |
| 31 | +bin/ninja-proxy -key $KEY & |
| 32 | +``` |
| 33 | +which by default will run on 0.0.0.0:7777. |
| 34 | + |
| 35 | +To generate a link for the service call |
| 36 | + |
| 37 | +```bash |
| 38 | +link= $(ninja-link 120 $KEY http://username:[email protected]:80 --headers test-header=foo another=bar) |
| 39 | +``` |
| 40 | + |
| 41 | +```bash |
| 42 | +$ curl $link/headers |
| 43 | +{ |
| 44 | + "headers": { |
| 45 | + "Accept": "*/*", |
| 46 | + "Another": "bar", |
| 47 | + "Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", |
| 48 | + "Host": "httpbin.org", |
| 49 | + "Test-Header": "foo", |
| 50 | + "User-Agent": "curl/7.72.0", |
| 51 | + "X-Amzn-Trace-Id": "Root=1-5f56788f-d9513fb01690f9080adeb528" |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | +Notice how the username and password are automatically added to the `Authorization` header, you can do the same thing with a proxy URL and it will just work. |
| 56 | + |
| 57 | +The generated link contains a username and header field with all of this information encrypted so that it can't be read. It looks quite messy, but it works. |
| 58 | + |
| 59 | +#### Proxies |
| 60 | +There's not very much else to say, use exactly the same procedure as above to wrap your proxy URL and use it as normal |
| 61 | + |
| 62 | +```bash |
| 63 | +proxy_link=$(ninja-link 120 $KEY "http://$PROXY_USER:$PROXY_PASS@$PROXY_HOST:$PROXY_PORT") |
| 64 | +curl -x $proxy_link -k http://httpbin.org/ip |
| 65 | +``` |
| 66 | + |
| 67 | +### Docker image |
| 68 | +A dockerfile has been included with this repository and can be built using `make docker`. Then you can run this using |
| 69 | + |
| 70 | +``` |
| 71 | +NINJA_PORT=7777 |
| 72 | +docker run --rm -d -p $NINJA_PORT:7777 ninja-proxy |
| 73 | +``` |
| 74 | + |
| 75 | +### Limitations |
| 76 | +This is a young project created for a specific problem at hand. You can use this to proxy both HTTP and HTTPS connections, but right now it only supports HTTP proxies or URLs using HTTP/1.x. |
0 commit comments