Skip to content

Commit 7b75bd6

Browse files
committed
Cache remote Python binary name
1 parent 17a37a9 commit 7b75bd6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

modules/post/multi/manage/shell_to_meterpreter.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,21 @@ def run
216216
# @return String/nil A string if a Python binary can be found, else nil.
217217
#
218218
def remote_python_binary
219+
return @remote_python_binary if defined?(@remote_python_binary)
220+
219221
python_exists_regex = /Python (2|3)\.(\d)/
220-
# We could cache these values
221-
return 'python' if cmd_exec('python -V 2>&1') =~ python_exists_regex
222-
return 'python2' if cmd_exec('python2 -V 2>&1') =~ python_exists_regex
223-
return 'python3' if cmd_exec('python3 -V 2>&1') =~ python_exists_regex
224222

225-
nil
223+
if cmd_exec('python3 -V 2>&1') =~ python_exists_regex
224+
@remote_python_binary = 'python3'
225+
elsif cmd_exec('python -V 2>&1') =~ python_exists_regex
226+
@remote_python_binary = 'python'
227+
elsif cmd_exec('python2 -V 2>&1') =~ python_exists_regex
228+
@remote_python_binary = 'python2'
229+
else
230+
@remote_python_binary = nil
231+
end
232+
233+
@remote_python_binary
226234
end
227235

228236
def transmit_payload(exe, platform)

0 commit comments

Comments
 (0)