Files
metasploit-gs/tools/exploit/nasm_shell.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.6 KiB
Ruby
Raw Normal View History

2005-12-17 06:46:23 +00:00
#!/usr/bin/env ruby
2018-03-20 11:33:34 +00:00
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
2010-05-03 17:13:09 +00:00
#
# This tool provides an easy way to see what opcodes are associated with
# certain x86 instructions by making use of nasm if it is installed and
# reachable through the PATH environment variable.
#
2021-03-22 15:47:41 +05:30
begin
msfbase = __FILE__
while File.symlink?(msfbase)
2013-09-30 13:47:53 -05:00
msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
2015-10-06 10:30:52 -05:00
$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
2005-12-08 15:37:10 +00:00
2020-03-25 02:21:08 +05:30
require 'msfenv'
2005-12-08 15:37:10 +00:00
require 'rex'
2024-10-02 13:15:12 +01:00
require 'readline'
2005-12-08 15:37:10 +00:00
# Check to make sure nasm is installed and reachable through the user's PATH.
begin
2013-09-30 13:47:53 -05:00
Rex::Assembly::Nasm.check
rescue RuntimeError
2013-09-30 13:47:53 -05:00
puts "#{$!}"
exit
end
2011-11-10 20:01:50 -06:00
bits = ARGV.length > 0 ? ARGV[0].to_i : 32
if ! [16, 32, 64].include?(bits) then
puts "#{bits} bits not supported"
exit 1
end
# Start a pseudo shell and dispatch lines to be assembled and then
# disassembled.
history_file = File.join(Msf::Config.config_directory, 'nasm_history')
shell = Rex::Ui::Text::PseudoShell.new("%bldnasm%clr", '>', history_file)
shell.init_ui(Rex::Ui::Text::Input::Stdio.new, Rex::Ui::Text::Output::Stdio.new)
shell.history_manager = Rex::Ui::Text::Shell::HistoryManager.new
2005-12-08 15:37:10 +00:00
shell.run { |line|
2013-09-30 13:47:53 -05:00
line.gsub!(/(\r|\n)/, '')
line.gsub!("\\n", "\n")
2005-12-08 15:37:10 +00:00
2013-09-30 13:47:53 -05:00
break if (line =~ /^(exit|quit)/i)
2005-12-08 15:37:10 +00:00
2013-09-30 13:47:53 -05:00
begin
puts(Rex::Assembly::Nasm.disassemble(
Rex::Assembly::Nasm.assemble(line, bits), bits))
rescue RuntimeError
puts "Error: #{$!}"
end
2009-11-11 04:43:52 +00:00
}
2021-03-22 15:47:41 +05:30
rescue SignalException => e
puts("Aborted! #{e}")
end