Skip to content

Commit 5b94c7e

Browse files
committed
Add an encoder to minify php payloads
```console $ ./msfvenom --platform php -a php -p php/reverse_php | ./msfvenom -e php/base64 --platform php -a php | php -l Attempting to read payload from STDIN... No encoder specified, outputting raw payload Payload size: 3010 bytes Found 1 compatible encoders Attempting to encode payload with 1 iterations of php/base64 php/base64 succeeded with size 4052 (iteration=0) php/base64 chosen with final size 4052 Payload size: 4052 bytes No syntax errors detected in Standard input code $ ./msfvenom --platform php -a php -p php/reverse_php -e php/minify | ./msfvenom -e php/base64 --platform php -a php | php -l Attempting to read payload from STDIN... Found 1 compatible encoders Attempting to encode payload with 1 iterations of php/minify php/minify succeeded with size 2109 (iteration=0) php/minify chosen with final size 2109 Payload size: 2109 bytes Found 1 compatible encoders Attempting to encode payload with 1 iterations of php/base64 php/base64 succeeded with size 2839 (iteration=0) php/base64 chosen with final size 2839 Payload size: 2839 bytes No syntax errors detected in Standard input code $ ```
1 parent db55e5e commit 5b94c7e

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)