Commit Graph

68 Commits

Author SHA1 Message Date
dmiller f0e4ac576a Limit rpc.lua fragment to what can be received in one socket timeout 2026-09-14 17:42:06 +00:00
dmiller b47e7f07ef Change explicit X==true to X 2026-07-08 00:42:18 +00:00
nnposter 8d7fa538e3 Properly detect if binding an RPC socket to a given port failed. Close #3194
Testing the return status of socket:bind() and socket:connect() is not enough.
For details, see #1939.
2025-11-01 22:34:51 +00:00
dmiller 32eaa828b7 Faster RPC number lookup 2022-09-29 22:19:28 +00:00
nnposter 80f4733c32 Correct RPC reserved port range is 512-1023
Some RPC services are strict about this and reject calls when the source port
is outside this range, causing nmap RPC calls to fail 50% of the time.
2020-02-29 22:29:51 +00:00
nnposter 922199296c Rectifies bug where RPC dump was always using program version 4 2020-01-09 22:51:02 +00:00
nnposter c4f7153c22 RPC protocol parsing workaround for NetApp 5.0
Dump response lists protocols with trailing null byte
2020-01-09 22:36:35 +00:00
dmiller 85ec647932 Support RPCBIND 3 and 4, not only portmap 2. See #1469 2019-04-15 19:35:24 +00:00
dmiller 9ba660d330 Fix endianness in string pack format 2018-09-06 01:07:23 +00:00
dmiller c47e3961b6 Remove bin.lua from rpc.lua 2018-09-05 20:34:20 +00:00
dmiller 46eca7f35f Move date/time functions from stdnse to datetime. See #517 2018-08-27 22:00:10 +00:00
dmiller 13dd6a3480 Replace bit.lua functions with bitwise operators 2017-10-19 02:42:55 +00:00
dmiller edfc5e3835 Remove useless bin.pack('A') calls (equivalent to tostring) 2017-03-14 02:51:06 +00:00
dmiller 8f3bbf33a5 Avoid crash in rpc.lua due to packing nmap.clock (a float) as integer 2016-08-19 17:37:30 +00:00
dmiller bd99365851 Change rpc's GetAdditionalBytes to error on a short read without an extra timeout 2016-06-28 02:19:44 +00:00
dmiller cb4b46bd53 Canonicalize authors as tables instead of comma-separated strings 2016-06-09 22:46:42 +00:00
dmiller f4619edece Update http urls for nmap.org to https 2015-11-05 20:41:05 +00:00
dmiller 9840973b60 Fix format string argument mismatches
Cases where the format string does not contain any placeholders, but
values are given anyway. Cases where string.format is used without any
placeholders or arguments.
2015-09-18 12:40:32 +00:00
dmiller e2bfa97920 Replace instances of bin.pack('A', x), which is equivalent to tostring(x), and a no-op on strings 2015-03-03 04:48:18 +00:00
dmiller c615bee688 New convenience function stdnse.get_timeout 2014-09-02 18:23:09 +00:00
dmiller 964006b223 Adjust default timeout for rpc.lua
Reported: http://seclists.org/nmap-dev/2014/q3/378

Changes the default timeout for rpc.lua from 30s to 5 times Nmap's
calculated host timeout or 10s if no timeout info is available.
2014-08-29 16:34:56 +00:00
batrick ee6622aea4 nselib stdnse.print_debug -> stdnse.debug
$ f() { find -name \*.lua -exec /bin/echo sed -i "$1" {} \; ; }
$ f 's/stdnse.print_debug( *\([0-9]*\) *, */stdnse.debug\1(/'
$ f 's/stdnse.print_debug( *"\(.*\))/stdnse.debug1("\1)/'
2014-08-03 00:56:45 +00:00
dmiller ec9074f718 Correct "it's" to "its" where necessary
it's = it is
its = belonging to it
2014-06-19 04:58:46 +00:00
dmiller e296cdea2a Fix some @see NSEdoc
https://secwiki.org/w/Nmap/Code_Standards#NSEdoc_best-practices
2014-03-04 17:04:58 +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 1c0c090ace Refactor some Lua string concatenations.
Using this regular expression, '\(\w*\)\s*=\s*\1\s*\.\.', found and
replaced many string concatenation-reassignments. These can cause
performance issues, since a new string gets allocated for each
reassignment. In many cases, the replacement is simply a single string,
wrapped across lines with the '\z' escape, which consumes a newline and
whitespace following it. In other cases, a table is used to hold the
substrings until the final string is built with a single table.concat
operation (same technique used in stdnse.strbuf).

Also, some string-building loops of this form:

s = ""
for i = 1, 100, 1 do
  s = s .. "\0"
end

were replaced with this much faster and cleaner version:

s = string.rep("\0", 100)
2014-02-18 18:10:23 +00:00
dmiller fb67a6717e Re-indent some libs and scripts, change 4 to 2-space indent
Mostly found with:

    for i in nselib/*.lua scripts/*.nse; do
      echo $(perl -lne 'BEGIN{$a=$p=0}next unless $_;/^(\s*)/;' \
        -e '$l=length$1;next if$l==$p;$a+=(abs($l-$p)-$a)/$.;' \
        -e '$p=$l;END{print$a}' $i) $i
    done | sort -nr

And indented with: https://gist.github.com/bonsaiviking/8845871

whois-ip.nse was particularly mangled (probably my fault due to using
vim's built-in indentation script, but it could be structured better)
2014-02-06 23:25:28 +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 ba4097af38 os.date format string cleanup
Removed some non-ANSI-C strftime format strings ("%F") and
locale-dependent formats ("%c") from NSE scripts and libraries.
C99-specified %F was noticed by Alex Weber
(http://seclists.org/nmap-dev/2013/q2/300)
2013-05-16 14:59:48 +00:00
david e03dcf3d8a Do a connect on rpc-grind UDP sockets to invoke socket_lock.
This connect should be side effect–free except for calling socket_lock,
which prevents the creation of an excessive number of sockets. Not using
the lock was causing "Too many open files" errors.

We should have a cleaner general solution for this, and not require
scripts to "connect" their unconnected UDP sockets. I seem to remember
that there was a good reason for not enforcing the lock on socket
creation, but only on connect, as we do.

http://seclists.org/nmap-dev/2012/q4/435
2012-12-31 19:06:33 +00:00
henri 16ea382e9b Added a maximum number of retries to mitigate a remote DoS in the RPC
packets parsing code. The number was chosen high to avoid decreasing
accuracy. It's just about having an upper limit.
2012-10-20 14:59:53 +00:00
patrik 40b1c4705b check_globals cleanup 2012-10-07 12:39:21 +00:00
henri 1f31f2e991 Typos 2012-10-06 21:24:50 +00:00
david b19647254d Typo. 2012-09-23 21:15:20 +00:00
dmiller 520651a9ed Check for timeout when trying reserved ports
rpc.Comm.Connect was trying to bind to 424 reserved ports, which is
overkill. Since nsock doesn't do an actual bind(2) call until
socket:connect for TCP, that meant up to 424 connect calls, each of
which is currently leaking a socket. This commit contains 3 fixes:

1. Add nmap.new_socket calls for non-privileged code path that were
moved inside the privileged loop to originally address the leak.

2. Check for TIMEOUT on each of the TCP connect calls and abandon the
Connect, avoiding many timeouts.

3. Try 10 random reserved ports (from 1 to 1024) instead of 400+.
Should be good odds of finding one unused, even when lots of threads are
trying (though empirical results would be helpful). Also, this should
reduce load since thread n won't need to fail n-1 bind attempts.
2012-09-21 02:39:48 +00:00
david 23625913a8 Create (and close) a new socket in rpc Connect, don't reuse one.
It appears that connecting more than one with the same nse_nsock socket
leaks socket descriptor. For example,

local s = nmap.new_socket()
s:connect(host, port) --> TIMEOUT
s:connect(host, port) --> TIMEOUT
s:close()

leaks a socket descriptor, the one used in the first connect. Nsock
should really take care of this, but let's do this workaround because
rpc-grind has been causing problems due to using the above pattern:

http://seclists.org/nmap-dev/2012/q3/864
http://seclists.org/nmap-dev/2012/q3/872
http://seclists.org/nmap-dev/2012/q3/949

The difficulty is that the rpc library will tolerate around 400 of those
timeouts per RPC connection, which leads to rapidly running out of
descriptors.
2012-09-21 01:08:14 +00:00
dmiller 4728d7437d Fixes to rpc-grind
NSE: rpc-grind Connect(): RPC library does not support: nil protocol
NSE: rpc-grind Connect(): RPC library does not support: rpcbind version
81578896

These errors caused by ChkProgram and ChkVersion called from
rpc.Comm.Connect. Added a dummy program in rpc-grind and a check for
self.checkprogver in ChkVersion, and everything works great.

Also fixed portrule to only fail if the non-rpcbind service name was not
the result of table lookup. Was failing on port 2049 (in nmap-services
as "nfs") without -sV.
2012-08-18 03:32:50 +00:00
kroosec 17d27f76b0 Updated documentation for rpc.lua latest changes. 2012-08-01 10:02:22 +00:00
kroosec 3cd7f8865d Added ability to disable for program and version support checking in rpc.lua. Authentication now defaults to NULL. 2012-08-01 09:58:48 +00:00
henri d1d1c7a6f4 Re-enabled connection attempts to RPC services when running in non-privileged
mode. This also fixes a bug in the privileged port binding loop, don't always try to
bind() to port 1000 but use the current resvport instead.
2012-07-27 17:23:03 +00:00
kroosec 4aebcc973b Small typo fix in rpc.lua. 2012-07-23 09:58:30 +00:00
david 360ba052e9 AUTH_UNIX support for rpc.lua.
http://seclists.org/nmap-dev/2012/q2/54

This patch is from Daniel Miller. He writes:

I've just finished enhancing the nfs-ls, nfs-statfs, and nfs-showmount
scripts so that they can run based on version detection information,
for cases where the portmapper is firewalled. For nfs-ls and
nfs-statfs, this required making a hostrule to check that both a
mountd service and a nfs service were detected. In the process, I
ended up adding the AUTH_UNIX flavor to rpc.lua, since the RFC states
that AUTH_NULL can only be used for the NULL procedure (and my Linux
nfs-kernel-server was enforcing that).

Other minor changes:

* If running privileged, attempt to bind to a reserved port. Many NFS
servers refuse to talk to source ports >1024, as a "security measure"
* handle an odd case in nfs-ls where READDIRPLUS does not return file
attributes. Chose to use all ?'s, but in the future maybe a direct
GETATTR call?
* remove reference to nfs.dirlist argument from nfs-ls doc, since it is unused
2012-06-20 02:12:58 +00:00
david aa6717eb1f Lua 5.2 fixed from Daniel Miller.
http://seclists.org/nmap-dev/2012/q2/525
2012-05-29 20:11:39 +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
henri 15f7ad8f3c Fixed typo. 2012-05-21 15:44:25 +00:00
patrik 2881ec0a19 o [NSE] Added RPC Call CALLIT to the RPC library and modified UDP sockets to be
unconnected in order to support broadcast. [Patrik]
2012-02-25 15:59:41 +00:00
batrick 5a68e5f04a Set the math.randomseed value in nse_main.lua on behalf of scripts.
Since Lua uses the C rand and srand functions, which have a static
seed for the entire program, we don't want scripts doing this themselves.
2011-05-23 21:43:46 +00:00
djalal b18df4d50a Make functions that call Helper.GetProgramInfo() return a string message on errors. 2010-10-31 18:29:15 +00:00
djalal 63f25dcc97 Add more NSEDoc and remove obsolete functions: ToAclMode() replaced by FmodeToOctalString() and ToAclText() replaced by FpermToString(). 2010-10-20 17:33:06 +00:00