don't create a new socket every time the command prompt is displayed

GSoC/Meterpreter_Web_Console
Brent Cook 2019-02-13 04:30:57 -06:00
parent 395346a720
commit 8083853cb9
1 changed files with 26 additions and 13 deletions

View File

@ -381,33 +381,46 @@ protected
#
def format_prompt(str)
if framework
if str.include?("%T")
if str.include?('%T')
t = Time.now
# This %T is the strftime shorthand for %H:%M:%S
format = framework.datastore['PromptTimeFormat'] || "%T"
format = framework.datastore['PromptTimeFormat'] || '%T'
t = t.strftime(format)
# This %T is the marker in the prompt where we need to place the time
str.gsub!(/%T/, t.to_s)
str.gsub!('%T', t.to_s)
end
if str.include?("%H")
if str.include?('%H')
hostname = ENV['HOSTNAME'] || `hostname`.split('.')[0] ||
ENV['COMPUTERNAME'] || 'unknown'
str.gsub!(/%H/, hostname.chomp)
str.gsub!('%H', hostname.chomp)
end
if str.include?("%U")
if str.include?('%U')
user = ENV['USER'] || `whoami` || ENV['USERNAME'] || 'unknown'
str.gsub!(/%U/, user.chomp)
str.gsub!('%U', user.chomp)
end
str.gsub!(/%S/, framework.sessions.length.to_s)
str.gsub!(/%J/, framework.jobs.length.to_s)
str.gsub!(/%L/, Rex::Socket.source_address("50.50.50.50"))
str.gsub!(/%D/, ::Dir.getwd)
if framework.db.active
str.gsub!(/%W/, framework.db.workspace.name)
if str.include?('%S')
str.gsub!('%S', framework.sessions.length.to_s)
end
if str.include?('%J')
str.gsub!('%J', framework.jobs.length.to_s)
end
if str.include?('%L')
ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
str.gsub!('%L', ip.ip_address)
end
if str.include?('%D')
str.gsub!('%D', ::Dir.getwd)
end
if str.include?('%W') && framework.db.active
str.gsub!('%W', framework.db.workspace.name)
end
end