CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/lib/msf/base/sessions/powershell.rb
Views: 1904
# -*- coding: binary -*-12class Msf::Sessions::PowerShell < Msf::Sessions::CommandShell3module Mixin4#5# Takes over the shell_command of the parent6#7def shell_command(cmd, timeout = 1800)8# insert random marker9strm = Rex::Text.rand_text_alpha(15)10endm = Rex::Text.rand_text_alpha(15)1112# Send the shell channel's stdin.13shell_write(";'#{strm}'\n" + cmd + "\n'#{endm}';\n")1415etime = ::Time.now.to_f + timeout1617buff = ''18# Keep reading data until the marker has been received or the 30 minute timeout has occurred19while (::Time.now.to_f < etime)20res = shell_read(-1, timeout)21break unless res2223timeout = etime - ::Time.now.to_f2425buff << res26next unless buff.include?(endm)2728# if you see the end marker, read the buffer from the start marker to the end and then display back to screen29buff = buff.split(/#{strm}\r\n/)[-1]30buff = buff.split(endm)[0]31buff.gsub!(/(?<=\r\n)PS [^>]*>/, '')32return buff33end34buff35end36end3738include Mixin3940#41# Execute any specified auto-run scripts for this session42#43def process_autoruns(datastore)44# Read the username and hostname from the initial banner45initial_output = shell_read(-1, 2)46if initial_output =~ /running as user ([^\s]+) on ([^\s]+)/47username = Regexp.last_match(1)48hostname = Regexp.last_match(2)49self.info = "#{username} @ #{hostname}"50elsif initial_output51self.info = initial_output.gsub(/[\r\n]/, ' ')52end5354# Call our parent class's autoruns processing method55super56end5758#59# Returns the type of session.60#61def self.type62'powershell'63end6465def self.can_cleanup_files66true67end6869#70# Returns the session platform.71#72def platform73'windows'74end7576#77# Returns the session description.78#79def desc80'Powershell session'81end8283end848586