Class: Msf::Ui::Console::CommandDispatcher::Payload

Inherits:
Object
  • Object
show all
Includes:
ModuleCommandDispatcher
Defined in:
lib/msf/ui/console/command_dispatcher/payload.rb

Overview

Payload module command dispatcher.

Constant Summary collapse

@@generate_opts =
Rex::Parser::Arguments.new(
"-b" => [ true,  "The list of characters to avoid: '\\x00\\xff'"        ],
"-E" => [ false, "Force encoding."                                      ],
"-e" => [ true,  "The name of the encoder module to use."               ],
"-h" => [ false, "Help banner."                                         ],
"-o" => [ true,  "A comma separated list of options in VAR=VAL format." ],
"-s" => [ true,  "NOP sled length."                                     ],
"-f" => [ true,  "The output file name (otherwise stdout)"              ],
"-t" => [ true,  "The output format: #{supported_formats.join(',')}"    ],
"-p" => [ true,  "The Platform for output."                             ],
"-k" => [ false, "Keep the template executable functional"              ],
"-x" => [ true,  "The executable template to use"                       ],
"-i" => [ true,  "the number of encoding iterations."                   ])

Instance Attribute Summary

Attributes included from Msf::Ui::Console::CommandDispatcher

#driver

Attributes included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from ModuleCommandDispatcher

#check_multiple, #check_progress, #check_show_progress, #check_simple, #cmd_check, #cmd_pry, #cmd_pry_help, #cmd_reload, #cmd_reload_help, #mod, #mod=, #reload

Methods included from Msf::Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #defanged?, #framework, #initialize, #log_error

Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #help_to_s, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_filenames, #update_prompt

Instance Method Details

#cmd_generate(*args) ⇒ Object

Generates a payload.


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/msf/ui/console/command_dispatcher/payload.rb', line 55

def cmd_generate(*args)

  # Parse the arguments
  encoder_name = nil
  sled_size    = nil
  option_str   = nil
  badchars     = nil
  type         = "ruby"
  ofile        = nil
  iter         = 1
  force        = nil
  template     = nil
  plat         = nil
  keep         = false

  @@generate_opts.parse(args) { |opt, idx, val|
    case opt
      when '-b'
        badchars = Rex::Text.hex_to_raw(val)
      when '-e'
        encoder_name = val
      when '-E'
        force = true
      when '-o'
        option_str = val
      when '-s'
        sled_size = val.to_i
      when '-t'
        type = val
      when '-f'
        ofile = val
      when '-i'
        iter = val
      when '-k'
        keep = true
      when '-p'
        plat = val
      when '-x'
        template = val
      when '-h'
        print(
          "Usage: generate [options]\n\n" +
          "Generates a payload.\n" +
          @@generate_opts.usage)
        return true
    end
  }
  if (encoder_name.nil? and mod.datastore['ENCODER'])
    encoder_name = mod.datastore['ENCODER']
  end


  # Generate the payload
  begin
    buf = mod.generate_simple(
      'BadChars'    => badchars,
      'Encoder'     => encoder_name,
      'Format'      => type,
      'NopSledSize' => sled_size,
      'OptionStr'   => option_str,
      'ForceEncode' => force,
      'Template'    => template,
      'Platform'    => plat,
      'KeepTemplateWorking' => keep,
      'Iterations'  => iter)
  rescue
    log_error("Payload generation failed: #{$!}")
    return false
  end

  if(not ofile)
    # Display generated payload
    print(buf)
  else
    print_status("Writing #{buf.length} bytes to #{ofile}...")
    fd = File.open(ofile, "wb")
    fd.write(buf)
    fd.close
  end

  return true

end

#commandsObject

Returns the hash of commands specific to payload modules.


39
40
41
42
43
# File 'lib/msf/ui/console/command_dispatcher/payload.rb', line 39

def commands
  super.update({
    "generate" => "Generates a payload",
  })
end

#nameObject

Returns the command dispatcher name.


48
49
50
# File 'lib/msf/ui/console/command_dispatcher/payload.rb', line 48

def name
  return "Payload"
end