1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-15 20:29:03 +00:00

Update nfs-{showmount,statfs} to new rpc-grind

This commit is contained in:
dmiller
2012-08-18 04:07:11 +00:00
parent 592f31fa0f
commit a329909fdf
2 changed files with 58 additions and 13 deletions

View File

@@ -30,18 +30,35 @@ Shows NFS exports, like the <code>showmount -e</code> command.
author = "Patrik Karlsson" author = "Patrik Karlsson"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html" license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"discovery", "safe"} categories = {"discovery", "safe"}
dependencies = {"rpc-grind"}
portrule = shortport.port_or_service(111, {"rpcbind", "mountd"}, {"tcp", "udp"} ) portrule = shortport.port_or_service(111, {"rpcbind", "mountd"}, {"tcp", "udp"} )
local function get_exports(host, port) local function get_exports(host, port)
local mnt = rpc.Mount:new() local mnt = rpc.Mount:new()
local mnt_comm = rpc.Comm:new('mountd', port.version.rpc_highver) local mountver
if host.registry.nfs then
mountver = host.registry.nfs.mountver
else
host.registry.nfs = {}
end
if mountver == nil then
local low, high = string.match(port.version.version, "(%d)-(%d)")
if high == nil then
mountver = tonumber(port.version.version)
else
mountver = tonumber(high)
end
end
local mnt_comm = rpc.Comm:new('mountd', mountver)
local status, result = mnt_comm:Connect(host, port) local status, result = mnt_comm:Connect(host, port)
if ( not(status) ) then if ( not(status) ) then
stdnse.print_debug(4, "get_exports: %s", result) stdnse.print_debug(4, "get_exports: %s", result)
return false, result return false, result
end end
host.registry.nfs.mountver = mountver
host.registry.nfs.mountport = port
local status, mounts = mnt:Export(mnt_comm) local status, mounts = mnt:Export(mnt_comm)
mnt_comm:Disconnect() mnt_comm:Disconnect()
if ( not(status) ) then if ( not(status) ) then

View File

@@ -37,13 +37,19 @@ the version used is NFSv3.
author = "Patrik Karlsson, Djalal Harouni" author = "Patrik Karlsson, Djalal Harouni"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html" license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"discovery", "safe"} categories = {"discovery", "safe"}
dependencies = {"rpc-grind"}
portrule = shortport.port_or_service(111, "rpcbind", {"tcp", "udp"} ) portrule = shortport.port_or_service(111, "rpcbind", {"tcp", "udp"} )
local mountport = nil
local nfsport = nil
hostrule = function(host) hostrule = function(host)
local mountport, nfsport
if host.registry.nfs then
mountport = host.registry.nfs.mountport
nfsport = host.registry.nfs.nfsport
else
host.registry.nfs = {}
end
for _,proto in ipairs({"tcp","udp"}) do for _,proto in ipairs({"tcp","udp"}) do
local port = nmap.get_ports(host, nil, proto, "open") local port = nmap.get_ports(host, nil, proto, "open")
while port do while port do
@@ -60,11 +66,33 @@ hostrule = function(host)
if mountport and nfsport then break end if mountport and nfsport then break end
end end
if nfsport == nil then return false end if nfsport == nil then return false end
if nfsport.version.rpc_highver == 4 and nfsport.version.rpc_lowver <= 3 then if host.registry.nfs.nfsver == nil then
nfsport.version.rpc_goodver = 3 local low, high = string.match(nfsport.version.version, "(%d)-(%d)")
else if high == nil then
nfsport.version.rpc_goodver = nfsport.version.rpc_highver high = tonumber(nfsport.version.version)
if high == 4 then
return false --Can't support version 4
else
host.registry.nfs.nfsver = high
end
else
if high == "4" then
host.registry.nfs.nfsver = 3
else
host.registry.nfs.nfsver = tonumber(low)
end
end
end end
if host.registry.nfs.mountver == nil then
local low, high = string.match(mountport.version.version, "(%d)-(%d)")
if high == nil then
host.registry.nfs.mountver = tonumber(mountport.version.version)
else
host.registry.nfs.mountver = tonumber(high)
end
end
host.registry.nfs.mountport = mountport
host.registry.nfs.nfsport = nfsport
return (mountport and nfsport) return (mountport and nfsport)
end end
@@ -239,8 +267,8 @@ hostaction = function(host)
ShowMounts = function(ahost) ShowMounts = function(ahost)
local mnt_comm, status, result, mounts local mnt_comm, status, result, mounts
local mnt = rpc.Mount:new() local mnt = rpc.Mount:new()
mnt_comm = rpc.Comm:new('mountd', mountport.version.rpc_highver) mnt_comm = rpc.Comm:new('mountd', host.registry.nfs.mountver)
status, result = mnt_comm:Connect(ahost, mountport) status, result = mnt_comm:Connect(ahost, host.registry.nfs.mountport)
if ( not(status) ) then if ( not(status) ) then
stdnse.print_debug(4, "ShowMounts: %s", result) stdnse.print_debug(4, "ShowMounts: %s", result)
return false, result return false, result
@@ -258,9 +286,9 @@ hostaction = function(host)
local mountd, mnt_comm local mountd, mnt_comm
local mnt = rpc.Mount:new() local mnt = rpc.Mount:new()
mnt_comm = rpc.Comm:new("mountd", mountport.version.rpc_highver) mnt_comm = rpc.Comm:new("mountd", host.registry.nfs.mountver)
status, err = mnt_comm:Connect(host, mountport) status, err = mnt_comm:Connect(host, host.registry.nfs.mountport)
if not status then if not status then
stdnse.print_debug(4, "MountPath: %s", err) stdnse.print_debug(4, "MountPath: %s", err)
return nil, err return nil, err
@@ -279,8 +307,8 @@ hostaction = function(host)
NfsOpen = function(ahost) NfsOpen = function(ahost)
local nfs_comm, status, err local nfs_comm, status, err
nfs_comm = rpc.Comm:new('nfs', nfsport.version.rpc_goodver) nfs_comm = rpc.Comm:new('nfs', host.registry.nfs.nfsver)
status, err = nfs_comm:Connect(host, nfsport) status, err = nfs_comm:Connect(host, host.registry.nfs.nfsport)
if not status then if not status then
stdnse.print_debug(4, "NfsOpen: %s", err) stdnse.print_debug(4, "NfsOpen: %s", err)
return nil, err return nil, err