@@ -250,8 +250,10 @@ def out(target, status, results)
250
250
end
251
251
252
252
# XML Output #
253
- # Hey, do u actually use this XML output? Then I'd love to hear from you for suggestions, changes, etc.
254
- # Does it bother you that some types of output are joined by commas but other types aren't?
253
+ # Does anyone use XML output?
254
+ # We'd love to hear any suggestions you may have!
255
+ # Does it bother you that some types of output are joined by commas
256
+ # but other types aren't?
255
257
class OutputXML < Output
256
258
def initialize ( f = STDOUT )
257
259
super
@@ -269,6 +271,16 @@ def escape(t)
269
271
text = t . to_s . dup
270
272
# use sort_by so that & is before ", etc.
271
273
@substitutions . sort_by { |a , b | a =="&" ? 0 : 1 } . map { |from , to | text . gsub! ( from , to ) }
274
+
275
+ # Encode all special characters
276
+ # More info: http://www.asciitable.com/
277
+ r = /[^\x20 -\x5A \x5E -\x7E ]/
278
+
279
+ # based on code for CGI.escape
280
+ text . gsub! ( r ) do |x |
281
+ '%' + x . unpack ( 'H2' * x . size ) . join ( '%' ) . upcase
282
+ end
283
+
272
284
text
273
285
end
274
286
@@ -277,11 +289,11 @@ def out(target, status, results)
277
289
@f . puts "<target>"
278
290
@f . puts "\t <uri>#{ escape ( target ) } </uri>"
279
291
@f . puts "\t <http-status>#{ escape ( status ) } </http-status>"
280
-
292
+
281
293
results . each do |plugin_name , plugin_results |
282
294
@f . puts "\t <plugin>"
283
295
@f . puts "\t \t <name>#{ escape ( plugin_name ) } </name>"
284
-
296
+
285
297
unless plugin_results . empty?
286
298
# important info in brief mode is version, type and ?
287
299
# what's the highest probability for the match?
@@ -301,28 +313,21 @@ def out(target, status, results)
301
313
filepath = plugin_results . map { |x |
302
314
x [ :filepath ] unless x [ :filepath ] . class ==Regexp } . flatten . compact . sort . uniq . join ( "," )
303
315
304
- accounts = plugin_results . map { |x |
305
- x [ :account ] unless x [ :account ] . class ==Regexp } . flatten . compact . sort . uniq . to_a
316
+ account = plugin_results . map { |x |
317
+ x [ :account ] unless x [ :account ] . class ==Regexp } . flatten . compact . sort . uniq . join ( "," )
306
318
modules = plugin_results . map { |x |
307
- x [ :module ] unless x [ :module ] . class ==Regexp } . flatten . compact . sort . uniq . to_a
308
-
319
+ x [ :module ] unless x [ :module ] . class ==Regexp } . flatten . compact . sort . uniq . join ( "," )
309
320
321
+ # Output results
310
322
@f . puts "\t \t <certainty>#{ escape ( certainty ) } </certainty>" if certainty and certainty < 100
311
323
version . map { |x | @f . puts "\t \t <version>#{ escape ( x ) } </version>" }
312
324
os . map { |x | @f . puts "\t \t <os>#{ escape ( x ) } </os>" }
313
- string . map { |x | @f . puts "\t \t <string>#{ escape ( x ) } </string>" }
325
+ string . map { |x | @f . puts "\t \t <string>#{ escape ( x ) } </string>" }
314
326
model . map { |x | @f . puts "\t \t <model>#{ escape ( x ) } </model>" }
315
327
firmware . map { |x | @f . puts "\t \t <firmware>#{ escape ( x ) } </firmware>" }
316
328
filepath . map { |x | @f . puts "\t \t <filepath>#{ escape ( x ) } </filepath>" }
317
-
318
- if accounts . size > 0
319
- accounts . map { |x | @f . puts "\t \t <account>#{ escape ( x ) } </account>" }
320
- @f . puts "\t \t <accounts>\n " + accounts . map { |x | "\t \t \t <accounts>#{ escape ( x ) } </accounts>" } . join ( "\n " ) + "\n \t \t </accounts>"
321
- end
322
-
323
- if modules . size > 0
324
- @f . puts "\t \t <modules>\n " + modules . map { |x | "\t \t \t <module>#{ escape ( x ) } </module>" } . join ( "\n " ) + "\n \t \t </modules>"
325
- end
329
+ account . map { |x | @f . puts "\t \t <account>#{ escape ( x ) } </account>" }
330
+ modules . map { |x | @f . puts "\t \t <module>#{ escape ( x ) } </module>" }
326
331
end
327
332
@f . puts "\t </plugin>"
328
333
end
@@ -351,6 +356,16 @@ def escape(t)
351
356
text = t . to_s . dup
352
357
# use sort_by so that & is before ", etc.
353
358
@substitutions . sort_by { |a , b | a =="&" ? 0 : 1 } . map { |from , to | text . gsub! ( from , to ) }
359
+
360
+ # Encode all special characters
361
+ # More info: http://www.asciitable.com/
362
+ r = /[^\x20 -\x5A \x5E -\x7E ]/
363
+
364
+ # based on code for CGI.escape
365
+ text . gsub! ( r ) do |x |
366
+ '%' + x . unpack ( 'H2' * x . size ) . join ( '%' ) . upcase
367
+ end
368
+
354
369
text
355
370
end
356
371
0 commit comments