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/nops/x86/single_byte.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45###6#7# This class implements single-byte NOP generation for X86. It takes from8# ADMmutate and from spoonfu.9#10###11class MetasploitModule < Msf::Nop1213SINGLE_BYTE_SLED =14{15# opcode affected registers16# ------ ------------------17"\x90" => nil , # nop18"\x97" => [ 'eax', 'edi' ], # xchg eax,edi19"\x96" => [ 'eax', 'esi' ], # xchg eax,esi20"\x95" => [ 'eax', 'ebp' ], # xchg eax,ebp21"\x93" => [ 'eax', 'ebx' ], # xchg eax,ebx22"\x92" => [ 'eax', 'edx' ], # xchg eax,edx23"\x91" => [ 'eax', 'ecx' ], # xchg eax,ecx24"\x99" => [ 'edx' ], # cdq25"\x4d" => [ 'ebp' ], # dec ebp26"\x48" => [ 'eax' ], # dec eax27"\x47" => [ 'edi' ], # inc edi28"\x4f" => [ 'edi' ], # dec edi29"\x40" => [ 'eax' ], # inc eax30"\x41" => [ 'ecx' ], # inc ecx31"\x37" => [ 'eax' ], # aaa32"\x3f" => [ 'eax' ], # aas33"\x27" => [ 'eax' ], # daa34"\x2f" => [ 'eax' ], # das35"\x46" => [ 'esi' ], # inc esi36"\x4e" => [ 'esi' ], # dec esi37"\xfc" => nil , # cld38"\xfd" => nil , # std39"\xf8" => nil , # clc40"\xf9" => nil , # stc41"\xf5" => nil , # cmc42"\x98" => [ 'eax' ], # cwde43"\x9f" => [ 'eax' ], # lahf44"\x4a" => [ 'edx' ], # dec edx45"\x44" => [ 'esp', 'align' ], # inc esp46"\x42" => [ 'edx' ], # inc edx47"\x43" => [ 'ebx' ], # inc ebx48"\x49" => [ 'ecx' ], # dec ecx49"\x4b" => [ 'ebx' ], # dec ebx50"\x45" => [ 'ebp' ], # inc ebp51"\x4c" => [ 'esp', 'align' ], # dec esp52"\x9b" => nil , # wait53"\x60" => [ 'esp' ], # pusha54"\x0e" => [ 'esp', 'align' ], # push cs55"\x1e" => [ 'esp', 'align' ], # push ds56"\x50" => [ 'esp' ], # push eax57"\x55" => [ 'esp' ], # push ebp58"\x53" => [ 'esp' ], # push ebx59"\x51" => [ 'esp' ], # push ecx60"\x57" => [ 'esp' ], # push edi61"\x52" => [ 'esp' ], # push edx62"\x06" => [ 'esp', 'align' ], # push es63"\x56" => [ 'esp' ], # push esi64"\x54" => [ 'esp' ], # push esp65"\x16" => [ 'esp', 'align' ], # push ss66"\x58" => [ 'esp', 'eax' ], # pop eax67"\x5d" => [ 'esp', 'ebp' ], # pop ebp68"\x5b" => [ 'esp', 'ebx' ], # pop ebx69"\x59" => [ 'esp', 'ecx' ], # pop ecx70"\x5f" => [ 'esp', 'edi' ], # pop edi71"\x5a" => [ 'esp', 'edx' ], # pop edx72"\x5e" => [ 'esp', 'esi' ], # pop esi73"\xd6" => [ 'eax' ], # salc74}7576def initialize77super(78'Name' => 'Single Byte',79'Alias' => 'ia32_singlebyte',80'Description' => 'Single-byte NOP generator',81'Author' => 'spoonm',82'License' => MSF_LICENSE,83'Arch' => ARCH_X86)8485register_advanced_options(86[87OptBool.new('RandomNops', [ false, "Generate a random NOP sled", true ])88])89end9091# Generate a single-byte NOP sled for X8692def generate_sled(length, opts = {})93sled_hash = SINGLE_BYTE_SLED94sled_max_idx = sled_hash.length95sled_cur_idx = 096out_sled = ''9798random = opts['Random']99badchars = opts['BadChars'] || ''100badregs = opts['SaveRegisters'] || []101102# Did someone specify random NOPs in the environment?103if (!random and datastore['RandomNops'])104random = datastore['RandomNops']105end106107# Generate the whole sled...1081.upto(length) { |current|109110cur_char = nil111threshold = 0112113# Keep snagging characters until we find one that satisfies both the114# bad character and bad register requirements115begin116sled_cur_idx = rand(sled_max_idx) if (random == true)117cur_char = sled_hash.keys[sled_cur_idx]118sled_cur_idx += 1 if (random == false)119sled_cur_idx = 0 if (sled_cur_idx >= sled_max_idx)120121# Make sure that we haven't gone over the sled repeat threshold122if ((threshold += 1) > self.nop_repeat_threshold)123return nil124end125126end while ((badchars.include?(cur_char)) or127((sled_hash[cur_char]) and128((sled_hash[cur_char] & badregs).length > 0)))129130# Add the character to the sled now that it's passed our checks131out_sled += cur_char132}133134# If the sled fails to entirely generate itself, then that's bogus,135# man...136if (out_sled.length != length)137return nil138end139140return out_sled141end142end143144145