CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/encoders/php/minify.rb
Views: 1904
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
43
44