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

Transparent SSH SOCKS proxy for Qubes #1536

Open
hdevalence opened this issue Dec 22, 2015 · 18 comments
Open

Transparent SSH SOCKS proxy for Qubes #1536

hdevalence opened this issue Dec 22, 2015 · 18 comments
Labels
C: other community dev This is being developed by a member of the community rather than a core Qubes developer. P: major Priority: major. Between "default" and "critical" in severity. S: in progress Status: in progress. The assignee is currently working on this issue. T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality.

Comments

@hdevalence
Copy link

hdevalence commented Dec 22, 2015

Community Dev: @Zrubi
PoC: https://groups.google.com/d/msgid/qubes-devel/d9731ee0-e89b-75e2-f024-83e59d02d8c8%40zrubi.hu


Hi. I'd like to implement a transparent SOCKS proxy for Qubes using SSH.

This way a user can transparently tunnel all traffic from a particular AppVM through another server, without having to configure a VPN or worry about a fail-open setup.

I think it should work roughly as follows:

  1. The user creates the proxyvm and enables the qubes-ssh-proxy service:

    qvm-create -p sys-ssh-proxy
    qvm-service sys-ssh-proxy -e qubes-ssh-proxy
    
  2. In the template, the user installs the ssh proxy:

    sudo dnf install qubes-ssh-proxy
    
  3. In the proxyVM, the user configures the ssh proxy:

    sudo ssh-keygen -q -N "" -C qubes-ssh-proxy -t ed25519 -f /rw/config/id_qubes_ssh
    sudo sed -i 's/XXXX/user@host/' /rw/config/qubes-ssh-proxy.service
    cat /rw/config/id_qubes_ssh.pub
    
  4. The user adds the ssh public key from the previous step to their .authorized_keys file on the server.

  5. The user sets the new ProxyVM as the NetVM for some AppVM. All TCP traffic from the AppVM is sent through the ssh tunnel and all UDP traffic is dropped.

Internally, ssh is run as a systemd service, so that restarting on failure, logging, etc. all happens automatically, and iptables sends incoming traffic through the tunnel.

Next, it would be good to automate the setup using the configuration management, so that a user just has to input user@hostname and they're given the generated ssh key to add to the server.

@marmarek marmarek added T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality. help wanted This issue will probably not get done in a timely fashion without help from community contributors. P: major Priority: major. Between "default" and "critical" in severity. labels Jan 6, 2016
@marmarek marmarek added this to the Far in the future milestone Jan 6, 2016
@Zrubi
Copy link
Member

Zrubi commented Feb 25, 2016

Hi,

Actually I have a working solution for this.
The only requirements are:

  • redsocks (we need to make rpm package)
  • iptables (with some magic settings ;)

My intention was not to make a failsafe/anti leaking setup - but it is completely depends on the actual iptables rules.

@Zrubi
Copy link
Member

Zrubi commented Feb 26, 2016

The current ipmlementation of qubes-firewall service are dropping the user changes ONLY in filter table, but leaving (saving) the nat table:

IPTABLES_SAVE=$(iptables-save | sed '/^\*filter/,/^COMMIT/d')
OUT=$(printf '%s\n%s\n' "$RULES" "$IPTABLES_SAVE" | sed 's/\\n\|\\x0a/\n/g' | iptables-restore 2>&1 || true)

This makes really hard to implement any custom rulesets needed such a service. because if it is calling the /rw/config/qubes-firewall-user-script There will be duplicated user defined rules/chains - unless I hack it around in that script...

@marmarek Is there any reason for this behavior?

Why not drop all the rules and recreate them from scratch?

@marmarek
Copy link
Member

This is one of the reason for discussion on new firewall API on qubes-devel.

andrewdavidwong added a commit that referenced this issue May 31, 2016
andrewdavidwong added a commit that referenced this issue Jun 7, 2016
@andrewdavidwong
Copy link
Member

@Zrubi, are you still working on this (or plan to)? (Asking for tracking purposes.)

andrewdavidwong added a commit that referenced this issue Jun 12, 2016
@Zrubi
Copy link
Member

Zrubi commented Jun 15, 2016

I'm not planning to work on this. Mainly because I don't believe in "leak prof" things the mass are "needs" (referring to a "leakproof" VPN hacks)

Currently I have a working transparent sock proxy solution but that is not worth publishing until the Qubes new firewall API is not released. The current Qubes firewall scripts may breaking/not refreshing the custom firewall rules.

@andrewdavidwong
Copy link
Member

Understood. Thanks!

andrewdavidwong added a commit that referenced this issue Jun 15, 2016
@hollyboy
Copy link

Hi, I used this tutorial https://linuxaria.com/article/redirect-all-tcp-traffic-through-transparent-socks5-proxy-in-linux
for set up ssh/proxy in ProxyVM, but i can't change settings IPTables for direct proxify traffic to another VM. Can you help me about this problem? Sorry about my English)

@hollyboy
Copy link

It's very important for my purposes. Thank you in advance.

@hollyboy
Copy link

P. S. I am not really understand about it.

@hollyboy
Copy link

@entr0py
Copy link

entr0py commented Nov 22, 2016

I would suggest taking a look at Qubes VPN documentation: https://www.qubes-os.org/doc/vpn/

It's not the same but you can get a feel for how traffic can be transparently routed through a proxyVM using iptables and learn about aspects that are specific to Qubes. Then, you'll need to move redsocks redirection from nat:OUTPUT to nat:PREROUTING and set up appropriate forwarding / dns rules.

@andrewdavidwong
Copy link
Member

@hollyboy: Please do not hijack GitHub issues for personal tech support. Please send a message to the qubes-users mailing list instead.

@Zrubi
Copy link
Member

Zrubi commented Dec 8, 2016

As I mentioned earlier, I have a working transparent SOCKS proxy solution based on redsocks:
http://darkk.net.ru/redsocks/

Now I'm created an .rpm package because there was no pre-build binary distributed jet for fedora.
I would not be able to handle the hassle to include it to the official fedora repos, but I think it is worth to include in qubes repos at least.

Sending the SRPM package to qubes-devel. This is building fine under F24, and F23
(and probably others too)
(I'm gonna make my scripts public as an usage example under Qubes)

andrewdavidwong added a commit that referenced this issue Dec 8, 2016
@jpouellet
Copy link
Contributor

jpouellet commented Mar 12, 2017

For being very fail-closed, you can use SSH's ProxyCommand option to invoke a qrexec service in a separate domain, which allows you to set the NetVM of the ProxyVM to none! The qrexec service can then enforce confidentiality and integrity of the channel and authenticity of the remote host by SSHing itself. You can then use SSH's tun/tap support (-w, -oTunnel={ethernet,point-to-point}) to transparently tunnel everything including UDP, broadcast ethernet frames, etc.

By far the most flexible and accident-proof solution I've found.

edit: for bonus leak-proofness, you can even make the ProxyVM actually be a NetVM so that you can't accidentally give it a NetVM.

andrewdavidwong added a commit that referenced this issue Apr 16, 2017
@v6ak
Copy link

v6ak commented Feb 11, 2018

Redsocks seems to be in Debian repository, so there seems to be no need to compile it unless you insist on Fedora. This way, you also get security updates.

How do you configure iptables for redsocks? EDIT: It seems that this is a good startpoing: https://gist.github.com/afriza/1097210 EDIT2: Hmm, not so easy. It does not affect the connected VMs and it is not much suitable for firewall script.

BTW, I've seen NetworkManager-SSH that is available in both Debian and Fedora repository. But this does not use SOCKS. It uses TUN/TAP over SSH. Its practical downside is that it has some requirements on the SSH server and the documentation requires root. So, it is not as easy solution as it looks.

andrewdavidwong added a commit that referenced this issue Feb 11, 2018
@Zrubi
Copy link
Member

Zrubi commented Feb 12, 2018 via email

andrewdavidwong added a commit that referenced this issue Feb 13, 2018
@andrewdavidwong andrewdavidwong added C: other community dev This is being developed by a member of the community rather than a core Qubes developer. S: needs review Status: needs review. Core devs must review contributed code for potential inclusion in Qubes OS. and removed help wanted This issue will probably not get done in a timely fashion without help from community contributors. labels Jun 9, 2019
@andrewdavidwong andrewdavidwong modified the milestones: Far in the future, Release 4.1 Jun 9, 2019
@andrewdavidwong
Copy link
Member

@Zrubi, would you mind packaging your contribution following our new package contribution procedure?

@andrewdavidwong andrewdavidwong added S: in progress Status: in progress. The assignee is currently working on this issue. and removed S: needs review Status: needs review. Core devs must review contributed code for potential inclusion in Qubes OS. labels Jun 9, 2019
@ghost
Copy link

ghost commented Dec 7, 2022

this project work for me https://github.com/hexstore/qubes-proxy

@andrewdavidwong andrewdavidwong removed this from the Release 4.2 milestone Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: other community dev This is being developed by a member of the community rather than a core Qubes developer. P: major Priority: major. Between "default" and "critical" in severity. S: in progress Status: in progress. The assignee is currently working on this issue. T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality.
Projects
None yet
Development

No branches or pull requests

8 participants