diff --git a/README.md b/README.md index 3e13ec8c455ac5e9e54dffffca285e13327d2d32..e78fa71f6e6b412ee6c3213cd9cc61cea7bc4c38 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,100 @@ -hijack -===== +Hijack +====== -An OTP application +An escript to hijack and tunnel connections from [Consul Proxy](https://gitlab.hedenstroem.com/erlang-ninja/consul_proxy). -Build ------ +Requirements +------------ - $ rebar3 compile +You need to install [Erlang/OTP](http://www.erlang.org/downloads) to run the escript. + +Downloading +----------- + +Use [this link](http://s3.erlang.ninja/consul_proxy/extras/hijack) to download the latest version of hijack. + +Building +-------- + +To build a self-contained escript named `_build/default/bin/hijack` + +``` +git clone https://gitlab.hedenstroem.com/erlang-ninja/hijack.git +cd hijack +make +``` + +Contents of `_build/default/bin/hijack` + +``` +#!usr/bin/env escript +%% +%%! -escript main hijack -pz hijack/hijack/ebin +[Embedded Zip Archive] +``` + +Configuration +------------- + +Before you can hijack or snoop a domain you must add a user to the /consul_proxy/hijackers` key on consul: + +``` +[ + { + "username" : "erikh", + "password" : "...", + "domains" : [ + ".*[.]hedenstroem[.]com" + ] + } +] +``` + +See the [Consul Proxy - Hijack Middleware](https://gitlab.hedenstroem.com/erlang-ninja/consul_proxy#hijack) for more details on configuring hijack. + +Running +------- + +``` +Usage: hijack [-c [<consul>]] [-t [<target>]] [-s [<snoop>]] + [-h [<host_rewrite>]] [-w [<port>]] [-u <username>] + [-p <password>] [-r [<path>]] [<host>] + + -c, --consul Consul host and port [default: localhost:8083] + -t, --target Target host and port [default: localhost:80] + -s, --snoop Ignore response from target [default: false] + -h, --host Rewrite host header [default: false] + -w, --port Port for hijack webserver [default: 4040] + -u, --username Username, if ommited env var USER is used as default + -p, --password Password, if ommited prompt will be used + -r, --path Path regexp [default: .*] + <host> Host to hijack, ex. www.test.com + +``` + +Example +------- + +The following will redirect all HTTP requests to demo.examplecom to the server running on localhost at port 80. It will also start a webserver at http://localhost:4040 that you can open in your browser to monitor requests. + +``` +> hijack -c consul.hedenstroem.com demo.hedenstroem.com +Password > +Logged in as erikh +Ready, hijacking demo.hedenstroem.com/.* +Started webserver at http://localhost:4040 + +``` + +Corresponding logs on Consul Proxy at consul.hedenstroem.com + +``` +12:12:27.323 UTC {consul_proxy_middleware_hijack:182} <0.2790.0> [notice] ranch_ssl socket opened: {sslsocket,{gen_tcp,#Port<0.1851>,tls_connection,<0.2798.0>},<0.3748.0>} +12:12:27.667 UTC {consul_proxy_middleware_hijack:150} <0.2790.0> [notice] demo.hedenstroem.com/.* hijack by erikh on {sslsocket,{gen_tcp,#Port<0.1851>,tls_connection,<0.2798.0>},<0.3748.0>} +12:14:43.539 UTC {consul_proxy_middleware_hijack:187} <0.2790.0> [notice] Socket closed: {sslsocket,{gen_tcp,#Port<0.1851>,tls_connection,<0.2798.0>},<0.3748.0>} +``` + +Inspecting Requests +------------------- + + diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..21220f202e6a23f0324cf68b7580516994793866 Binary files /dev/null and b/screenshot.png differ diff --git a/src/hijack.erl b/src/hijack.erl index 6baa6519856d2e75a8a3b6e969c64e62f12954fc..5579a68a903993ec9e892e0a75f3bf87b5091601 100644 --- a/src/hijack.erl +++ b/src/hijack.erl @@ -3,12 +3,12 @@ -define(OPT_SPEC, [ {consul, $c, "consul", {string, "localhost:8083"}, "Consul host and port"}, - {target, $t, "target", {string, "localhost:8080"}, "Target host and port"}, + {target, $t, "target", {string, "localhost:80"}, "Target host and port"}, {snoop, $s, "snoop", {boolean, false}, "Ignore response from target"}, {host_rewrite, $h, "host", {boolean, false}, "Rewrite host header"}, {port, $w, "port", {integer, 4040}, "Port for hijack webserver"}, - {username, $u, "username", string, "Username"}, - {password, $p, "password", string, "Password"}, + {username, $u, "username", string, "Username, if ommited env var USER is used as default"}, + {password, $p, "password", string, "Password, if ommited prompt will be used"}, {path, $r, "path", {string, ".*"}, "Path regexp"}, {host, undefined, undefined, string, "Host to hijack, ex. www.test.com"} ]). @@ -29,6 +29,8 @@ -define(LOG(Format, Data), io_lib:format("{~p,~p}: " ++ Format ++ "~n", [?MODULE, ?LINE] ++ Data)). -endif. +main([]) -> + getopt:usage(?OPT_SPEC, "hijack"); main(Args) -> application:ensure_all_started(gun), {ok, {Opts, _}} = getopt:parse(?OPT_SPEC, Args),