Skip to content

Instantly share code, notes, and snippets.

@w1k1n9cc
Forked from Joeviocoe/qvm-portfwd-socat
Created May 31, 2018 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w1k1n9cc/d7f3ed4f5477b470b7816d6baa4af5be to your computer and use it in GitHub Desktop.
Save w1k1n9cc/d7f3ed4f5477b470b7816d6baa4af5be to your computer and use it in GitHub Desktop.
Qubes-OS socket connection to allow external connections
#!/bin/bash
NetVM=$1
TargetVM=$2
Service=$3
TCP_Port=$4
wasrunning=$(qvm-ls | grep $TargetVM | grep -i RUNNING)
echo -ne "TCP socket connection for $Service from $NetVM to $TargetVM on port $TCP_Port...\nPress Any Key to End\n\n"
trap cleanup 1 2 3 6 15
cleanup() {
qvm-run -p -u root $NetVM "iptables-save | grep -v 'SOCAT_PortFwd-$Service' | iptables-restore"
qvm-run -p -u root $NetVM "pkill -HUP -f 'socat -d -d TCP-LISTEN:$TCP_Port'"
if [ -z "$wasrunning" ] ; then qvm-shutdown $TargetVM ; fi
}
qvm-start --skip-if-running $TargetVM
qvm-run -p -u root $NetVM "iptables -I INPUT 5 -p tcp --dport $TCP_Port -m conntrack --ctstate NEW -j ACCEPT -m comment --comment 'SOCAT_PortFwd-$Service'"
qvm-run -p -u root $NetVM "socat -d -d TCP-LISTEN:$TCP_Port,reuseaddr,fork EXEC:'qrexec-client-vm $TargetVM $Service'" &
read -p ""
cleanup
sleep 5
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment