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/tools/exploit/nasm_shell.rb
Views: 11768
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# This tool provides an easy way to see what opcodes are associated with9# certain x86 instructions by making use of nasm if it is installed and10# reachable through the PATH environment variable.11#12begin13msfbase = __FILE__14while File.symlink?(msfbase)15msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))16end1718$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))19$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']2021require 'msfenv'22require 'rex'23require 'readline'2425# Check to make sure nasm is installed and reachable through the user's PATH.26begin27Rex::Assembly::Nasm.check28rescue RuntimeError29puts "#{$!}"30exit31end3233bits = ARGV.length > 0 ? ARGV[0].to_i : 3234if ! [16, 32, 64].include?(bits) then35puts "#{bits} bits not supported"36exit 137end3839# Start a pseudo shell and dispatch lines to be assembled and then40# disassembled.41history_file = File.join(Msf::Config.config_directory, 'nasm_history')42shell = Rex::Ui::Text::PseudoShell.new("%bldnasm%clr", '>', history_file)43shell.init_ui(Rex::Ui::Text::Input::Stdio.new, Rex::Ui::Text::Output::Stdio.new)44shell.history_manager = Rex::Ui::Text::Shell::HistoryManager.new4546shell.run { |line|47line.gsub!(/(\r|\n)/, '')48line.gsub!(/\\n/, "\n")4950break if (line =~ /^(exit|quit)/i)5152begin53puts(Rex::Assembly::Nasm.disassemble(54Rex::Assembly::Nasm.assemble(line, bits), bits))55rescue RuntimeError56puts "Error: #{$!}"57end58}59rescue SignalException => e60puts("Aborted! #{e}")61end626364