1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00
Commit Graph

120 Commits

Author SHA1 Message Date
dmiller
69345854ee Fix script matching patterns that start with category names
The keyword patterns like "categories" or K "true" were consuming the
first part of patterns like --script 'broadcast-*' resulting in the
error "'broadcast-*' did not match a category, filename, or directory"

Changed to add a lookahead match for space, parentheses, or end-of-line
before considering a keyword to have matched.
2015-08-12 14:29:20 +00:00
dmiller
2fa36ec97f Fix arg parsing with nested tables, e.g. {{path=/}} 2015-08-11 20:45:33 +00:00
dmiller
21560db1cf Strip escapes from quoted script-args before returning them 2015-06-15 03:32:59 +00:00
jah
3c3d3bc55a Fix thread.info in Script:new_thread and new_worker
in nse_main - the pattern to capture the script thread ID did not
match on Windows.  See http://seclists.org/nmap-dev/2015/q1/205 .
2015-04-06 16:26:48 +00:00
jah
ff8c8484b0 Revert revision 34034 from nmap/nse_main.lua:
Fix the creation of the thread.info property.
2015-02-20 04:27:28 +00:00
jah
6146593e11 Fix the creation of the thread.info property.
Update the patterns used to extract hex chars from the string representation of a coroutine.  It seems the string has changed in Lua 5.3 from "0xAB..." to "thread: AB..."; this was before:-

NSE: Starting http-feed M:nil against ...
NSE: http-feed M:nil spawning new thread (thread: 02C63A78).
NSE: Finished http-feed W:nil against ...

this is now:-

NSE: Starting http-feed M:02D6EAF0 against ...
NSE: http-feed M:02D6EAF0 spawning new thread (thread: 02D6E640).
NSE: Finished http-feed W:02D6E640 against ...
2015-02-20 03:07:04 +00:00
dmiller
f560655605 Enhance NSE debugging messages slightly 2015-02-02 03:56:10 +00:00
jay
b281e0bf1d Get rid of unnecessary spaces at the end of lines 2014-08-09 19:09:06 +00:00
batrick
1cec0a305b Run rule functions in the main loop.
This allows usage of verbose/debug in portrule/hostrule and access to all
functionality of NSE, including sockets. So for example, we can now do:

function portrule (host, port)
  local response = http.get(host, port, "/");
  stdnse.debug1(response.body)
  ...
end

The verbose/debug function did not work in rule functions because the
introspection API (getid, gettid, etc.) only work when NSE is in the main loop.
The main loop sets the required internal variable current needed by the API.

List of changes:

stdnse.lua:

  o debug/verbose check the debugging/verbosity level much earlier to allow
    returning if nothing will be printed.

  o Simplified debug/verbose logic to handle the optional first argument
    better.

  o made debug/verbose local functions to avoid using globals and allow self
    tail calls

nse_main.lua:

  o The logic for adding threads via a rule function is simplified. So long as
    the script has the desired rule function, a thread is always returned.
    Evaluation of the rule function is done while NSE is in the main loop (i.e.
    not in script:new_thread()). The rule function only determines if the action
    function is run.

  o [Not a change:] If the action function will be run or was run then we see
    the usual "Starting X" and "Finished X" messages from NSE.

  o Use Lua 5.2's pack function instead of the slightly more expensive
    {n = select("#", ...), ...} idiom.

  o New stdnse.getinfo introspection function which is used by stdnse.debug.
2014-08-02 21:18:08 +00:00
dmiller
fa65ff04d0 Restore verbosity boost for by-name scripts, broken in r33104 2014-07-31 05:34:17 +00:00
devin
d68396d823 Merged Lpeg branch 2014-06-26 20:12:54 +00:00
batrick
c6fc780a29 remove extraneous arguments 2014-05-29 13:30:21 +00:00
devin
5e6c9d5f78 NSE enhanced output patch 2014-05-29 03:22:59 +00:00
dmiller
3f0d0c16f9 Spellcheck on Nmap, Nsock, Nbase source files 2014-02-20 18:44:12 +00:00
dmiller
b3b5f8c377 Fix format-string bug: ./nmap -sC --script-args '%n' -ddd 2014-02-19 22:14:18 +00:00
dmiller
cd7df91ce0 Fix a bug introduced in r32678
string.gsub returns 2 values, the new string and the number of
replacements made. It also has a 4th argument, the number of
replacements to make. So when you use the return value of gsub as the
3rd argument, and no replacements were made, it instructs the next call
to not make any replacements. Thanks to Ron Bowes for reporting this
issue.
2014-01-29 13:24:30 +00:00
david
d6288c5280 Escape '%' in arguments to Thread:d.
A user reported this crash when scanning a target whose name contained
the '%' character:

NSE: Script Engine Scan Aborted.
An error was thrown by the engine: nse_main.lua:322: invalid capture index
stack traceback:
	[C]: in function 'gsub'
	nse_main.lua:322: in function 'd'
	nse_main.lua:377: in function 'start'
	nse_main.lua:912: in function 'run'
	nse_main.lua:1390: in function <nse_main.lua:1293>
	[C]: in ?

I'm not sure how a name with '%' got resolved, but I was able to
reproduce the crash by adding this line to /etc/hosts:
	127.0.0.1	a%40b
and then running
	./nmap --script=banner a%40b -d --top-ports 5

The gsub function recognizes "%d", where d is a digit, as a capture
index. The constructed string is then passed to print_debug, which is
like printf. Therefore we escape every occurrence of "%" twice, to get
"%%%%".
2014-01-27 22:56:29 +00:00
dmiller
620f9fdb34 Remove trailing whitespace in lua files
Whitespace is not significant, so this should not be a problem.
https://secwiki.org/w/Nmap/Code_Standards
2014-01-23 21:51:58 +00:00
batrick
bd387f6826 With debugging, NSE prints out the script-args string and the pretty printed
final script-args table. The rationale is, unfortunately shells interpret
quotes differently and so it can be hard to tell exactly what NSE ends up
seeing/producing. [Some discussion in #nmap on Freenode resulted in this
addition.]
2013-06-23 02:40:28 +00:00
batrick
48b604bcd2 The directory path was being passed to Script.new rather than the file in the
directory. This bug was reported by Robin Wood [1].

[1] http://seclists.org/nmap-dev/2013/q2/282
2013-05-12 21:24:16 +00:00
david
a1cc3690cc Include the targetname if possible in NSE diagnostic messages. 2013-02-07 23:26:18 +00:00
batrick
e8caacae85 Read large chunks instead of lines. 2012-12-16 00:24:37 +00:00
batrick
76239f73b9 Escape backslashes which may appear in Windows filenames. 2012-12-16 00:02:08 +00:00
david
ad65ddb777 Simplify a boolean condition. 2012-10-18 03:18:07 +00:00
batrick
164fbe284b o Added a "Worker" class which helps encapsulate behavior better.
o Moved some specific behavior for resuming a thread to Thread:resume().
o Cleaned up the inheritance mechanism to use a static metatable (the Class
  table itself).
o Worker main functions are no longer wrapped with a function to truncate to 0
  results. Instead, we just check if a thread is a worker in Thread:set_output()
  to prevent adding output by worker threads.
2012-10-09 07:16:01 +00:00
batrick
4fe62b040c Better response to misuse of stdnse.base|new_thread when not executing an
action function (current == nil).
2012-09-23 21:31:02 +00:00
david
676de05f7f Provide a default {} value for script categories.
This is so I don't have to write
  categories = {}
when writing test scripts.
2012-08-28 12:17:36 +00:00
david
fdac9750a1 No longer require the "description" field in scripts.
This is so I don't have to do
  description = ""
when writing test scripts.
2012-08-28 12:17:27 +00:00
dmiller
c3f88169a4 Fix NSE error: attempt to get length of a number
NSE: Script Engine Scan Aborted.
An error was thrown by the engine: attempt to get length of a number
value
stack traceback:
        [C]: in function 'port_set_output'
        /home/rt/builds/nmap/nse_main.lua:314: in function 'set_output'
        /home/rt/builds/nmap/nse_main.lua:947: in function 'run'
        /home/rt/builds/nmap/nse_main.lua:1330: in function
</home/rt/builds/nmap/nse_main.lua:1237>
        [C]: in ?

This now allows return of anything stringifiable as second return value
without crashing (though this may not be what the script author intends,
better to not crash)
2012-08-23 18:45:42 +00:00
batrick
24e38466f5 Do version checking for Lua 5.2. 2012-08-14 22:19:09 +00:00
dmiller
c5d642a340 Check for nil return from scripts to avoid empty <script> elements 2012-08-14 17:25:43 +00:00
david
0c3e0fcc4d Structured script output.
Scripts may now return a key–value table, or such a table in addition to
a string. The table will be automatically formatted for normal output
and will appear as a hierarchy of elements in XML output.

Some history and discussion of this development can be found at
https://secwiki.org/w/Nmap/Structured_Script_Output.

This is a merge of r29484:29569 from /nmap-exp/david/xml-output.
2012-08-14 16:36:25 +00:00
patrik
6f43ac38b2 SSL overhaul fixing OpenSSL related problems when SSL has not been compiled in
* replace require function calls with stndse.silent_require
* fixed a bug in nse_main that would fail creating scripts.db when a script
  fails to load
* reworked some code to provide limited functionality even though SSL is not
  present
2012-08-05 12:05:07 +00:00
batrick
715525f31b Throw an actual error. Do not yield. 2012-08-05 09:16:04 +00:00
perdo
6e5b999c99 Add parts of LuaFileSystem to NSE (support for mkdir, rmdir, link). 2012-07-17 18:07:28 +00:00
batrick
bbea3dc088 "Start" the worker thread so the host timeout accounting is correct.
Also add to num_threads for accounting.
2012-07-14 22:32:37 +00:00
batrick
000f6dc4d9 Lua 5.2 upgrade [1] for NSE.
[1] http://seclists.org/nmap-dev/2012/q2/34
2012-05-27 08:53:32 +00:00
patrik
59b30bacf8 o [NSE] Added an error message indicating script failure, when Nmap is being
run in non verbose/debug mode. [Patrik Karlsson]
2012-04-04 21:11:20 +00:00
patrik
72af4637b0 o [NSE] Added host based registry, which allows scripts to share data between
scripts scanning a specific host. [Patrik]
2012-02-22 20:03:15 +00:00
david
be73a3e9e9 Put the nselib/* loader at the front, not the end, of the loaders list.
The loaders list determines the order in which places are checked for
Lua modules. I had a problem on Windows when the nmap.exe directory
contained WinPcap's packet.dll. There was a runtime error when liblua
tried to open packet.dll instead of our packet.lua. This way we check
for our own files first.
2012-02-08 22:28:06 +00:00
fyodor
bb62bab448 o Added the new --script-args-file option which allows you to specify
the name of a file containing all of your desired NSE script
  arguments.  The arguments may be separated with commas or newlines
  and may be overridden by arguments specified on the command-line
  with --script-args. [Daniel Miller]
2012-01-03 07:14:20 +00:00
batrick
165b58f3d3 minor improvements 2011-12-16 21:01:09 +00:00
patrik
2197116d18 o [NSE] Added support for forcing scripts to run agains certain ports by adding
a plus in front of the script name. [Martin Swende]
2011-12-16 20:37:46 +00:00
batrick
110b0d35b0 Fixed a bug I introduced in r23911 that caused some "rules" to not
mark a script as selected by name.
Removed some dead code.
2011-09-30 06:54:53 +00:00
batrick
8628520123 Change module separator to directory separator as is done in
Lua's ?.lua loader. This is necessary when requiring submodules
e.g. require "foo.bar"
2011-09-20 18:24:09 +00:00
batrick
6069b50ce3 Add loader for searching nselib/ for ?.lua files. nselib/ can be in multiple
directories that nmap will search, e.g. ~/.nmap/nselib $NMAPDIR/nselib
/usr/share/nmap/nselib etc.

Resolves Daniel Miller's request [1].

[1] http://seclists.org/nmap-dev/2011/q3/817
2011-09-20 16:18:35 +00:00
djalal
7d0df638ab o [NSE] When the rule function failes include its type in the error message. 2011-08-16 01:24:46 +00:00
djalal
39be3a4621 o [NSE] Use the correct variable 'value' instead of 'rule_return' to
show the error message of the rule function and why it has failed.
2011-08-16 01:22:01 +00:00
batrick
4d27d83f62 Fix to make SCRIPT_NAME not have a filename extension in certain situations.
See [1].

[1] http://seclists.org/nmap-dev/2011/q3/304
2011-07-21 18:26:11 +00:00
batrick
9d7ce06a96 better error message when script fails to load (now includes traceback of the script) 2011-07-21 17:46:16 +00:00