Skip to content

Commit ccb0c1a

Browse files
authored
Merge pull request rapid7#19993 from h00die-gr3y/cmd-enc-base64
BUGFIX: cmd encoder base64
2 parents a429732 + 9a60caf commit ccb0c1a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

modules/encoders/cmd/base64.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def initialize
3333

3434
#
3535
# Encodes the payload
36+
# All unnecessary spaces from your payload inside the () are removed to avoid shell POSIX command lauguage conflicts
37+
# The only things allowed after compound commands are redirections, shell keywords, and the various command separators
38+
# such as (;, &, |, &&, ||)
3639
#
3740
def encode_block(state, buf)
3841
return buf if (buf.bytes & state.badchars.bytes).empty?
@@ -48,7 +51,7 @@ def encode_block(state, buf)
4851
when 'base64'
4952
raise EncodingError if (state.badchars.bytes & '(|)'.bytes).any?
5053

51-
base64_decoder = '(base64 --decode || base64 -d)'
54+
base64_decoder = '(base64 --decode||base64 -d)'
5255
when 'base64-long'
5356
base64_decoder = 'base64 --decode'
5457
when 'base64-short'
@@ -58,9 +61,9 @@ def encode_block(state, buf)
5861
else
5962
# find a decoder at runtime if we can use the necessary characters
6063
if (state.badchars.bytes & '(|)>/&'.bytes).empty?
61-
base64_decoder = '((command -v base64 >/dev/null && (base64 --decode || base64 -d)) || (command -v openssl >/dev/null && openssl enc -base64 -d))'
64+
base64_decoder = '((command -v base64>/dev/null&&(base64 --decode||base64 -d))||(command -v openssl>/dev/null&&openssl enc -base64 -d))'
6265
elsif (state.badchars.bytes & '(|)'.bytes).empty?
63-
base64_decoder = '(base64 --decode || base64 -d)'
66+
base64_decoder = '(base64 --decode||base64 -d)'
6467
else
6568
base64_decoder = 'openssl enc -base64 -d'
6669
end

0 commit comments

Comments
 (0)