Skip to content

Commit 4712bb4

Browse files
committed
Land rapid7#19435, Add php minify encoder
This encoder minifies PHP payloads by removing spaces after keywords and before block openings. It removes comments, empty lines, new lines and leading and trailing spaces
2 parents 5f65ce2 + 5b94c7e commit 4712bb4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

modules/encoders/php/minify.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Encoder
7+
Rank = GreatRanking
8+
9+
def initialize
10+
super(
11+
'Name' => 'PHP Minify Encoder',
12+
'Description' => %q{
13+
This encoder minifies a PHP payload by removing leasing spaces, trailing
14+
new lines, comments, …
15+
},
16+
'Author' => 'Julien Voisin',
17+
'License' => BSD_LICENSE,
18+
'Arch' => ARCH_PHP)
19+
end
20+
21+
def encode_block(_, buf)
22+
# Remove comments
23+
buf.gsub!(/^\s*#.*$/, '')
24+
25+
# Remove spaces after keywords
26+
buf.gsub!(/^\s*(if|else|elsif|while|for|foreach)\s*\(/, '\1(')
27+
28+
# Remove spaces before block opening
29+
buf.gsub!(/\s*{$/, '{')
30+
31+
# Remove empty lines
32+
buf.squeeze!("\n")
33+
34+
# Remove leading/trailing spaces
35+
buf.gsub!(/^[ \t]+/, '')
36+
37+
# Remove new lines
38+
buf.gsub!(/([;{}])\n/, '\1')
39+
40+
return buf
41+
end
42+
end

0 commit comments

Comments
 (0)