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/riscv64le/simple.rb
Views: 11777
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45# This class implements a simple NOP generator for RISC-V 64-bit (Little Endian)6class MetasploitModule < Msf::Nop78def initialize9super(10'Name' => 'Simple',11'Alias' => 'riscv64le_simple',12'Description' => 'Simple NOP generator',13'License' => MSF_LICENSE,14'Author' => ['bcoles'],15'Arch' => ARCH_RISCV64LE)16register_advanced_options([17OptBool.new('RandomNops', [false, 'Generate a random NOP sled', true]),18])19end2021def generate_sled(length, opts)22badchars = opts['BadChars'] || ''23random = opts['Random'] || datastore['RandomNops']2425nops = [26# Safe NULL-free nops using temporary registers (t0 - t6)27[0x400282b3].pack('V'), # sub t0, t0, 028[0x40030333].pack('V'), # sub t1, t1, 029[0x400383b3].pack('V'), # sub t2, t2, 030[0x400e0e33].pack('V'), # sub t3, t3, 031[0x400e8eb3].pack('V'), # sub t4, t4, 032[0x400f0f33].pack('V'), # sub t5, t5, 033[0x400f8fb3].pack('V'), # sub t6, t6, 03435# Safe NULL-free nops using zero register (x0)36[0x01102013].pack('V'), # slti x0, x0, 0x1137[0x7ff02013].pack('V'), # slti x0, x0, 0x7ff3839[0x01103013].pack('V'), # sltiu x0, x0, 0x1140[0x7ff03013].pack('V'), # sltiu x0, x0, 0x7ff4142[0x01105013].pack('V'), # srli x0, x0, 0x1143[0x03f05013].pack('V'), # srli x0, x0, 0x3f4445[0x01101013].pack('V'), # slli x0, x0, 0x1146[0x03f01013].pack('V'), # slli x0, x0, 0x3f4748[0x41105013].pack('V'), # srai x0, x0, 0x1149[0x43f05013].pack('V'), # srai x0, x0, 0x3f5051[0x01106013].pack('V'), # ori x0, x0, 0x1152[0x7ff06013].pack('V'), # ori x0, x0, 0x7ff5354[0x01104013].pack('V'), # xori x0, x0, 0x1155[0x7ff04013].pack('V'), # xori x0, x0, 0x7ff5657[0x01107013].pack('V'), # andi x0, x0, 0x1158[0x7ff07013].pack('V'), # andi x0, x0, 0x7ff5960[0x10101037].pack('V'), # lui x0, 0x1010161[0xfffff037].pack('V'), # lui x0, 0xfffff6263# Safe NULL-free numeric nops using zero register (x0)64# lui x0, 0x????303765"\x37\x30" + Rex::Text.rand_text_numeric(2, badchars),6667# Safe NULL-free alphanumeric nops using zero register (x0)68# lui x0, 0x????[357]03769"\x37\x30" + Rex::Text.rand_text_alphanumeric(2, badchars),70"\x37\x50" + Rex::Text.rand_text_alphanumeric(2, badchars),71"\x37\x70" + Rex::Text.rand_text_alphanumeric(2, badchars),7273# Safe NULL-free english nops using zero register (x0)74# lui x0, 0x????[34567]03775"\x37\x30" + Rex::Text.rand_text_english(2, badchars),76"\x37\x40" + Rex::Text.rand_text_english(2, badchars),77"\x37\x50" + Rex::Text.rand_text_english(2, badchars),78"\x37\x60" + Rex::Text.rand_text_english(2, badchars),79"\x37\x70" + Rex::Text.rand_text_english(2, badchars),80]8182# Remove nops containing BadChars83nops.delete_if do |nop|84nop.bytes.any? { |byte| badchars.force_encoding('BINARY').include?(byte.chr) }85end8687# Give up if no safe nops are available88return if nops.empty?8990# Use random instructions for all NOPs91if random92sled = ''93(length / 4).times do94sled << nops.sample95end96return sled97end9899# Use a single instruction for all NOPs100return (nops.sample * (length / 4))101end102end103104105