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

139 Commits

Author SHA1 Message Date
dmiller
07bc658c4a Hide error traceback for nmap.new_try() handled exceptions. Fixes #2463 2022-06-29 20:40:30 +00:00
dmiller
08d50ed318 NSE: quit if all remaining threads are abandoned workers 2022-01-04 18:10:43 +00:00
dmiller
279be9917d Simplify NSE timeout debug print 2022-01-04 18:10:43 +00:00
dmiller
ccf0f3af78 Make 'Starting' and 'Finished' debug prints balanced for worker threads 2021-12-12 23:42:36 +00:00
dmiller
eb029afd7c Minor performance tweaks to core NSE functions. 2020-11-10 00:08:38 +00:00
dmiller
a0b05c0f4f Require trailing '/' to match a directory name with --script. See #2051 2020-08-28 15:06:10 +00:00
dmiller
dcc0e3ed7e New tableaux library containing table auxiliary functions. 2018-10-17 15:34:30 +00:00
dmiller
daa48fdfb8 Warn about a known bug in Lua 5.3.2 and earlier. 2018-10-16 05:18:29 +00:00
dmiller
78a526761b Avoid erroring when -sV but scripts directory is missing or modified 2018-01-09 17:35:41 +00:00
dmiller
c3bf58b2f2 Fix a typo. Closes #884 2017-05-21 02:58:08 +00:00
dmiller
abb0bf663f Clarify an assertion 2017-05-19 19:03:33 +00:00
dmiller
3a7f446b90 Avoid empty rules interpreted as all scripts in the script dir. 2017-05-19 19:03:33 +00:00
dmiller
d80a4e4e59 Print number of threads per script if <5 scripts. See #701 2017-03-21 16:20:41 +00:00
dmiller
48641e3a14 Make os calls local in nse_main.lua 2017-03-21 16:20:40 +00:00
abhishek
cd0b373130 Add --script-timeout option to limit the script's runtime. Closes #330 and Fixes #234. 2016-08-20 18:57:47 +00:00
tudor
6c8a753013 CONCURRENCY_LIMIT in NSE can be increased above 1000 with a higher --min-parallelism value 2016-07-22 05:18:32 +00:00
batrick
7f5ec526fe Merge branch 'nse-lua53'
Lua 5.3 adds several awesome features of particular interest to nmap including
bitwise operators and integers, a utf8 library, and standard binary pack/unpack
functions.

In addition to adding Lua 5.3, this branch changes:

o Complete removal of the NSE bit library (in C), It has been replaced with
  a new Lua library wrapping Lua 5.3's bit-wise operators.

o Complete removal of the NSE bin library (in C). It has been replaced with a
  new Lua library wrapping Lua 5.3's string.pack|unpack functions.

o The bin.pack "B" format specifier (which has never worked correctly) is
  unimplemented.  All scripts/libraries which use it have been updated. Most
  usage of this option was to allow string based bit-wise operations which are no
  longer necessary now that Lua 5.3 provides integers and bit-wise operators.

o The base32/base64 libraries have been reimplemented using Lua 5.3's new
  bitwise operators. (This library was the main user of the bin.pack "B" format
  specifier.)

o A new "bits" library has been added for common bit hacks. Currently only has
  a reverse function.

Thanks to David Fifield, Daniel Miller, Jacek Wielemborek, and  Paulino
Calderon for testing this branch.
2016-07-02 17:02:27 +00:00
dmiller
7a9ab13bee Fix assertion error when stats requested and 0 threads scheduled 2016-06-14 00:34:22 +00:00
dmiller
f8be8feade Allow newlines to separate script-args
This was previously done for --script-args-file with a blind gsub of all
newlines with commas (","), which meant that quoted strings could not
contain newlines. Now they can.
2016-01-14 21:08:29 +00:00
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