Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client-outbound SOCKS support #78

Merged
merged 4 commits into from May 20, 2020
Merged

Conversation

aus
Copy link
Collaborator

@aus aus commented Feb 9, 2019

In some situations, it may be useful to utilize the chisel tunnel to access the internal network of the connected client. With the recent addition of reverse port forward remotes, we can simply start a SOCKS5 server on the client and remote port forward to it.

Example: (see comment below for latest syntax)

server

chisel server --reverse
2019/02/09 12:54:50 server: Reverse tunnelling enabled
2019/02/09 12:54:50 server: Fingerprint a7:39:0e:a3:78:87:9e:ba:12:12:b0:42:62:75:99:e3
2019/02/09 12:54:50 server: Listening on 0.0.0.0:8080...
2019/02/09 12:54:52 server: proxy#1:R:127.0.0.1:5000=>127.0.0.1:1081: Listening

client

chisel client --socks5 http://chisel-server:8080 R:127.0.0.1:5000:127.0.0.1:1081
2019/02/09 12:54:52 client: client-side SOCKS5 server enabled
2019/02/09 12:54:52 client: Connecting to ws://localhost:8080
2019/02/09 12:54:52 client: Fingerprint a7:39:0e:a3:78:87:9e:ba:12:12:b0:42:62:75:99:e3
2019/02/09 12:54:52 client: Connected (Latency 404.322µs)

@jpillora
Copy link
Owner

Thanks for the PR! I think a better user experience would be for it to work like the server's socks endpoint (e.g. socks, converts to localhost:1080:localhost:socks). So maybe R:socks should try to listen on the server's 1080 and forward through the clients internal socks handler (does not need to be listening, use ServeConn instead, see chisel server usage).

@aus
Copy link
Collaborator Author

aus commented Feb 12, 2019

Thanks for the feedback! I did originally consider something like you've suggested, but this was a quick solution to a problem. I'll consider implementing as you've suggested, but it may take some more time for me to understand the code (and more of golang).

I do prefer the R:socks design better. And if multiple clients connect, then the subsequent client can simply specify a free port to listen on (e.g. R:1081:socks).

@jpillora
Copy link
Owner

jpillora commented Feb 12, 2019 via email

@aus
Copy link
Collaborator Author

aus commented Feb 23, 2019

Reworked the code to support the R:socks remote syntax. Let me know what you think. Thanks!

@jpillora
Copy link
Owner

jpillora commented Feb 24, 2019 via email

@aus
Copy link
Collaborator Author

aus commented Feb 24, 2019

Thanks for the clarification. And good catch. I've add the nil check as suggested.

(if you got an email notification on my previous comment, please ignore. I realized I did not have the --socks5 server option on when testing.)

@aus
Copy link
Collaborator Author

aus commented Mar 1, 2019

For those following along at home, the current syntax works like this:

root@server:~$ chisel server --reverse
2019/02/28 20:13:06 server: Reverse tunnelling enabled
2019/02/28 20:13:06 server: Fingerprint 60:12:73:13:4a:ad:29:f5:51:f9:4c:05:62:e8:13:2c
2019/02/28 20:13:06 server: Listening on 0.0.0.0:8080...
2019/02/28 20:13:22 server: proxy#1:R:127.0.0.1:1080=>socks: Listening
root@client:~$ chisel client http://example.com:8080 R:socks
2019/02/28 20:13:22 client: Connecting to ws://example.com:8080
2019/02/28 20:13:22 client: Fingerprint 60:12:73:13:4a:ad:29:f5:51:f9:4c:05:62:e8:13:2c
2019/02/28 20:13:22 client: Connected (Latency 999.8µs)

From the chisel server (example.com), you can access a SOCKS server on 127.0.0.1:1080 that will originate from the client chisel (12.34.56.78).

root@server:~$ curl -x socks5h://localhost:1080 http://icanhazip.com
12.34.56.78

Then we see this in the server log:

2019/03/01 02:23:46 server: proxy#1:R:127.0.0.1:1080=>socks: conn#1: Open
2019/03/01 02:23:46 server: proxy#1:R:127.0.0.1:1080=>socks: conn#1: Close (sent 101B received 425B)

@CCob
Copy link

CCob commented Dec 8, 2019

Very cool PR, works very well. Is there a way we can request the listen IP when setting up the reverse socks proxy. Seems to default to 127.0.0.1. I can see that the port can be changed, R:socks:5000 for example, but could we have something like R:socks:0.0.0.0:5000

@aus
Copy link
Collaborator Author

aus commented Dec 20, 2019

Yup. This is already supported. Another example:

From the server:

user@server:~$ chisel server --reverse
2019/12/20 09:22:12 server: Reverse tunnelling enabled
2019/12/20 09:22:12 server: Fingerprint cf:03:16:24:f2:a3:77:73:75:2e:dc:fd:9a:f8:36:05
2019/12/20 09:22:12 server: Listening on 0.0.0.0:8080...

From the client:

user@client:~$ chisel client http://example.com:8080 R:0.0.0.0:5000:socks
2019/12/20 09:23:10 client: Connecting to ws://example.com:8080
2019/12/20 09:23:10 client: Fingerprint 52:21:e8:07:f4:6a:81:7d:f3:57:c0:a8:6c:b8:c1:46
2019/12/20 09:23:10 client: Connected (Latency 539.3µs)

And now we can see our server log that we are listening on 0.0.0.0:5000:

2019/12/20 09:23:10 server: proxy#1:R:0.0.0.0:5000=>socks: Listening

You cannot change the listening port on the client side, because the client does not listen with a reverse socks.

@vetch101 vetch101 mentioned this pull request Feb 18, 2020
@karimodm
Copy link

Why wasn't this merged yet? It is awesome!

@malcomvetter
Copy link

Why wasn't this merged yet? It is awesome!

^^^ This! ^^^

@aus
Copy link
Collaborator Author

aus commented May 18, 2020

I have a fork here with some other useful PRs merged. Check the red branch.

https://github.com/aus/chisel/tree/red

@jpillora
Copy link
Owner

Looks good! Will test tonight and get this merged :) Sorry guys

@jpillora jpillora closed this in 68050d0 May 20, 2020
@jpillora jpillora merged commit 6d83df3 into jpillora:master May 20, 2020
@jpillora
Copy link
Owner

Merged, can you guys please test

Thanks again @aus, I ended up merging your red branch since it was newer (And made a few minor edits here and there, see 68050d0)

@aus
Copy link
Collaborator Author

aus commented May 20, 2020

Awesome! Thanks for the merge @jpillora. And thanks for creating chisel! It's been really useful for me. I will test the release.

Also, there were a few additional minor changes in my branch that may not be reflected in the changelog:

The DialContext is useful if you are creating a chisel client and need to modify the connect behavior. I created aus/proxyplease for this purpose. A DialContext from aus/proxyplease enables my chisel client to transparently authenticate against a Kerberos HTTP proxy via SSPI. proxyplease might be worth integrating into chisel as a dependency, but my code probably needs a bit more testing and cleanup.

@jpillora
Copy link
Owner

Oh yea I saw those in there, forgot to mention

Cool looks good - I'm doing some Go+kerberos stuff at work at the moment actually, will take a look

@malcomvetter
Copy link

Merged, can you guys please test

Thanks again @aus, I ended up merging your red branch since it was newer (And made a few minor edits here and there, see 68050d0)

Thanks!

@n4kre
Copy link

n4kre commented Apr 25, 2021

Hi @jpillora,

Oh yea I saw those in there, forgot to mention

Cool looks good - I'm doing some Go+kerberos stuff at work at the moment actually, will take a look

For chisel clients in Windows environments, the following two extra options would be awesome:

  • automatic HTTP CONNECT proxy selection selection based on on system settings;
  • authenticate against this proxy using SSPI (Negotiate / Kerberos / NTLM).

In addition to the work from @aus, maybe the Px (Python) implementation can help.

Essentially, it would be pretty cool to be able to enjoy the Px features within chisel directly. :)
A typical use case would be a red teaming operation where user credentials are unknown and one must go through a corporate proxy (unknown a priori: based on the Windows proxy settings / PAC) enforcing Kerberos or NTLM authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants