mirror of
https://github.com/nmap/nmap.git
synced 2026-01-02 04:49:02 +00:00
Update afp-ls, nfs-ls, smb-ls to use ls.lua. See #106
This commit is contained in:
@@ -2,8 +2,7 @@ local afp = require "afp"
|
||||
local nmap = require "nmap"
|
||||
local shortport = require "shortport"
|
||||
local stdnse = require "stdnse"
|
||||
local tab = require "tab"
|
||||
local table = require "table"
|
||||
local ls = require "ls"
|
||||
|
||||
description = [[
|
||||
Attempts to get useful information about files from AFP volumes.
|
||||
@@ -12,45 +11,88 @@ The output is intended to resemble the output of <code>ls</code>.
|
||||
|
||||
---
|
||||
--
|
||||
--@output
|
||||
-- @usage
|
||||
-- nmap -sS -sV -p 548 --script=afp-ls target
|
||||
--
|
||||
-- @output
|
||||
-- PORT STATE SERVICE
|
||||
-- 548/tcp open afp syn-ack
|
||||
-- | afp-ls:
|
||||
-- | Macintosh HD
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw-r--r-- 501 80 15364 2010-06-13 17:52 .DS_Store
|
||||
-- | ---------- 0 80 0 2009-10-05 07:42 .file
|
||||
-- | drwx------ 501 20 0 2009-11-04 17:28 .fseventsd
|
||||
-- | -rw------- 0 0 393216 2010-06-14 01:49 .hotfiles.btree
|
||||
-- | drwx------ 0 80 0 2009-11-04 18:19 .Spotlight-V100
|
||||
-- | d-wx-wx-wx 0 80 0 2009-11-04 18:25 .Trashes
|
||||
-- | drwxr-xr-x 0 0 0 2009-05-18 21:29 .vol
|
||||
-- | drwxrwxr-x 0 80 0 2009-04-28 00:06 Applications
|
||||
-- | drwxr-xr-x 0 0 0 2009-05-18 21:43 bin
|
||||
-- | drwxr-xr-x 501 80 0 2010-08-10 22:55 bundles
|
||||
-- | Patrik Karlsson's Public Folder
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw------- 501 20 6148 2010-12-27 23:45 .DS_Store
|
||||
-- | -rw-r--r-- 501 20 0 2007-07-24 21:17 .localized
|
||||
-- | drwx-wx-wx 501 20 0 2009-06-19 04:01 Drop Box
|
||||
-- | patrik
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw------- 501 20 11281 2010-06-14 22:51 .bash_history
|
||||
-- | -rw-r--r-- 501 20 33 2011-01-19 20:11 .bashrc
|
||||
-- | -rw------- 501 20 3 2007-07-24 21:17 .CFUserTextEncoding
|
||||
-- | drwx------ 501 20 0 2010-09-12 14:52 .config
|
||||
-- | drwx------ 501 20 0 2010-09-12 12:29 .cups
|
||||
-- | -rw-r--r-- 501 20 15364 2010-06-13 18:34 .DS_Store
|
||||
-- | drwxr-xr-x 501 20 0 2010-09-12 14:13 .fontconfig
|
||||
-- | -rw------- 501 20 102 2010-06-14 01:46 .lesshst
|
||||
-- | -rw-r--r-- 501 20 241 2010-06-14 01:45 .profile
|
||||
-- | -rw------- 501 20 218 2010-09-12 16:35 .recently-used.xbel
|
||||
-- | Information retrieved as patrik
|
||||
-- | Volume Macintosh HD
|
||||
-- | maxfiles limit reached (10)
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw-r--r-- 501 80 15364 2010-06-13 17:52 .DS_Store
|
||||
-- | ---------- 0 80 0 2009-10-05 07:42 .file
|
||||
-- | drwx------ 501 20 0 2009-11-04 17:28 .fseventsd
|
||||
-- | -rw------- 0 0 393216 2010-06-14 01:49 .hotfiles.btree
|
||||
-- | drwx------ 0 80 0 2009-11-04 18:19 .Spotlight-V100
|
||||
-- | d-wx-wx-wx 0 80 0 2009-11-04 18:25 .Trashes
|
||||
-- | drwxr-xr-x 0 0 0 2009-05-18 21:29 .vol
|
||||
-- | drwxrwxr-x 0 80 0 2009-04-28 00:06 Applications
|
||||
-- | drwxr-xr-x 0 0 0 2009-05-18 21:43 bin
|
||||
-- | drwxr-xr-x 501 80 0 2010-08-10 22:55 bundles
|
||||
-- |
|
||||
-- | Information retrieved as: patrik
|
||||
-- |_ Output restricted to 10 entries per volume. (See afp-ls.maxfiles)
|
||||
--
|
||||
-- @args afp-ls.maxfiles If set, limits the amount of files returned by the script (default 10).
|
||||
-- | Volume Patrik Karlsson's Public Folder
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw------- 501 20 6148 2010-12-27 23:45 .DS_Store
|
||||
-- | -rw-r--r-- 501 20 0 2007-07-24 21:17 .localized
|
||||
-- | drwx-wx-wx 501 20 0 2009-06-19 04:01 Drop Box
|
||||
-- |
|
||||
-- | Volume patrik
|
||||
-- | maxfiles limit reached (10)
|
||||
-- | PERMISSION UID GID SIZE TIME FILENAME
|
||||
-- | -rw------- 501 20 11281 2010-06-14 22:51 .bash_history
|
||||
-- | -rw-r--r-- 501 20 33 2011-01-19 20:11 .bashrc
|
||||
-- | -rw------- 501 20 3 2007-07-24 21:17 .CFUserTextEncoding
|
||||
-- | drwx------ 501 20 0 2010-09-12 14:52 .config
|
||||
-- | drwx------ 501 20 0 2010-09-12 12:29 .cups
|
||||
-- | -rw-r--r-- 501 20 15364 2010-06-13 18:34 .DS_Store
|
||||
-- | drwxr-xr-x 501 20 0 2010-09-12 14:13 .fontconfig
|
||||
-- | -rw------- 501 20 102 2010-06-14 01:46 .lesshst
|
||||
-- | -rw-r--r-- 501 20 241 2010-06-14 01:45 .profile
|
||||
-- | -rw------- 501 20 218 2010-09-12 16:35 .recently-used.xbel
|
||||
-- |_
|
||||
--
|
||||
-- @xmloutput
|
||||
-- <table key="volumes">
|
||||
-- <table>
|
||||
-- <elem key="volume">Storage01</elem>
|
||||
-- <table key="files">
|
||||
-- <table>
|
||||
-- <elem key="permission">drwx------</elem>
|
||||
-- <elem key="uid">0</elem>
|
||||
-- <elem key="gid">100</elem>
|
||||
-- <elem key="size">0</elem>
|
||||
-- <elem key="time">2015-06-26 17:17</elem>
|
||||
-- <elem key="filename">Backups</elem>
|
||||
-- </table>
|
||||
-- <table>
|
||||
-- <elem key="permission">drwxr-xr-x</elem>
|
||||
-- <elem key="uid">0</elem>
|
||||
-- <elem key="gid">37</elem>
|
||||
-- <elem key="size">0</elem>
|
||||
-- <elem key="time">2015-06-19 06:36</elem>
|
||||
-- <elem key="filename">Network Trash Folder</elem>
|
||||
-- </table>
|
||||
-- <table>
|
||||
-- <elem key="permission">drwxr-xr-x</elem>
|
||||
-- <elem key="uid">0</elem>
|
||||
-- <elem key="gid">37</elem>
|
||||
-- <elem key="size">0</elem>
|
||||
-- <elem key="time">2015-06-19 06:36</elem>
|
||||
-- <elem key="filename">Temporary Items</elem>
|
||||
-- </table>
|
||||
-- </table>
|
||||
-- </table>
|
||||
-- </table>
|
||||
-- <table key="info">
|
||||
-- <elem>information retrieved as nil</elem>
|
||||
-- </table>
|
||||
-- <table key="total">
|
||||
-- <elem key="files">3</elem>
|
||||
-- <elem key="bytes">0</elem>
|
||||
-- </table>
|
||||
|
||||
-- Version 0.1
|
||||
-- Created 04/03/2011 - v0.1 - created by Patrik Karlsson
|
||||
@@ -59,34 +101,17 @@ The output is intended to resemble the output of <code>ls</code>.
|
||||
author = "Patrik Karlsson"
|
||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
categories = {"discovery", "safe"}
|
||||
|
||||
|
||||
dependencies = {"afp-brute"}
|
||||
|
||||
portrule = shortport.portnumber(548, "tcp")
|
||||
|
||||
local function createFileTable()
|
||||
local filetab = tab.new()
|
||||
|
||||
tab.add(filetab, 1, "PERMISSION")
|
||||
tab.add(filetab, 2, "UID")
|
||||
tab.add(filetab, 3, "GID")
|
||||
tab.add(filetab, 4, "SIZE")
|
||||
tab.add(filetab, 5, "TIME")
|
||||
tab.add(filetab, 6, "FILENAME")
|
||||
tab.nextrow(filetab)
|
||||
|
||||
return filetab
|
||||
end
|
||||
|
||||
portrule = shortport.port_or_service(548, {"afp"})
|
||||
|
||||
action = function(host, port)
|
||||
|
||||
local afpHelper = afp.Helper:new()
|
||||
local args = nmap.registry.args
|
||||
local users = nmap.registry.afp or { ['nil'] = 'nil' }
|
||||
local maxfiles = tonumber(stdnse.get_script_args("afp-ls.maxfiles") or 10)
|
||||
local output = {}
|
||||
local maxfiles = ls.config("maxfiles")
|
||||
local output = ls.new_listing()
|
||||
|
||||
if ( args['afp.username'] ) then
|
||||
users = {}
|
||||
@@ -122,12 +147,12 @@ action = function(host, port)
|
||||
for _, vol in ipairs( vols ) do
|
||||
local status, tbl = afpHelper:Dir( vol )
|
||||
if ( not(status) ) then
|
||||
table.insert(
|
||||
ls.report_error(
|
||||
output,
|
||||
("ERROR: Failed to list the contents of %s"):format(vol))
|
||||
else
|
||||
local file_tab = createFileTable()
|
||||
local counter = maxfiles or 10
|
||||
ls.new_vol(output, vol, true)
|
||||
local continue = true
|
||||
for _, item in ipairs(tbl[1]) do
|
||||
if ( item and item.name ) then
|
||||
local status, result = afpHelper:GetFileUnixPermissions(
|
||||
@@ -135,27 +160,30 @@ action = function(host, port)
|
||||
if ( status ) then
|
||||
local status, fsize = afpHelper:GetFileSize( vol, item.name)
|
||||
if ( not(status) ) then
|
||||
table.insert(
|
||||
ls.report_error(
|
||||
output,
|
||||
("\n\nERROR: Failed to retrieve file size for %/%s"):format(vol, item.name))
|
||||
("ERROR: Failed to retrieve file size for %/%s"):format(vol, item.name))
|
||||
else
|
||||
local status, date = afpHelper:GetFileDates( vol, item.name)
|
||||
if ( not(status) ) then
|
||||
table.insert(
|
||||
ls.report_error(
|
||||
output,
|
||||
("\n\nERROR: Failed to retrieve file dates for %/%s"):format(vol, item.name))
|
||||
else
|
||||
tab.addrow(file_tab, result.privs, result.uid, result.gid, fsize, date.create, item.name)
|
||||
counter = counter - 1
|
||||
continue = ls.add_file(output, {
|
||||
result.privs, result.uid, result.gid,
|
||||
fsize, date.create, item.name
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if ( counter == 0 ) then break end
|
||||
if not continue then
|
||||
ls.report_info(output, ("maxfiles limit reached (%d)"):format(maxfiles))
|
||||
break
|
||||
end
|
||||
end
|
||||
local result_part = { name = vol }
|
||||
table.insert(result_part, tab.dump(file_tab))
|
||||
table.insert(output, result_part)
|
||||
ls.end_vol(output)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -164,13 +192,9 @@ action = function(host, port)
|
||||
status, response = afpHelper:CloseSession()
|
||||
|
||||
-- stop after first successful attempt
|
||||
if ( output and #output > 0 ) then
|
||||
table.insert(output, "")
|
||||
table.insert(output, ("Information retrieved as: %s"):format(username))
|
||||
if ( maxfiles > 0 ) then
|
||||
table.insert(output, ("Output restricted to %d entries per volume. (See afp-ls.maxfiles)"):format(maxfiles))
|
||||
end
|
||||
return stdnse.format_output(true, output)
|
||||
if #output["volumes"] > 0 then
|
||||
ls.report_info(output, ("information retrieved as %s"):format(username))
|
||||
return ls.end_listing(output)
|
||||
end
|
||||
end
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user