Nmap Development mailing list archives
[NSE] Basepath handling in http-default-accounts
From: nnposter () users sourceforge net
Date: Tue, 13 Aug 2013 20:38:25 +0000
The following patch allows http-default-accounts.lua to correctly
handle cases where the basepath consists of a single character other
than "/". Without this patch such basepaths are effectively ignored.
As an example, the current basepath normalization behavior converts
"ab" to "/ab", as expected, but it converts "a" to an empty string, as
opposed to "/a".
Cheers,
nnposter
Patch against revision 31798 follows:
--- scripts/http-default-accounts.nse.orig 2013-08-12 16:46:32.718750000 -0600
+++ scripts/http-default-accounts.nse 2013-08-13 14:23:52.437500000 -0600
@@ -182,24 +182,18 @@
---
-- format_basepath(basepath)
--- Removes trailing and leading dashes in a string
+-- Modifies a given path so that it can be later prepended to another absolute
+-- path to form a new absolute path.
-- @param basepath Basepath string
--- @return Basepath string with no trailing or leading dashes
+-- @return Basepath string with a leading slash and no trailing slashes.
+-- (Empty string is returned if the input is an empty string
+-- or "/".)
---
local function format_basepath(basepath)
- -- Remove trailing slash, if it exists
- if(#basepath > 1 and string.sub(basepath, #basepath, #basepath) == '/') then
- basepath = string.sub(basepath, 1, #basepath - 1)
- end
- -- Add a leading slash, if it doesn't exist
- if(#basepath <= 1) then
- basepath = ''
- else
- if(string.sub(basepath, 1, 1) ~= '/') then
- basepath = '/' .. basepath
- end
+ if basepath:sub(1,1) ~= "/" then
+ basepath = "/" .. basepath
end
- return basepath
+ return basepath:gsub("/+$","")
end
---
@@ -240,7 +234,7 @@
end
stdnse.print_debug(1, "%s: %d fingerprints were loaded", SCRIPT_NAME, #fingerprints)
- --Format basepath: Removes or adds slashs
+ --Format basepath: Removes or adds slashes to normalize it
basepath = format_basepath(basepath)
-- Add requests to the http pipeline
_______________________________________________
Sent through the dev mailing list
http://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/
Current thread:
- [NSE] Basepath handling in http-default-accounts nnposter (Aug 13)
- Re: [NSE] Basepath handling in http-default-accounts George Chatzisofroniou (Aug 15)
