Skip to content

Commit 49d3826

Browse files
committed
Land rapid7#19377, Add compressinon to php/base64
This enables users to set a datastore option in enocoders/php/base64 which will compress the payload using zlib, greatly reducing its size
2 parents 3ad24b4 + 573643a commit 49d3826

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

modules/encoders/php/base64.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ def initialize
1717
'Author' => 'egypt',
1818
'License' => BSD_LICENSE,
1919
'Arch' => ARCH_PHP)
20+
register_options(
21+
[
22+
OptBool.new('Compress', [ true, 'Compress the payload with zlib', false ]) # Disabled by default as it relies on having php compiled with zlib, which might not be available on come exotic setups.
23+
],
24+
self.class)
2025
end
2126

2227
def encode_block(state, buf)
@@ -26,6 +31,12 @@ def encode_block(state, buf)
2631
raise BadcharError if state.badchars.include?(c)
2732
end
2833

34+
if datastore['Compress']
35+
%w[g z u n c o m p r e s s].uniq.each do |c|
36+
raise BadcharError if state.badchars.include?(c)
37+
end
38+
end
39+
2940
# Modern versions of PHP choke on unquoted literal strings.
3041
quote = "'"
3142
if state.badchars.include?("'")
@@ -34,6 +45,10 @@ def encode_block(state, buf)
3445
quote = '"'
3546
end
3647

48+
if datastore['Compress']
49+
buf = Zlib::Deflate.deflate(buf)
50+
end
51+
3752
# PHP escapes quotes by default with magic_quotes_gpc, so we use some
3853
# tricks to get around using them.
3954
#
@@ -98,6 +113,10 @@ def encode_block(state, buf)
98113
# cause a syntax error. Remove any trailing dots.
99114
b64.chomp!('.')
100115

101-
return 'eval(base64_decode(' + quote + b64 + quote + '));'
116+
if datastore['Compress']
117+
return 'eval(gzuncompress(base64_decode(' + quote + b64 + quote + ')));'
118+
else
119+
return 'eval(base64_decode(' + quote + b64 + quote + '));'
120+
end
102121
end
103122
end

0 commit comments

Comments
 (0)