1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00
Commit Graph

100 Commits

Author SHA1 Message Date
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
batrick
4201aa8eac Fix stdnse undeclared variable warning.
Also fixes a typo:

-function debug3 (...) return stdnse.debug(4, ...) end
+function debug4 (...) return _ENV.debug(4, ...) end
2014-08-02 03:37:29 +00:00
devin
5e6c9d5f78 NSE enhanced output patch 2014-05-29 03:22:59 +00:00
dmiller
125d84fd67 Allow stdnse.format_timestamp to take a Lua date table
This will allow formatting of timestamps beyond 2036, which currently
are limited by the wrapping of the 32-bit Unix timestamp.
2014-05-21 15:04:12 +00:00
dmiller
17c3e9755e NSEdoc cleanup.
1. The first paragraph of a function's NSEdoc is used as a short
summary. Some of these were very long, so I split off a shorter summary.

2. Use asterisks (*) to denote bulletted lists, not 'o'

3. Wrap lines at 80 columns

4. a couple other spelling and formatting fixes
2014-03-10 19:01:19 +00:00
dmiller
1b71f75aad Spelling fixes for Lua files
Mostly in documentation/comments, but a couple code bugs were caught,
including a call to stdnse.pirnt_debug and a mis-declared variable.
2014-02-19 04:15:46 +00:00
dmiller
69e343f0aa Reindent the last of the NSE libraries.
https://secwiki.org/w/Nmap/Code_Standards
2014-02-04 19:47:26 +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
dmiller
726b259b20 Consolidate "contains" functions into stdnse.contains
These implementations were all functionally identical. The replacement
has an extra feature of returning the index where the value was found,
currently unused.
2014-01-16 22:57:33 +00:00
dmiller
197f28265f New function stdnse.format_mac
This function will format a MAC address as colon-separated hex bytes.
It's really very simple: stdnse.tohex(mac, {separator=":"})

This commit updates all the instances I could find of the varying
convoluted attempts at performing this conversion.
2014-01-16 21:50:30 +00:00
dmiller
39cdd05864 Use @param luadoc for stdnse.pretty_printer, not @args 2013-11-28 23:26:11 +00:00
jah
bce4bcf7f9 Add missing local reference to print() to stdnse; print() is used when
stdnse.pretty_print is called without supplying it with a printer.
2013-11-05 21:56:36 +00:00
dmiller
25a2a184c4 Add __len metamethod for output_table 2013-10-18 18:35:03 +00:00
fyodor
f79a11aeeb o [NSE] Oops, there was a vulnerability in one of our 437 NSE scripts.
If you ran the (fortunately non-default) http-domino-enum-passwords
  script with the (fortunately also non-default)
  domino-enum-passwords.idpath parameter against a malicious server,
  it could cause an arbitrarily named file to to be written to the
  client system.  Thanks to Trustwave researcher Piotr Duszynski for
  discovering and reporting the problem.  We've fixed that script, and
  also updated several other scripts to use a new
  stdnse.filename_escape function for extra safety.  This breaks our
  record of never having a vulnerability in the 16 years that Nmap has
  existed, but that's still a fairly good run. [David, Fyodor]
2013-07-29 06:19:24 +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
david
dcca84eb0d Fix weird double variable declaration.
It seemed to run fine even with this.
2013-06-13 15:22:09 +00:00
dmiller
930bc91359 Modify stdnse.output_table to handle empty values better
Two changes here, both minor. First, explicitly assigning a new key to
nil does not add the key to the ordered set of keys. This better
emulates the behavior of regular tables.

> o = stdnse.output_table()
> o["test"] = nil

This previously resulted in output like this:

|_ test: nil

Now it simply omits the "test:" key.

Second, I needed a way to tell whether an output table was empty or not.
Since Lua's next() function doesn't call the __pairs metamethod, it was
always returning nil. Instead, I used the __call metamethod, since it
had the least preexisting semantic meaning:

> o = stdnse.output_table()
> =o()
false
> o["test"] = 1
> =o()
true
2013-05-06 18:39:54 +00:00
dmiller
ab098ef4d2 Don't crash on stdnse.parse_timespec(nil) 2013-03-06 04:36:09 +00:00
david
cc126ea7d4 Fix removal (assignment to nil) of elements in stdnse.output_table.
There was a reverse table that was meant to map keys to their position
in the order table, to make it easy to table.remove an entry from order.
But removing something from order would shift the indices of all
following elements by 1, and those elements were not updated
correspondingly in the reverse table. Instead, do a linear lookup for
the the element to remove from order, after checking that the element
exists at all.

http://seclists.org/nmap-dev/2012/q3/905
2012-09-20 06:47:42 +00:00
david
e9b2a8aa5d Add stdnse.format_timestamp function.
This function follows RFC 3339 and is going to be the standard formatter
for dates and times in structured output.
2012-09-08 16:09:04 +00:00
david
ac87c9b251 Add stdnse.date_to_timestamp function.
This takes a broken-down date table, as produced by os.date("*t"), and
converts it into an integer number of seconds since the epoch UTC,
interpreting it as a time in a given time zone. Simply passing a date
table to os.time is not good enough, because os.time always assumes the
date table represents a local time; i.e., you will get different results
from running os.time({year=2012,month=1,day=1,hour=12,min=0,sec=0})
depending on what time zone you run it in.
2012-09-08 16:08:58 +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
batrick
cc6d7b67bf Fix r29529. Alias was wrong. 2012-08-07 17:37:10 +00:00
batrick
036d28c898 Remove nmap.sleep as we just want to have stdnse.sleep. 2012-08-07 17:25:49 +00:00
david
21ba9f7b4a Undocument nmap.sleep and undeprecate stdnse.sleep.
There are various functions in the internal nmap.socket and nmap.dnet
libraries that are there for technical reasons:
	http://seclists.org/nmap-dev/2012/q1/318
The sleep function is exposed through the stdnse namespace because it
fits that library better.

Some code comments said that names such as nmap.new_socket were
deprecated in favor of e.g. nmap.socket.new, but the old names were
never formally deprecated, so I removed those comments.
2012-08-03 02:08:44 +00:00
perdo
54e73d555a Added a function that generates random strings to stdnse.lua. 2012-06-10 23:03:04 +00:00
batrick
6140215e2d Add explicit tags for stdnse.lua since it sets the environment
manually (it defines stdnse.module).
2012-05-30 20:44:21 +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
djalal
02b7d6e563 o [NSE] Use a table to store the output results, and use table.concat()
to concat data instead of classic concatenation. This can have a huge
  performance boost, check this thread:
  http://seclists.org/nmap-dev/2011/q3/623
2011-08-23 09:26:06 +00:00
djalal
a9bbb27a54 o [NSE] Added a missing function parameter for registry_add_table(). 2011-07-30 12:02:24 +00:00
paulino
ec63b8a647 Adds support for passing arguments without the script name. 2011-07-27 04:32:01 +00:00
batrick
dc9a35bc9d New system for silent require errors. Use the new function
stdnse.silent_require. The Lua require function is back in its usual spot
(_G.require).
2011-06-13 23:38:35 +00:00
gorjan
3d249dbb4b Adding in_port_range function to nselib/stdnse.lua 2011-05-12 22:36:45 +00:00
henri
a433cc08ed Fixed typo 2011-05-11 14:21:07 +00:00
batrick
7f66646636 Patch to make require errors silent and removed evil workarounds.
Added new stdnse function stdnse.print_verbose (similar to print_debug).
2011-05-04 21:06:53 +00:00
david
04210ef88f When an entry in stdnse.format_output has multiple lines, insert the
indent and prefix before each line, not just at the beginning. If the
indent was ">>>>", then formatting the line "AB\nCD" would result in

| >>>>  AB
|_CD

Now it will be

| >>>>  AB
|_>>>>  CD

Some script were working around this by relying on an invisible blank
first line and manually indenting following lines.
2010-12-30 21:08:24 +00:00
david
086b043cde Remove the single-string special case in stdnse.format_output.
This should be handled by the generic case, and I don't think it was
used anyway because the logic was wrong:

if(indent == nil and #data == 1 and type(data) == 'string' and not(data['name']) and not(data['warning'])) then
  return data[1]
end

This seems to be checking for a one-element table whose single element
is a string. But the test "#data == 1 and type(data) == 'string'" is
actually testing for a one-byte string. I think this is supposed to be
"type(data[1]) == 'string'", but anyway it should be handled by the
generic case.
2010-12-30 21:08:15 +00:00
batrick
03c7e9d00e Have stdnse.make_buffer read chunks instead of lines [1] so we do not implicitly
buffer based on the presence of new lines.

[1] http://seclists.org/nmap-dev/2010/q4/554
2010-11-29 22:51:51 +00:00
ron
f14a179b44 Fixed a bug in stdnse.format_output() where the 'name' attribute of the top-most table wouldn't display 2010-11-20 16:18:18 +00:00
ron
13bb98b8b8 Bring in changes from my experimental brange, nmap-http 2010-10-27 03:08:08 +00:00
ron
2608bae6ca Rollback the changes to the HTTP library I accidentally commited in the last revision 2010-10-18 21:23:24 +00:00
ron
b8e712ceeb Added a couple shares to the list of common ones (requested on IRC by kraigus) 2010-10-18 21:16:48 +00:00
david
e7fc9c4c5f Change " \n" to just "\n" where appropriate in NSE. Leading newlines are
no longer removed from script output.
2010-09-30 05:03:39 +00:00
david
3927d53e00 Simplify get_script_args and remove the deprecation warning. 2010-09-29 19:29:09 +00:00
ron
a477d142f1 Updated stdnse.get_script_args() function to take arrays in addition to strings. If an array is passed, currently, the first name is considered 'valid' and the others are considered 'deprecated'. This behaviour is still under discussion. 2010-09-24 02:52:00 +00:00
djalal
f3e08e85a0 Merge r19753,r19755,r19756,r19776,r19783 changes from nmap-exp/djalal/nmap-add-targets. The changes introduce a new stdnse function 'get_script_args()' to parse script arguments. 2010-08-16 22:06:49 +00:00
kris
cc33a59ca4 Add nmap.clock() for providing scripts with the current time in floating
point seconds since the epoch, and add clock_ms() and clock_us() to stdnse
for convenience (millisecond and microsecond).

qscan.nse now provides microsecond resolution.
2010-07-23 19:49:42 +00:00
david
8811bdb6cc Reflow NSEDoc for PDF inclusion. 2010-07-18 19:41:04 +00:00
david
7d0c08a097 Brief copyediting of NSEDoc for modules. 2010-07-12 19:42:43 +00:00
david
b7428619cf Add a stdnse.parse_timespec function. 2010-04-13 17:06:34 +00:00