Class: Msf::Serializer::ReadableText

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/base/serializer/readable_text.rb

Overview

This class formats information in a plain-text format that is meant to be displayed on a console or some other non-GUI medium.

Constant Summary collapse

DefaultColumnWrap =

Default number of characters to wrap at.

70
DefaultIndent =

Default number of characters to indent.

2

Class Method Summary collapse

Class Method Details

.dump_advanced_options(mod, indent = '') ⇒ String

Dumps the advanced options associated with the supplied module.


345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/msf/base/serializer/readable_text.rb', line 345

def self.dump_advanced_options(mod, indent = '')
  output = ''
  pad    = indent

  mod.options.sorted.each { |entry|
    name, opt = entry

    next if (!opt.advanced?)

    val = mod.datastore[name] || opt.default.to_s
    desc = word_wrap(opt.desc, indent.length + 3)
    desc = desc.slice(indent.length + 3, desc.length)

    output << pad + "Name           : #{name}\n"
    output << pad + "Current Setting: #{val}\n"
    output << pad + "Description    : #{desc}\n"
  }

  return output
end

.dump_auxiliary_actions(mod, indent = '', h = nil) ⇒ String

Dumps an auxiliary's actions


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/msf/base/serializer/readable_text.rb', line 94

def self.dump_auxiliary_actions(mod, indent = '', h = nil)
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent.length,
    'Header'  => h,
    'Columns' =>
      [
        'Name',
        'Description'
      ])

  mod.actions.each_with_index { |target, idx|
    tbl << [ target.name || 'All' , target.description || '' ]
  }

  tbl.to_s + "\n"
end

.dump_auxiliary_module(mod, indent = '') ⇒ String

Dumps information about an auxiliary module.


198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/msf/base/serializer/readable_text.rb', line 198

def self.dump_auxiliary_module(mod, indent = '')
  output  = "\n"
  output << "       Name: #{mod.name}\n"
  output << "     Module: #{mod.fullname}\n"
  output << "    License: #{mod.license}\n"
  output << "       Rank: #{mod.rank_to_s.capitalize}\n"
  output << "\n"

  # Authors
  output << "Provided by:\n"
  mod.each_author { |author|
    output << indent + author.to_s + "\n"
  }
  output << "\n"

  # Options
  if (mod.options.has_options?)
    output << "Basic options:\n"
    output << dump_options(mod, indent)
    output << "\n"
  end

  # Description
  output << "Description:\n"
  output << word_wrap(Rex::Text.compress(mod.description))
  output << "\n"

  # References
  output << dump_references(mod, indent)

  return output
end

.dump_basic_module(mod, indent = '') ⇒ String

Dumps information about a module, just the basics.


275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/msf/base/serializer/readable_text.rb', line 275

def self.dump_basic_module(mod, indent = '')
  # General
  output  = "\n"
  output << "       Name: #{mod.name}\n"
  output << "     Module: #{mod.fullname}\n"
  output << "   Platform: #{mod.platform_to_s}\n"
  output << "       Arch: #{mod.arch_to_s}\n"
  output << "       Rank: #{mod.rank_to_s.capitalize}\n"
  output << "\n"

  # Authors
  output << "Provided by:\n"
  mod.each_author { |author|
    output << indent + author.to_s + "\n"
  }
  output << "\n"

  # Description
  output << "Description:\n"
  output << word_wrap(Rex::Text.compress(mod.description))
  output << "\n"

  output << dump_references(mod, indent)

  output << "\n"

  return output

end

.dump_compatible_payloads(exploit, indent = '', h = nil) ⇒ String

Dumps the table of payloads that are compatible with the supplied exploit.


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/msf/base/serializer/readable_text.rb', line 119

def self.dump_compatible_payloads(exploit, indent = '', h = nil)
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent.length,
    'Header'  => h,
    'Columns' =>
      [
        'Name',
        'Description',
      ])

  exploit.compatible_payloads.each { |entry|
    tbl << [ entry[0], entry[1].new.description ]
  }

  tbl.to_s + "\n"
end

.dump_datastore(name, ds, indent = DefaultIndent, col = DefaultColumnWrap) ⇒ String

Dumps the contents of a datastore.


419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/msf/base/serializer/readable_text.rb', line 419

def self.dump_datastore(name, ds, indent = DefaultIndent, col = DefaultColumnWrap)
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent,
    'Header'  => name,
    'Columns' =>
      [
        'Name',
        'Value'
      ])

  ds.keys.sort.each { |k|
    tbl << [ k, (ds[k] != nil) ? ds[k].to_s : '' ]
  }

  return ds.length > 0 ? tbl.to_s : "#{tbl.header_to_s}No entries in data store.\n"
end

.dump_evasion_options(mod, indent = '') ⇒ String

Dumps the evasion options associated with the supplied module.


371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/msf/base/serializer/readable_text.rb', line 371

def self.dump_evasion_options(mod, indent = '')
  output = ''
  pad    = indent

  mod.options.sorted.each { |entry|
    name, opt = entry

    next if (!opt.evasion?)

    val = mod.datastore[name] || opt.default || ''

    desc = word_wrap(opt.desc, indent.length + 3)
    desc = desc.slice(indent.length + 3, desc.length)

    output << pad + "Name           : #{name}\n"
    output << pad + "Current Setting: #{val}\n"
    output << pad + "Description    : #{desc}\n"
  }

  return output
end

.dump_exploit_module(mod, indent = '') ⇒ String

Dumps information about an exploit module.


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/msf/base/serializer/readable_text.rb', line 141

def self.dump_exploit_module(mod, indent = '')
  output  = "\n"
  output << "       Name: #{mod.name}\n"
  output << "     Module: #{mod.fullname}\n"
  output << "   Platform: #{mod.platform_to_s}\n"
  output << " Privileged: " + (mod.privileged? ? "Yes" : "No") + "\n"
  output << "    License: #{mod.license}\n"
  output << "       Rank: #{mod.rank_to_s.capitalize}\n"
  output << "\n"

  # Authors
  output << "Provided by:\n"
  mod.each_author { |author|
    output << indent + author.to_s + "\n"
  }
  output << "\n"

  # Targets
  output << "Available targets:\n"
  output << dump_exploit_targets(mod, indent)

  # Options
  if (mod.options.has_options?)
    output << "Basic options:\n"
    output << dump_options(mod, indent)
    output << "\n"
  end

  # Payload information
  if (mod.payload_info.length)
    output << "Payload information:\n"
    if (mod.payload_space)
      output << indent + "Space: " + mod.payload_space.to_s + "\n"
    end
    if (mod.payload_badchars)
      output << indent + "Avoid: " + mod.payload_badchars.length.to_s + " characters\n"
    end
    output << "\n"
  end

  # Description
  output << "Description:\n"
  output << word_wrap(Rex::Text.compress(mod.description))
  output << "\n"

  # References
  output << dump_references(mod, indent)

  return output

end

.dump_exploit_target(mod, indent = '', h = nil) ⇒ String

Dumps the exploit's selected target


72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/msf/base/serializer/readable_text.rb', line 72

def self.dump_exploit_target(mod, indent = '', h = nil)
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent.length,
    'Header'  => h,
    'Columns' =>
      [
        'Id',
        'Name',
      ])

  tbl << [ mod.target_index, mod.target.name || 'All' ]

  tbl.to_s + "\n"
end

.dump_exploit_targets(mod, indent = '', h = nil) ⇒ String

Dumps an exploit's targets.


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/msf/base/serializer/readable_text.rb', line 48

def self.dump_exploit_targets(mod, indent = '', h = nil)
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent.length,
    'Header'  => h,
    'Columns' =>
      [
        'Id',
        'Name',
      ])

  mod.targets.each_with_index { |target, idx|
    tbl << [ idx.to_s, target.name || 'All' ]
  }

  tbl.to_s + "\n"
end

.dump_generic_module(mod, indent = '') ⇒ Object

No current use


306
307
# File 'lib/msf/base/serializer/readable_text.rb', line 306

def self.dump_generic_module(mod, indent = '')
end

.dump_jobs(framework, verbose = false, indent = DefaultIndent, col = DefaultColumnWrap) ⇒ String

Dumps the list of running jobs.


497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/msf/base/serializer/readable_text.rb', line 497

def self.dump_jobs(framework, verbose = false, indent = DefaultIndent, col = DefaultColumnWrap)
  columns = [ 'Id', 'Name' ]

  if (verbose)
    columns << "Payload"
    columns << "LPORT"
    columns << "URIPATH"
    columns << "Start Time"
  end

  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent,
    'Header'  => "Jobs",
    'Columns' => columns
    )


  # jobs are stored as a hash with the keys being a numeric job_id.
  framework.jobs.keys.sort{|a,b| a.to_i <=> b.to_i }.each { |k|
    row = [ k, framework.jobs[k].name ]
    if (verbose)
      ctx = framework.jobs[k].ctx
      uripath = ctx[0].get_resource if ctx[0].respond_to?(:get_resource)
      uripath = ctx[0].datastore['URIPATH'] if uripath.nil?
      row << (ctx[1].nil? ? (ctx[0].datastore['PAYLOAD'] || "") : ctx[1].refname)
      row << (ctx[0].datastore['LPORT'] || "")
      row << (uripath || "")
      row << (framework.jobs[k].start_time || "")
    end

    tbl << row
  }

  return framework.jobs.keys.length > 0 ? tbl.to_s : "#{tbl.header_to_s}No active jobs.\n"
end

.dump_module(mod, indent = " ") ⇒ String

Returns a formatted string that contains information about the supplied module instance.


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/msf/base/serializer/readable_text.rb', line 21

def self.dump_module(mod, indent = "  ")
  case mod.type
    when MODULE_PAYLOAD
      return dump_payload_module(mod, indent)
    when MODULE_NOP
      return dump_basic_module(mod, indent)
    when MODULE_ENCODER
      return dump_basic_module(mod, indent)
    when MODULE_EXPLOIT
      return dump_exploit_module(mod, indent)
    when MODULE_AUX
      return dump_auxiliary_module(mod, indent)
    when MODULE_POST
      return dump_basic_module(mod, indent)
    else
      return dump_generic_module(mod, indent)
  end
end

.dump_options(mod, indent = '') ⇒ String

Dumps the list of options associated with the supplied module.


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/msf/base/serializer/readable_text.rb', line 315

def self.dump_options(mod, indent = '')
  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent.length,
    'Columns' =>
      [
        'Name',
        'Current Setting',
        'Required',
        'Description'
      ])

  mod.options.sorted.each { |entry|
    name, opt = entry

    next if (opt.advanced?)
    next if (opt.evasion?)

    val_display = opt.display_value(mod.datastore[name] || opt.default)

    tbl << [ name, val_display, opt.required? ? "yes" : "no", opt.desc ]
  }

  return tbl.to_s
end

.dump_payload_module(mod, indent = '') ⇒ String

Dumps information about a payload module.


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/msf/base/serializer/readable_text.rb', line 236

def self.dump_payload_module(mod, indent = '')
  # General
  output  = "\n"
  output << "       Name: #{mod.name}\n"
  output << "     Module: #{mod.fullname}\n"
  output << "   Platform: #{mod.platform_to_s}\n"
  output << "       Arch: #{mod.arch_to_s}\n"
  output << "Needs Admin: " + (mod.privileged? ? "Yes" : "No") + "\n"
  output << " Total size: #{mod.size}\n"
  output << "       Rank: #{mod.rank_to_s.capitalize}\n"
  output << "\n"

  # Authors
  output << "Provided by:\n"
  mod.each_author { |author|
    output << indent + author.to_s + "\n"
  }
  output << "\n"

  # Options
  if (mod.options.has_options?)
    output << "Basic options:\n"
    output << dump_options(mod)
    output << "\n"
  end

  # Description
  output << "Description:\n"
  output << word_wrap(Rex::Text.compress(mod.description))
  output << "\n\n"

  return output
end

.dump_references(mod, indent = '') ⇒ String

Dumps the references associated with the supplied module.


398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/msf/base/serializer/readable_text.rb', line 398

def self.dump_references(mod, indent = '')
  output = ''

  if (mod.respond_to? :references and mod.references and mod.references.length > 0)
    output << "References:\n"
    mod.references.each { |ref|
      output << indent + ref.to_s + "\n"
    }
    output << "\n"
  end

  output
end

.dump_sessions(framework, opts = {}) ⇒ String

Dumps the list of active sessions.

Options Hash (opts):

  • :session_ids (Array)

    the list of sessions to dump (no effect).

  • :verbose (Boolean)

    gives more information if set to true.

  • :indent (Integer)

    set the indentation amount.

  • :col (Integer)

    the column wrap width.


447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/msf/base/serializer/readable_text.rb', line 447

def self.dump_sessions(framework, opts={})
  ids = (opts[:session_ids] || framework.sessions.keys).sort
  verbose = opts[:verbose] || false
  indent = opts[:indent] || DefaultIndent
  col = opts[:col] || DefaultColumnWrap

  columns =
    [
      'Id',
      'Type',
      'Information',
      'Connection'
    ]

  columns << 'Via' if verbose

  tbl = Rex::Ui::Text::Table.new(
    'Indent'  => indent,
    'Header'  => "Active sessions",
    'Columns' => columns)

  framework.sessions.each_sorted { |k|
    session = framework.sessions[k]

    sinfo = session.info.to_s
    # Arbitrarily cut it at 80 columns
    if sinfo.length > 80
      sinfo = sinfo[0,77] + "..."
    end

    row = [ session.sid.to_s, session.type.to_s, sinfo, session.tunnel_to_s + " (#{session.session_host})" ]
    if session.respond_to? :platform
      row[1] += " " + session.platform
    end
    row << session.via_exploit if verbose and session.via_exploit

    tbl << row
  }

  return framework.sessions.length > 0 ? tbl.to_s : "#{tbl.header_to_s}No active sessions.\n"
end

.word_wrap(str, indent = DefaultIndent, col = DefaultColumnWrap) ⇒ String

Jacked from Ernest Ellingson <erne [at] powernav.com>, modified a bit to add indention


540
541
542
# File 'lib/msf/base/serializer/readable_text.rb', line 540

def self.word_wrap(str, indent = DefaultIndent, col = DefaultColumnWrap)
  return Rex::Text.wordwrap(str, indent, col)
end