whitespace/indentation
parent
ce23c2db53
commit
d091a32be8
|
@ -1,222 +1,215 @@
|
||||||
# -*- coding: binary -*-
|
# -*- coding: binary -*-
|
||||||
|
|
||||||
#
|
|
||||||
# Rex
|
|
||||||
#
|
|
||||||
|
|
||||||
require 'rex/ui/text/output/buffer/stdout'
|
require 'rex/ui/text/output/buffer/stdout'
|
||||||
|
|
||||||
|
|
||||||
module Msf
|
module Msf
|
||||||
module Ui
|
module Ui
|
||||||
module Console
|
module Console
|
||||||
module CommandDispatcher
|
module CommandDispatcher
|
||||||
|
#
|
||||||
|
# {CommandDispatcher} for commands related to background jobs in Metasploit Framework.
|
||||||
|
#
|
||||||
|
class Jobs
|
||||||
|
include Msf::Ui::Console::CommandDispatcher
|
||||||
|
|
||||||
#
|
@@jobs_opts = Rex::Parser::Arguments.new(
|
||||||
# {CommandDispatcher} for commands related to background jobs in Metasploit Framework.
|
"-h" => [ false, "Help banner." ],
|
||||||
#
|
"-k" => [ true, "Terminate jobs by job ID and/or range." ],
|
||||||
class Jobs
|
"-K" => [ false, "Terminate all running jobs." ],
|
||||||
|
"-i" => [ true, "Lists detailed information about a running job."],
|
||||||
|
"-l" => [ false, "List all running jobs." ],
|
||||||
|
"-v" => [ false, "Print more detailed info. Use with -i and -l" ]
|
||||||
|
)
|
||||||
|
|
||||||
include Msf::Ui::Console::CommandDispatcher
|
def commands
|
||||||
|
{
|
||||||
|
"jobs" => "Displays and manages jobs",
|
||||||
|
"rename_job" => "Rename a job",
|
||||||
|
"kill" => "Kill a job",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
@@jobs_opts = Rex::Parser::Arguments.new(
|
#
|
||||||
"-h" => [ false, "Help banner." ],
|
# Returns the name of the command dispatcher.
|
||||||
"-k" => [ true, "Terminate jobs by job ID and/or range." ],
|
#
|
||||||
"-K" => [ false, "Terminate all running jobs." ],
|
def name
|
||||||
"-i" => [ true, "Lists detailed information about a running job."],
|
"Job"
|
||||||
"-l" => [ false, "List all running jobs." ],
|
end
|
||||||
"-v" => [ false, "Print more detailed info. Use with -i and -l" ])
|
|
||||||
|
|
||||||
def commands
|
def cmd_rename_job_help
|
||||||
{
|
print_line "Usage: rename_job [ID] [Name]"
|
||||||
"jobs" => "Displays and manages jobs",
|
print_line
|
||||||
"rename_job" => "Rename a job",
|
print_line "Example: rename_job 0 \"meterpreter HTTPS special\""
|
||||||
"kill" => "Kill a job",
|
print_line
|
||||||
}
|
print_line "Rename a job that's currently active."
|
||||||
end
|
print_line "You may use the jobs command to see what jobs are available."
|
||||||
|
print_line
|
||||||
|
end
|
||||||
|
|
||||||
#
|
def cmd_rename_job(*args)
|
||||||
# Returns the name of the command dispatcher.
|
if args.include?('-h') || args.length != 2 || args[0] !~ /^\d+$/
|
||||||
#
|
cmd_rename_job_help
|
||||||
def name
|
|
||||||
"Job"
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_rename_job_help
|
|
||||||
print_line "Usage: rename_job [ID] [Name]"
|
|
||||||
print_line
|
|
||||||
print_line "Example: rename_job 0 \"meterpreter HTTPS special\""
|
|
||||||
print_line
|
|
||||||
print_line "Rename a job that's currently active."
|
|
||||||
print_line "You may use the jobs command to see what jobs are available."
|
|
||||||
print_line
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_rename_job(*args)
|
|
||||||
if args.include?('-h') || args.length != 2 || args[0] !~ /^\d+$/
|
|
||||||
cmd_rename_job_help
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
job_id = args[0].to_s
|
|
||||||
job_name = args[1].to_s
|
|
||||||
|
|
||||||
unless framework.jobs[job_id]
|
|
||||||
print_error("Job #{job_id} does not exist.")
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is not respecting the Protected access control, but this seems to be the only way
|
|
||||||
# to rename a job. If you know a more appropriate way, patches accepted.
|
|
||||||
framework.jobs[job_id].send(:name=, job_name)
|
|
||||||
print_status("Job #{job_id} updated")
|
|
||||||
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
|
||||||
# Tab completion for the rename_job command
|
|
||||||
#
|
|
||||||
# @param str [String] the string currently being typed before tab was hit
|
|
||||||
# @param words [Array<String>] the previously completed words on the command line. words is always
|
|
||||||
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
|
||||||
|
|
||||||
def cmd_rename_job_tabs(str, words)
|
|
||||||
return [] if words.length > 1
|
|
||||||
framework.jobs.keys
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_jobs_help
|
|
||||||
print_line "Usage: jobs [options]"
|
|
||||||
print_line
|
|
||||||
print_line "Active job manipulation and interaction."
|
|
||||||
print @@jobs_opts.usage()
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
|
||||||
# Displays and manages running jobs for the active instance of the
|
|
||||||
# framework.
|
|
||||||
#
|
|
||||||
def cmd_jobs(*args)
|
|
||||||
# Make the default behavior listing all jobs if there were no options
|
|
||||||
# or the only option is the verbose flag
|
|
||||||
args.unshift("-l") if args.length == 0 || args == ["-v"]
|
|
||||||
|
|
||||||
verbose = false
|
|
||||||
dump_list = false
|
|
||||||
dump_info = false
|
|
||||||
job_id = nil
|
|
||||||
|
|
||||||
# Parse the command options
|
|
||||||
@@jobs_opts.parse(args) do |opt, idx, val|
|
|
||||||
case opt
|
|
||||||
when "-v"
|
|
||||||
verbose = true
|
|
||||||
when "-l"
|
|
||||||
dump_list = true
|
|
||||||
# Terminate the supplied job ID(s)
|
|
||||||
when "-k"
|
|
||||||
job_list = build_range_array(val)
|
|
||||||
if job_list.blank?
|
|
||||||
print_error("Please specify valid job identifier(s)")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
print_status("Stopping the following job(s): #{job_list.join(', ')}")
|
|
||||||
job_list.map(&:to_s).each do |job|
|
job_id = args[0].to_s
|
||||||
if framework.jobs.has_key?(job)
|
job_name = args[1].to_s
|
||||||
print_status("Stopping job #{job}")
|
|
||||||
framework.jobs.stop_job(job)
|
unless framework.jobs[job_id]
|
||||||
else
|
print_error("Job #{job_id} does not exist.")
|
||||||
print_error("Invalid job identifier: #{job}")
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
# This is not respecting the Protected access control, but this seems to be the only way
|
||||||
|
# to rename a job. If you know a more appropriate way, patches accepted.
|
||||||
|
framework.jobs[job_id].send(:name=, job_name)
|
||||||
|
print_status("Job #{job_id} updated")
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tab completion for the rename_job command
|
||||||
|
#
|
||||||
|
# @param str [String] the string currently being typed before tab was hit
|
||||||
|
# @param words [Array<String>] the previously completed words on the command line. words is always
|
||||||
|
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
||||||
|
|
||||||
|
def cmd_rename_job_tabs(str, words)
|
||||||
|
return [] if words.length > 1
|
||||||
|
framework.jobs.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_jobs_help
|
||||||
|
print_line "Usage: jobs [options]"
|
||||||
|
print_line
|
||||||
|
print_line "Active job manipulation and interaction."
|
||||||
|
print @@jobs_opts.usage
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Displays and manages running jobs for the active instance of the
|
||||||
|
# framework.
|
||||||
|
#
|
||||||
|
def cmd_jobs(*args)
|
||||||
|
# Make the default behavior listing all jobs if there were no options
|
||||||
|
# or the only option is the verbose flag
|
||||||
|
args.unshift("-l") if args.length == 0 || args == ["-v"]
|
||||||
|
|
||||||
|
verbose = false
|
||||||
|
dump_list = false
|
||||||
|
dump_info = false
|
||||||
|
job_id = nil
|
||||||
|
|
||||||
|
# Parse the command options
|
||||||
|
@@jobs_opts.parse(args) do |opt, idx, val|
|
||||||
|
case opt
|
||||||
|
when "-v"
|
||||||
|
verbose = true
|
||||||
|
when "-l"
|
||||||
|
dump_list = true
|
||||||
|
# Terminate the supplied job ID(s)
|
||||||
|
when "-k"
|
||||||
|
job_list = build_range_array(val)
|
||||||
|
if job_list.blank?
|
||||||
|
print_error("Please specify valid job identifier(s)")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
print_status("Stopping the following job(s): #{job_list.join(', ')}")
|
||||||
|
job_list.map(&:to_s).each do |job|
|
||||||
|
if framework.jobs.has_key?(job)
|
||||||
|
print_status("Stopping job #{job}")
|
||||||
|
framework.jobs.stop_job(job)
|
||||||
|
else
|
||||||
|
print_error("Invalid job identifier: #{job}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
when "-K"
|
||||||
|
print_line("Stopping all jobs...")
|
||||||
|
framework.jobs.each_key do |i|
|
||||||
|
framework.jobs.stop_job(i)
|
||||||
|
end
|
||||||
|
when "-i"
|
||||||
|
# Defer printing anything until the end of option parsing
|
||||||
|
# so we can check for the verbose flag.
|
||||||
|
dump_info = true
|
||||||
|
job_id = val
|
||||||
|
when "-h"
|
||||||
|
cmd_jobs_help
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
when "-K"
|
|
||||||
print_line("Stopping all jobs...")
|
if dump_list
|
||||||
framework.jobs.each_key do |i|
|
print("\n#{Serializer::ReadableText.dump_jobs(framework, verbose)}\n")
|
||||||
framework.jobs.stop_job(i)
|
|
||||||
end
|
end
|
||||||
when "-i"
|
if dump_info
|
||||||
# Defer printing anything until the end of option parsing
|
if job_id && framework.jobs[job_id.to_s]
|
||||||
# so we can check for the verbose flag.
|
job = framework.jobs[job_id.to_s]
|
||||||
dump_info = true
|
mod = job.ctx[0]
|
||||||
job_id = val
|
|
||||||
when "-h"
|
|
||||||
cmd_jobs_help
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if dump_list
|
output = '\n'
|
||||||
print("\n#{Serializer::ReadableText.dump_jobs(framework, verbose)}\n")
|
output += "Name: #{mod.name}"
|
||||||
end
|
output += ", started at #{job.start_time}" if job.start_time
|
||||||
if dump_info
|
print_line(output)
|
||||||
if job_id && framework.jobs[job_id.to_s]
|
|
||||||
job = framework.jobs[job_id.to_s]
|
|
||||||
mod = job.ctx[0]
|
|
||||||
|
|
||||||
output = '\n'
|
show_options(mod) if mod.options.has_options?
|
||||||
output += "Name: #{mod.name}"
|
|
||||||
output += ", started at #{job.start_time}" if job.start_time
|
|
||||||
print_line(output)
|
|
||||||
|
|
||||||
show_options(mod) if mod.options.has_options?
|
if verbose
|
||||||
|
mod_opt = Serializer::ReadableText.dump_advanced_options(mod, ' ')
|
||||||
if verbose
|
if mod_opt && mod_opt.length > 0
|
||||||
mod_opt = Serializer::ReadableText.dump_advanced_options(mod,' ')
|
print_line("\nModule advanced options:\n\n#{mod_opt}\n")
|
||||||
if mod_opt && mod_opt.length > 0
|
end
|
||||||
print_line("\nModule advanced options:\n\n#{mod_opt}\n")
|
end
|
||||||
|
else
|
||||||
|
print_line("Invalid Job ID")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
print_line("Invalid Job ID")
|
#
|
||||||
|
# Tab completion for the jobs command
|
||||||
|
#
|
||||||
|
# @param str [String] the string currently being typed before tab was hit
|
||||||
|
# @param words [Array<String>] the previously completed words on the command line. words is always
|
||||||
|
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
||||||
|
|
||||||
|
def cmd_jobs_tabs(str, words)
|
||||||
|
if words.length == 1
|
||||||
|
return @@jobs_opts.fmt.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
if words.length == 2 && (@@jobs_opts.fmt[words[1]] || [false])[0]
|
||||||
|
return framework.jobs.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_kill_help
|
||||||
|
print_line "Usage: kill <job1> [job2 ...]"
|
||||||
|
print_line
|
||||||
|
print_line "Equivalent to 'jobs -k job1 -k job2 ...'"
|
||||||
|
print @@jobs_opts.usage
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_kill(*args)
|
||||||
|
cmd_jobs("-k", *args)
|
||||||
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tab completion for the kill command
|
||||||
|
#
|
||||||
|
# @param str [String] the string currently being typed before tab was hit
|
||||||
|
# @param words [Array<String>] the previously completed words on the command line. words is always
|
||||||
|
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
||||||
|
|
||||||
|
def cmd_kill_tabs(str, words)
|
||||||
|
return [] if words.length > 1
|
||||||
|
framework.jobs.keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
|
||||||
# Tab completion for the jobs command
|
|
||||||
#
|
|
||||||
# @param str [String] the string currently being typed before tab was hit
|
|
||||||
# @param words [Array<String>] the previously completed words on the command line. words is always
|
|
||||||
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
|
||||||
|
|
||||||
def cmd_jobs_tabs(str, words)
|
|
||||||
if words.length == 1
|
|
||||||
return @@jobs_opts.fmt.keys
|
|
||||||
end
|
|
||||||
|
|
||||||
if words.length == 2 and (@@jobs_opts.fmt[words[1]] || [false])[0]
|
|
||||||
return framework.jobs.keys
|
|
||||||
end
|
|
||||||
|
|
||||||
[]
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_kill_help
|
|
||||||
print_line "Usage: kill <job1> [job2 ...]"
|
|
||||||
print_line
|
|
||||||
print_line "Equivalent to 'jobs -k job1 -k job2 ...'"
|
|
||||||
print @@jobs_opts.usage()
|
|
||||||
end
|
|
||||||
|
|
||||||
def cmd_kill(*args)
|
|
||||||
cmd_jobs("-k", *args)
|
|
||||||
end
|
|
||||||
|
|
||||||
#
|
|
||||||
# Tab completion for the kill command
|
|
||||||
#
|
|
||||||
# @param str [String] the string currently being typed before tab was hit
|
|
||||||
# @param words [Array<String>] the previously completed words on the command line. words is always
|
|
||||||
# at least 1 when tab completion has reached this stage since the command itself has been completed
|
|
||||||
|
|
||||||
def cmd_kill_tabs(str, words)
|
|
||||||
return [] if words.length > 1
|
|
||||||
framework.jobs.keys
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
# -*- coding: binary -*-
|
# -*- coding: binary -*-
|
||||||
|
|
||||||
#
|
|
||||||
# Rex
|
|
||||||
#
|
|
||||||
|
|
||||||
require 'rex/ui/text/output/buffer/stdout'
|
require 'rex/ui/text/output/buffer/stdout'
|
||||||
|
|
||||||
|
|
||||||
module Msf
|
module Msf
|
||||||
module Ui
|
module Ui
|
||||||
module Console
|
module Console
|
||||||
|
|
|
@ -3,139 +3,141 @@
|
||||||
require 'rex/parser/arguments'
|
require 'rex/parser/arguments'
|
||||||
|
|
||||||
module Msf
|
module Msf
|
||||||
module Ui
|
module Ui
|
||||||
module Console
|
module Console
|
||||||
module CommandDispatcher
|
module CommandDispatcher
|
||||||
|
|
||||||
###
|
###
|
||||||
#
|
#
|
||||||
# Payload module command dispatcher.
|
# Payload module command dispatcher.
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
class Payload
|
class Payload
|
||||||
|
|
||||||
include Msf::Ui::Console::ModuleCommandDispatcher
|
include Msf::Ui::Console::ModuleCommandDispatcher
|
||||||
|
|
||||||
# Load supported formats
|
# Load supported formats
|
||||||
supported_formats = Msf::Simple::Buffer.transform_formats + Msf::Util::EXE.to_executable_fmt_formats
|
supported_formats = Msf::Simple::Buffer.transform_formats + Msf::Util::EXE.to_executable_fmt_formats
|
||||||
|
|
||||||
@@generate_opts = Rex::Parser::Arguments.new(
|
@@generate_opts = Rex::Parser::Arguments.new(
|
||||||
"-b" => [ true, "The list of characters to avoid: '\\x00\\xff'" ],
|
"-b" => [ true, "The list of characters to avoid: '\\x00\\xff'" ],
|
||||||
"-E" => [ false, "Force encoding." ],
|
"-E" => [ false, "Force encoding." ],
|
||||||
"-e" => [ true, "The name of the encoder module to use." ],
|
"-e" => [ true, "The name of the encoder module to use." ],
|
||||||
"-h" => [ false, "Help banner." ],
|
"-h" => [ false, "Help banner." ],
|
||||||
"-o" => [ true, "A comma separated list of options in VAR=VAL format." ],
|
"-o" => [ true, "A comma separated list of options in VAR=VAL format." ],
|
||||||
"-s" => [ true, "NOP sled length." ],
|
"-s" => [ true, "NOP sled length." ],
|
||||||
"-f" => [ true, "The output file name (otherwise stdout)" ],
|
"-f" => [ true, "The output file name (otherwise stdout)" ],
|
||||||
"-t" => [ true, "The output format: #{supported_formats.join(',')}" ],
|
"-t" => [ true, "The output format: #{supported_formats.join(',')}" ],
|
||||||
"-p" => [ true, "The Platform for output." ],
|
"-p" => [ true, "The Platform for output." ],
|
||||||
"-k" => [ false, "Keep the template executable functional" ],
|
"-k" => [ false, "Keep the template executable functional" ],
|
||||||
"-x" => [ true, "The executable template to use" ],
|
"-x" => [ true, "The executable template to use" ],
|
||||||
"-i" => [ true, "the number of encoding iterations." ])
|
"-i" => [ true, "the number of encoding iterations." ])
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns the hash of commands specific to payload modules.
|
# Returns the hash of commands specific to payload modules.
|
||||||
#
|
#
|
||||||
def commands
|
def commands
|
||||||
super.update({
|
super.update({
|
||||||
"generate" => "Generates a payload",
|
"generate" => "Generates a payload",
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns the command dispatcher name.
|
# Returns the command dispatcher name.
|
||||||
#
|
#
|
||||||
def name
|
def name
|
||||||
return "Payload"
|
return "Payload"
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Generates a payload.
|
# Generates a payload.
|
||||||
#
|
#
|
||||||
def cmd_generate(*args)
|
def cmd_generate(*args)
|
||||||
|
|
||||||
# Parse the arguments
|
# Parse the arguments
|
||||||
encoder_name = nil
|
encoder_name = nil
|
||||||
sled_size = nil
|
sled_size = nil
|
||||||
option_str = nil
|
option_str = nil
|
||||||
badchars = nil
|
badchars = nil
|
||||||
type = "ruby"
|
type = "ruby"
|
||||||
ofile = nil
|
ofile = nil
|
||||||
iter = 1
|
iter = 1
|
||||||
force = nil
|
force = nil
|
||||||
template = nil
|
template = nil
|
||||||
plat = nil
|
plat = nil
|
||||||
keep = false
|
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
|
||||||
|
|
||||||
@@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
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
}
|
|
||||||
if (encoder_name.nil? and mod.datastore['ENCODER'])
|
|
||||||
encoder_name = mod.datastore['ENCODER']
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end end end end
|
|
||||||
|
|
Loading…
Reference in New Issue