1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 13:11:28 +00:00
Commit Graph

144 Commits

Author SHA1 Message Date
dmiller
b2ebc18360 NSEdoc fixes 2025-03-13 18:13:21 +00:00
nnposter
c661b0af64 Implement support for arbitrary separator in stdnse.tohex()
Closes #2901, fixes #2744, closes #2745
2024-08-25 13:27:58 +00:00
dmiller
94d6c605bb Fix get_script_interfaces: was crashing when filter function returned false 2024-06-13 17:45:08 +00:00
dmiller
4ee4d9ea27 New utility function: get_script_interfaces() 2024-05-24 19:01:14 +00:00
dmiller
914cd2b272 Fix stdnse.tohex not adding separators. Fixes #2531 2022-09-30 20:03:37 +00:00
dmiller
4124025d62 Clarify that args are strings [ci skip] 2022-01-03 21:08:50 +00:00
dmiller
87fe985f32 Move a reused function out to file scope 2021-12-07 19:50:47 +00:00
dmiller
8a85cdd06b Minor perf boost: use locals, not class members, for string funcs in stdnse 2021-12-07 19:50:46 +00:00
dmiller
d34d14416d Performance improvement for stdnse.tohex 2021-12-07 19:33:39 +00:00
dmiller
1943c0a2fc Simplify output_table __index metamethod
From Lua 5.3 docs: "Despite the name, the metamethod for this event can
be either a function or a table. [...] If it is a table, the final
result is the result of indexing this table with key."
2020-12-30 23:31:35 +00:00
dmiller
6f57df02be Don't strip leading 0s in stdnse.tobinary
Every place this function is used, the result is padded with 0s anyway,
so may as well not strip them here. Didn't remove the padding code since
this could return only 4 chars, and most padding is to 8-char width.
2020-11-30 23:22:07 +00:00
dmiller
5eced2c1a5 Reuse constant objects instead of creating them for frequently-used functions 2020-11-06 21:48:31 +00:00
dmiller
030a58a26e Replace 'master' with 'controller thread' in NSE script docs/comments 2020-06-18 17:14:48 +00:00
nnposter
f5b4d98153 Faster implementation of fromhex()
Over 40% faster and creates only a quarter of temporary Lua strings than
the legacy implementation
2020-06-04 19:38:10 +00:00
dmiller
0500811f5a Move string utility functions to stringaux.lua 2018-10-18 01:08:19 +00:00
dmiller
39cfbdf4e2 Use an iterator instead of building an intermediate table for format_output 2018-10-18 01:08:11 +00:00
dmiller
dcc0e3ed7e New tableaux library containing table auxiliary functions. 2018-10-17 15:34:30 +00:00
dmiller
03639761c3 Move in_port_range to shortport.port_range, expand portnumber to match ranges 2018-10-11 05:11:13 +00:00
dmiller
26ef852a28 Move stdnse.generate_random_string to new rand.lua 2018-09-08 17:07:06 +00:00
dmiller
46eca7f35f Move date/time functions from stdnse to datetime. See #517 2018-08-27 22:00:10 +00:00
dmiller
c892dab9a3 Handle large dates on platforms that can't. Fixes #1303 2018-08-10 19:42:50 +00:00
dmiller
62e667e2eb Mark stdnse.format_output as deprecated 2018-01-22 21:31:34 +00:00
rewanth
ab1eb4c037 Adds case insensitive pattern generator function. Closes
#853
2017-06-08 08:20:19 +00:00
dmiller
d334620aa0 New stdnse function 'fromhex' does hex decoding like bin.pack('H') 2017-03-10 17:29:51 +00:00
dmiller
b61d517a71 Fix lookup order of script args and allow plain 'name.arg' to be specified as 'arg' 2017-03-04 19:54:55 +00:00
nnposter
e6f3bc7a12 Simplifies implementation of function arg_value(). Closes #617 2017-01-16 01:12:15 +00:00
nnposter
8cf3d98fe9 Removes unused local variable 2016-12-17 21:22:02 +00:00
dmiller
5483beef88 Support floats and negative intervals in format_time 2016-07-21 17:05:20 +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
f4619edece Update http urls for nmap.org to https 2015-11-05 20:41:05 +00:00
dmiller
3025022f98 Optimize stdnse.debug and stdnse.verbose
Unnecessary, probably, but this eliminates 2 of 7 string
creations/collections due to concatenation and reassignment. Also
eliminates 2 unneeded table lookups and tests (since host always has
host.ip and port always has port.number), and eliminates 1 extra test
for prerule and postrule scripts, since we can't have a port if we don't
have a host.
2015-03-01 04:18:33 +00:00
dmiller
d641d00031 Simplify format_get_indent since all indents are spaces for a long time now. 2015-03-01 04:18:32 +00:00
dmiller
8f939279ca Let charset arg to stdnse.generate_random_string be a string
The charset argument was intended to be a table, since Lua doesn't allow
indexing strings with []. Unfortunately, irc-brute and tftp-enum passed
a string instead, which meant that the output was always the empty
string. This change allows both formats, and fixes those scripts.

irc-brute and tftp-enum had been broken since r33632 (no released
version of Nmap)
2015-02-25 05:06:03 +00:00
dmiller
d1e429f42b Don't crash when an NSE library (e.g. sasl) calls stdnse.debug during require 2015-01-01 21:09:03 +00:00
dmiller
140846aca1 Remove a leftover debug from stdnse.format_time 2014-11-18 03:53:24 +00:00
dmiller
379759d539 Avoid __pairs metamethod in stdnse.keys
This allows stdnse.keys to be used in a __pairs metamethod to, for
instance, yield keys in sorted order. Using next() bypasses the __pairs
metamethod that would be called when pairs() was used. Otherwise,
infinite recursion was possible.
2014-09-23 05:23:06 +00:00
dmiller
b6e59efb4b Add stdnse.keys() for extracting keys from a table 2014-09-05 13:08:09 +00:00
dmiller
6dfd1b5abe Let stdnse.format_time take other units besides seconds 2014-09-05 02:54:37 +00:00
dmiller
9460f34e32 New stdnse.format_time for showing time intervals 2014-09-05 02:54:35 +00:00
dmiller
8bb13ebf81 Localize more functions in stdnse.lua 2014-09-03 19:49:59 +00:00
dmiller
25725d369e Localize a few functions in stdnse.generate_random_string for performance reasons 2014-09-03 04:49:49 +00:00
dmiller
c615bee688 New convenience function stdnse.get_timeout 2014-09-02 18:23:09 +00:00
dmiller
2692746c42 NSEdoc cleanup
Mostly splitting function summaries (the first paragraph of NSEdoc) from
the body of the description to make the summary indexes shorter and
easier to scan.

Also fixed some unbalanced code tags like <code>foo</table>
2014-09-02 18:23:06 +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
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