Path: blob/master/modules/encoders/cmd/powershell_base64.rb
19720 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Encoder6Rank = ExcellentRanking78include Msf::Post::Windows910def initialize11super(12'Name' => 'Powershell Base64 Command Encoder',13'Description' => %q{14This encodes the command as a base64 encoded command for powershell.15},16'Author' => 'Ben Campbell',17'Arch' => ARCH_CMD,18'Platform' => 'win')19end2021#22# Encodes the payload23#24def encode_block(state, buf)25# Skip encoding for empty badchars26if state.badchars.empty?27return buf28end2930if (state.badchars.include? '-') || (state.badchars.include? ' ')31return buf32end3334cmd = encode_buf(buf)3536if state.badchars.include? '='37while cmd.include? '='38buf << ' '39cmd = encode_buf(buf)40end41end4243cmd44end4546def encode_buf(buf)47base64 = Rex::Text.encode_base64(Rex::Text.to_unicode("cmd.exe /c '#{Msf::Post::Windows.escape_powershell_literal(buf)}'"))48"powershell -w hidden -nop -e #{base64}"49end50end515253