Nmap Development mailing list archives
Use of nmap.fetchfile in scripts
From: Daniel Miller <bonsaiviking () gmail com>
Date: Thu, 25 Apr 2013 14:50:37 -0500
List,Today on IRC, a user had a problem with dns-brute.nse. The dns-brute.hostlist script-arg would not accept a relative filename like so: `--script-args dns-brute.hostlist=./list.txt` I provided him a small patch (http://pastebin.com/QHMavbKa) that checked for a file at the relative or absolute path after first checking the locations that nmap.fetchfile returns.
dns-brute is not the only script that does this. Lots of scripts are using the pattern of passing script-args to nmap.fetchfile, when the function really makes better sense to retrieve a static filename relative to the Nmap search paths. On the other hand, the unpwdb library does what I would expect: If the userdb script-arg is provided, it uses the value literally as a path, otherwise it uses nmap.fetchfile to grab "nselib/data/usernames.lst"
My question is: Should this behavior be standardized? I have no problem doing the grunt work, but I'd like the community's consensus on these rules:
1. Filenames from script-args should not be passed to nmap.fetchfile, but instead directly to io.open. 2. When necessary, to preserve backwards-compatibility, the script-arg may be passed to nmap.fetchfile, but if the return value is nil, the script-arg should be used verbatim.
This means that new scripts should use this idiom:filename = stdnse.get_script_args("file") or nmap.fetchfile("default.filename")
and older scripts can be brought into conformity by using this formula:
arg = stdnse.get_script_args("file")
filename = (arg and (nmap.fetchfile(arg) or arg) or
nmap.fetchfile("default.filename")
Thoughts? Dan _______________________________________________ Sent through the dev mailing list http://nmap.org/mailman/listinfo/dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Use of nmap.fetchfile in scripts Daniel Miller (Apr 25)
- Re: Use of nmap.fetchfile in scripts Kris Katterjohn (Apr 25)
- Re: Use of nmap.fetchfile in scripts Daniel Miller (Apr 26)
- Re: Use of nmap.fetchfile in scripts Kris Katterjohn (Apr 25)
