add the "makerc" command for quick resource script generation, fixes #738

git-svn-id: file:///home/svn/framework3/trunk@10119 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Joshua Drake 2010-08-23 21:19:01 +00:00
parent b6577681c6
commit 49beb83081
3 changed files with 46 additions and 7 deletions

View File

@ -91,6 +91,7 @@ class Core
"loadpath" => "Searches for and loads modules from a path",
"quit" => "Exit the console",
"resource" => "Run the commands stored in a file",
"makerc" => "Save commands entered since start to a file",
"route" => "Route traffic through a session",
"save" => "Saves the active datastores",
"search" => "Searches module names and descriptions",
@ -160,6 +161,18 @@ class Core
end
end
#
# Saves commands executed since the ui started to the specified msfrc file
#
def cmd_makerc(*args)
if args.empty?
print(
"Usage: makerc <output rc file>\n\n" +
"Save the commands executed since startup to the specified file.\n")
return false
end
driver.save_recent_history(args[0])
end
#
# Pop the current dispatcher stack context, assuming it isn't pointed at
@ -1509,7 +1522,7 @@ class Core
opts << el
}
print_status("Additional module-specific parameters are: #{opts}")
when 'all'
show_encoders
show_nops
@ -1559,7 +1572,7 @@ class Core
else
print_error("No auxiliary module selected.")
end
else
print_error("Invalid parameter \"#{type}\", use \"show -h\" for more information")
end

View File

@ -263,6 +263,29 @@ class Driver < Msf::Ui::Driver
end
end
#
# Saves the recent history to the specified file
#
def save_recent_history(path)
num = Readline::HISTORY.length - hist_last_saved - 1
tmprc = ""
num.times { |x|
tmprc << Readline::HISTORY[hist_last_saved + x] + "\n"
}
if tmprc.length > 0
print_status("Saving last #{num} commands to #{path} ...")
save_resource(tmprc, path)
else
print_error("No commands to save!")
end
# Always update this, even if we didn't save anything. We do this
# so that we don't end up saving the "makerc" command itself.
self.hist_last_saved = Readline::HISTORY.length
end
#
# Creates the resource script file for the console.
#

View File

@ -47,15 +47,17 @@ module Shell
self.prompt_char = prompt_char
self.histfile = histfile
self.hist_last_saved = 0
end
def init_tab_complete
if (self.input and self.input.supports_readline)
self.input = Input::Readline.new(lambda { |str| tab_complete(str) })
if Readline::HISTORY.length == 0 and histfile and File.exists?(histfile)
File.readlines(histfile).each { |e|
Readline::HISTORY << e.chomp
}
File.readlines(histfile).each { |e|
Readline::HISTORY << e.chomp
}
self.hist_last_saved = Readline::HISTORY.length
end
self.input.output = self.output
update_prompt(input.prompt)
@ -142,9 +144,9 @@ module Shell
# don't bother saving lines that couldn't be found as a
# command, create the file if it doesn't exist
if ret and self.histfile
File.open(self.histfile, "a+") { |f|
File.open(self.histfile, "a+") { |f|
f.puts(line)
}
}
end
self.stop_count = 0
end
@ -299,6 +301,7 @@ protected
attr_accessor :prompt # :nodoc:
attr_accessor :prompt_char, :tab_complete_proc # :nodoc:
attr_accessor :histfile # :nodoc:
attr_accessor :hist_last_saved # the number of history lines when last saved/loaded
attr_accessor :log_source, :stop_count # :nodoc:
end