Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/base/sessions/ssh_command_shell_reverse.rb
Views: 11784
# -*- coding: binary -*-12module Msf::Sessions3###4#5# This class provides basic interaction with a ChannelFD6# abstraction provided by the Rex::Proto::Ssh wrapper7# around HrrRbSsh.8#9# Date: June 22, 201910# Author: RageLtMan11#12###13class SshCommandShellReverse < Msf::Sessions::CommandShell1415#16# This interface supports basic interaction.17#18include Msf::Session::Basic1920#21# This interface supports interacting with a single command shell.22#23include Msf::Session::Provider::SingleCommandShell2425##26#27# Returns the session description.28#29def desc30'SSH command shell'31end3233def shell_command(cmd, timeout = 5)34# Send the command to the session's stdin.35shell_write(cmd + "\n")3637etime = ::Time.now.to_f + timeout38buff = ""3940# Keep reading data until no more data is available or the timeout is41# reached.42while ::Time.now.to_f < etime && ::IO.select([rstream.fd_rd], nil, nil, timeout)43res = shell_read(-1, 0.01)44buff << res if res45timeout = etime - ::Time.now.to_f46end4748buff49end5051protected5253def _interact_stream54fdr = [rstream.fd_rd, user_input.fd]55fdw = [rstream.fd_wr, user_input.fd]56while interacting57sd = Rex::ThreadSafe.select(fdr, nil, fdw, 0.5)58next unless sd5960if sd[0].include? rstream.fd_rd61user_output.print(shell_read)62end63if sd[0].include? user_input.fd64run_single((user_input.gets || '').chomp("\n"))65end66Thread.pass67end68end6970end71end727374