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

59 lines
1.4 KiB
Ruby
Raw Normal View History

2005-12-17 06:46:23 +00:00
#!/usr/bin/env ruby
2018-04-01 23:26:42 -05: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.
#
2005-12-08 15:37:10 +00:00
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')))
2012-04-15 23:35:38 -05:00
require 'msfenv'
$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
2005-12-08 15:37:10 +00:00
require 'rex'
require 'rex/ui'
# 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.
2009-11-11 04:43:52 +00:00
shell = Rex::Ui::Text::PseudoShell.new("%bldnasm%clr")
shell.init_ui(Rex::Ui::Text::Input::Stdio.new, Rex::Ui::Text::Output::Stdio.new)
2005-12-08 15:37:10 +00:00
shell.run { |line|
2013-09-30 13:47:53 -05:00
line.gsub!(/(\r|\n)/, '')
2018-04-01 23:26:42 -05:00
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
}