Skip to content

Commit b178ce1

Browse files
committed
allow the mixin to auto detect an available decoder binary
1 parent ce4aa60 commit b178ce1

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/msf/core/exploit/cmdstager_bourne.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(info = {})
2121

2222
register_advanced_options(
2323
[
24-
OptEnum.new( 'DECODER', [ true, 'The decoding binary to use', 'base64', ['base64', 'openssl', 'python', 'perl']]),
24+
OptEnum.new( 'DECODER', [ false, 'The decoding binary to use', 'auto', ['auto', 'base64', 'openssl', 'python', 'perl']]),
2525
], self.class)
2626
end
2727

@@ -30,8 +30,29 @@ def create_stager(exe)
3030
end
3131

3232
def generate_cmdstager(opts = {}, pl = nil)
33-
opts.merge!({ :decoder => datastore['DECODER'] })
3433
available_decoders = ['base64', 'openssl', 'python', 'perl']
34+
opts.merge!({ :decoder => datastore['DECODER'] })
35+
36+
if opts[:decoder] == 'auto'
37+
if self.respond_to? :execute_command_with_feedback
38+
available_decoders.each do |bin|
39+
which_result = execute_command_with_feedback("which #{bin}", opts).to_s
40+
which_result = which_result.strip
41+
if which_result.split.length == 1 and which_result.end_with?(bin)
42+
opts[:decoder] = bin
43+
break
44+
end
45+
end
46+
end
47+
48+
if opts[:decoder] == 'auto'
49+
print_error("Could not detect an appropriate decoder, try setting the DECODER option")
50+
raise ArgumentError
51+
else
52+
print_status("Command Stager using auto-detected decoder: #{opts[:decoder]}")
53+
end
54+
end
55+
3556
if not available_decoders.include?(opts[:decoder])
3657
print_error("Decoder must be one of #{available_decoders.join(', ')}")
3758
raise ArgumentError

lib/rex/exploitation/cmdstager/bourne.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def parts_to_commands(parts, opts)
6565
cmds
6666
end
6767

68-
6968
#
7069
# Generate the commands that will decode the file we just created
7170
#

modules/exploits/multi/ssh/sshexec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ def initialize
7979
)
8080
end
8181

82-
def execute_command(cmd, opts)
82+
def execute_command(cmd, opts = {})
8383
begin
8484
Timeout.timeout(3) do
85-
self.ssh_socket.exec!(cmd)
85+
self.ssh_socket.exec!("#{cmd}\n")
86+
end
87+
rescue ::Exception
88+
end
89+
end
90+
91+
def execute_command_with_feedback(cmd, opts = {})
92+
begin
93+
Timeout.timeout(3) do
94+
feedback = self.ssh_socket.exec!("#{cmd}\n")
95+
return feedback
8696
end
8797
rescue ::Exception
8898
end

0 commit comments

Comments
 (0)