Skip to content

Commit

Permalink
Add additional platforms and decoders
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroSteiner committed Feb 12, 2024
1 parent 994a207 commit be1b7ba
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions modules/encoders/cmd/base64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def initialize
},
'Author' => 'Spencer McIntyre',
'Arch' => ARCH_CMD,
'Platform' => %w[linux unix],
'Platform' => %w[bsd bsdi linux osx solaris unix],
'EncoderType' => Msf::Encoder::Type::CmdPosixBase64)

register_advanced_options(
[
OptString.new('Base64Decoder', [ false, 'The binary to use for base64 decoding', '', %w[base64 openssl] ])
OptString.new('Base64Decoder', [ false, 'The binary to use for base64 decoding', '', %w[base64 base64-long base64-short openssl] ])
],
self.class
)
Expand All @@ -46,23 +46,32 @@ def encode_block(state, buf)
base64_buf = Base64.strict_encode64(buf)
case datastore['Base64Decoder']
when 'base64'
raise EncodingError if (state.badchars.bytes & '(|)'.bytes).any?

base64_decoder = '(base64 --decode || base64 -d)'
when 'base64-long'
base64_decoder = 'base64 --decode'
when 'base64-short'
base64_decoder = 'base64 -d'
when 'openssl'
base64_decoder = 'openssl enc -base64 -d'
else
# find a decoder at runtime if we can use the necessary characters
if (state.badchars.bytes & '(|)>/&'.bytes).empty?
base64_decoder = '((command -v base64 >/dev/null && (base64 --decode || base64 -d)) || (command -v openssl >/dev/null && openssl enc -base64 -d))'
elsif (state.badchars.bytes & '(|)'.bytes).empty?
base64_decoder = '(base64 --decode || base64 -d)'
else
base64_decoder = 'base64 -d'
base64_decoder = 'openssl enc -base64 -d'
end
end

if (state.badchars.bytes & '|'.bytes).empty?
buf = "echo #{base64_buf}|#{base64_decoder}|sh"
elsif (state.badchars.bytes & '<()'.bytes).empty?
buf = "sh < <(#{base64_decoder} < <(echo #{base64_buf}))"
elsif (state.badchars.bytes & '<`\''.bytes).empty?
buf = "sh<<<`#{base64_decoder}<<<'#{base64_buf}'`"
else
raise EncodingError
end
Expand Down

0 comments on commit be1b7ba

Please sign in to comment.