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

91 Commits

Author SHA1 Message Date
david
bf99fb231b Check that the argument to freeaddrinfo is not NULL. The behavior may be
unspecified and causes a segmentation fault on Android Bionic libc.
Vlatko fixed the bug in his Android binaries and it was first reported
by @alexismm2.
2011-02-15 08:19:58 +00:00
david
47030f71db o [NSE] Made it a controlled Lua stack trace instead of a fatal error
when an NSE script sets a negative socket timeout. Vlatko Kosturjak
  reported the bug. [David]
2011-02-01 21:20:29 +00:00
david
18157ed081 Merge from /nmap-exp/david/nmap-unconnected. This adds unconnected
socket support to NSE, with updates in scripts and libraries.

o [NSE] Added the ability to send and receive on unconnected sockets.
  This can be used, for example, to receive UDP broadcasts without
  using pcap. A number of scripts have been changed so that they can
  work as prerule scripts to discover services by UDP broadcasting,
  optionally add the discovered targets to the scanning queue:
    - ms-sql-info
    - upnp-info
    - dns-service-discovery
  The nmap.new_socket function can now optionally take a default
  protocol and address family, which will be used if the socket is not
  connected. There is a new nmap.sendto function to be used with
  unconnected UDP sockets. [David, Patrik]
2010-10-16 00:48:44 +00:00
david
85d81f76ce Add another parameter to nsp_settrace that allows setting the FILE
stream to write to. It defaults to stdout like before if NULL is
provided. Ncat uses this to write to stderr instead.
2010-10-01 18:12:22 +00:00
david
1723949c05 Revert r20455; I meant to do this in a branch. 2010-10-01 06:29:17 +00:00
david
87ee8343f3 Provide a new nsock_setup_udp function to create a UDP socket without connecting it. Provide an NSE interface to the function. Add broadcast.nse, a script that receives UDP broadcasts with an unconnected socket. 2010-10-01 06:26:22 +00:00
djalal
85030874ea Fix a bug that prevents Nmap to compile on systems that lacks OpenSSL. This patch was contributed by Patrik Karlsson. 2010-09-26 10:43:32 +00:00
batrick
31fbab7eba Moved receive_buf function (not in use yet, until Lua 5.2) next to other
receive functions.
2010-09-21 20:01:16 +00:00
batrick
de4ba536de Merge from /nmap-exp/patrick/nse-nsock-maintenance.
This is a maintenance fix for the NSE Nsock library binding. The patch focuses
on code correctness and simplicity. The patch also brings some initial updates
with an eye towards the upcoming Lua 5.2 release. See [1] for a post concerning
this branch.

[1] http://seclists.org/nmap-dev/2010/q3/710
2010-09-18 20:35:09 +00:00
david
745a49d24a Upgrade the included Windows OpenSSL to version 1.0.0a. 2010-09-16 03:49:43 +00:00
david
1e80229708 Change "ncap" to "pcap" in some function names so the C names match the
Lua names.
2010-08-24 17:49:39 +00:00
david
bfffa53616 When nmap.connect gets a port table, let port.protocol be the default
protocol (instead of always "tcp"). You can still override it by
providing an explicit protocol after the table.
2010-08-16 18:09:04 +00:00
david
0e3c861ea0 Let nmap.connect take a host table and port table in place of a string
and an integer. This is going to be used to easily support Server Name
Indication for SSL connections.
2010-08-16 17:35:20 +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
kris
ee3c89afe4 o [NSE] When receiving raw packets from Pcap, the packet capture time
is now available to scripts as an additional return value from
  pcap_receive().  It is returned as the floating point number of
  seconds since the epoch.  The qscan.nse script was updated to use
  this more accurate data instead of using the clock_ms() function
  (which returns the current time). [Kris]
2010-07-23 10:43:04 +00:00
batrick
885bc6e034 SCRIPT_ENGINE is defined in nse_main.h. 2010-07-07 15:01:19 +00:00
luis
da126c8b78 Merged nmap-dedup branch from nmap-exp/luis/nmap-dedup. This completes the Nmap/Nping code de-duplication phase. 2010-06-22 17:24:34 +00:00
djalal
24807128d2 Merge r17640:18062 from /nmap-exp/djalal/nmap, this is a port of the LuaFileSystem directory iterator in order to use Lua code to list scripts. 2010-06-12 21:41:09 +00:00
batrick
9ead4dec87 Removed an old false comment. 2010-04-30 19:56:16 +00:00
david
5e8f88194d Use socket_errno() instead of errno in NSE raw socket code, to get
Windows errors.
2010-03-02 18:29:22 +00:00
kris
a42ea72a97 Merge through r16884 from /nmap-exp/kris/nse-rawip plus the following changelog
entries:

o [NSE] Raw packet sending at the IP layer is now supported, in addition to
  the Ethernet sending functionality.  Packets to send start with an IPv4
  header and can be sent to arbitrary hosts. [Kris]

o [NSE] Added the ipidseq script to classify a host's IP ID sequence numbers
  in the same way Nmap does.  This can be used to test hosts' suitability for
  Nmap's Idle Scan (-sI), i.e. check if a host is an idle zombie.  This is
  the first script to use the new raw IP sending functionality in NSE. [Kris]

o [NSE] Added the function nmap.is_privileged() to tell a script if, as far
  as Nmap's concerned, it can do privileged operations.  For instance, this
  can be used to see if a script should be able to open a raw socket or
  Ethernet interface. [Kris]

o [NSE] Added the function nmap.get_ports() to allow a script to iterate
  over a host's port tables matching a certain protocol and state. [Kris,
  Patrick]
2010-02-26 20:42:10 +00:00
david
f21a07cfde Revert r16464. 2010-01-15 03:55:23 +00:00
david
c73b250615 Factor out a function that reports the failure to open an Ethernet
device and exits. On Windows, print a hint about "net start npf" to
start the NPF service.
2010-01-15 00:37:39 +00:00
david
0f8c77ba4c Restore all threads that are waiting on a socket lock when a thread
relinquishes its lock. We expect only one of them to be able to grab the
newly freed lock, and the rest to go back to waiting. This seems to have
helped with a deadlock in running a large-scale favicon survey.
2009-11-28 16:58:02 +00:00
david
9d4e947b4b Revert r16121, which changed when NSE sockets are created, as it seems
to be the cause of a segfault reported by Ron Bowes.

nmap -PN -p4567 -sV --script=http-* x.x.x.x
Program received signal SIGSEGV, Segmentation fault.
nsock_connect_tcp (nsp=0x83b8b38, ms_iod=0x0, handler=0x80b5cf0
<l_nsock_connect_handler(void*, void*, void*)>, timeout_msecs=10000,
userdata=0x8729308, saddr=0x871a6f8, sslen=16, port=4567)
    at nsock_connect.c:154
2009-11-19 03:46:53 +00:00
david
8b89e83df2 Create an Nsock iod with nsi_new as soon as nmap.new_socket is called,
instead of waiting until a request is made to connect. This eliminates a
little bit of bookkeeping that needed to be done to retain state on the
NSE socket. Unfortunately this alone doesn't allow binding a socket to a
source address to receive UDP data, because Nsock doesn't create the
physical socket until a connection is made.
2009-11-18 05:35:39 +00:00
david
91478be449 Don't use the AI_NUMERICSERV flag, which isn't available on OS X, in the
getaddrinfo call in l_nsock_bind. We always use decimal port numbers anyway.
2009-10-21 18:04:15 +00:00
david
a8821f3cf4 Add the NSE function nmap.bind, which sets the source address of a
socket.
2009-10-11 23:08:43 +00:00
david
3fd8f0a0c5 Remove the allocation and freeing of a fixed-size dynamic buffer and
replace it with a static buffer.
2009-10-11 21:54:39 +00:00
david
dd6eb63b36 Fix NSE trace printing of IPv6 addresses. The code was using a plain
sockaddr instead of sockaddr_storage so it got only a fraction of the
address and the inet_ntop function would look outside of the structure
into adjacent memory. A scan of localhost would look like this:

NSE: TCP ::a00:0:600:0:1234 > ::a00:4d2:0:0:25 | CONNECT

Here, for example, that 4d2 is the port number 1234 from the other
structure. Now it prints correctly:

NSE: TCP ::1:1234 > ::1:25 | CONNECT
2009-10-11 21:51:51 +00:00
batrick
afa84d2320 [NSE] Added the reconnect_ssl method for sockets. We sometimes need
to reconnect a socket with SSL because the initial communication on the socket
is done without SSL. See this thread [1] for more details.

[1] http://seclists.org/nmap-dev/2009/q4/3
2009-10-06 13:02:12 +00:00
david
cac58924e0 Avoid dereferencing a NULL key in l_nsock_ncap_close. 2009-08-24 21:18:26 +00:00
david
ddf05afe1b Fix a memory leak in l_nsock_get_info when trying to get information
from a closed socket.
2009-08-24 21:09:47 +00:00
david
cb226847e5 Move a couple of allocated string variables into the same scope where
they are freed to avoid a memory leak.
2009-08-24 21:02:32 +00:00
david
7d87fe7aa5 Remove the const qualifier from the SSL pointer returned from
nse_nsock_get_ssl. In older versions of OpenSSL (I don't know how old)
the argument to SSL_get_peer_certificate is not const and it caused a
compiler error reported by Ron Bowes.
2009-08-19 16:33:11 +00:00
david
6c766c58cd Add the nmap.get_ssl_certificate NSE function, which returns the peer
certificate of an SSL socket.
2009-08-13 23:32:33 +00:00
josh
df71e36084 Updated uses of the ctype function to support explict casting of the arguments
to (int)(unsigned char).
2009-08-06 15:10:00 +00:00
david
9aebba220c Merge from svn://svn.insecure.org/nmap-exp/daniel/{nmap,ncat,nsock}-sctp.
This adds SCTP support (including SSL over SCTP) to Nsock and Ncat.
2009-07-25 00:03:48 +00:00
batrick
04685b77a5 Changed default --max-parallelism for the NSE Nsock library binding to 20
after discussion in the NSE meeting. We are using this value due to machines
on very poor network connections occupying a niche in Nmap's user base.
2009-07-15 15:27:16 +00:00
batrick
9dce0cd070 Fixed a compiler warning. 2009-07-14 09:56:09 +00:00
batrick
543af4c57d Increased the default parallelism for NSE to 40. This patch is the result
of testing to determine an ideal default value. A post on nmap-dev will
soon follow further describing the results and motivation.
2009-07-14 05:19:47 +00:00
batrick
fa404e03c9 [NSE] This patch is related to the change to eliminate the reliance on
GC for collecting socket locks [1].

If a thread does not close any sockets it creates, and then
returns (or errors), the thread and sockets will keep their "lock" until
garbage collected. This would be the same situation as before in this
particular case (reliance on GC).

To fix this, I have changed the socket unlock system to close all the sockets
of a thread not yielded and remove its "lock".

[1] http://seclists.org/nmap-dev/2009/q2/0624.html
2009-07-02 02:41:11 +00:00
david
8ae512478a Reorganize some code to make it clear what assignments are happening.
This was slightly tricky and caused Coverity to false report a memory
leak.
2009-07-01 23:06:41 +00:00
fyodor
9ca4041ec1 Merged -r13793:HEAD from nmap-exp/dev/nmap branch now that we're opening up trunk development
again.  Here are the items which were merged:

------------------------------------------------------------------------
r13971 | jah | 2009-06-29 14:30:27 -0700 (Mon, 29 Jun 2009) | 2 lines

Improved a pattern for matching HTTP status-line, tidy away some variables and
fix a typo.
------------------------------------------------------------------------
r13967 | daniel | 2009-06-29 13:47:04 -0700 (Mon, 29 Jun 2009) | 5 lines

o Added a convenience top-level BSD makefile redirecting BSD make
  to GNU make on BSD systems.  This should help prevent bogus
  error reports when users run "make" instead of "gmake" on BSD
  systems. [Daniel Roethlisberger]

------------------------------------------------------------------------
r13965 | batrick | 2009-06-29 06:50:11 -0700 (Mon, 29 Jun 2009) | 14 lines

[NSE] The NSE Nsock Library binding no longer relies on garbage collection to
monitor the use of socket "slots". A thread (script) attempting to connect must
first obtain one of a limited number of available socket locks (usually 10 or
--max-parallelism). The binding would use garbage collection of sockets to
determine when a thread has finished using its allocated sockets. This is
unfortunately slow and requires us to constantly run the garbage collector to
cause timely reallocation. I have changed the binding to now regularly inspect
allocated sockets in the nsock_loop function. Available sockets slots are now
immediately reallocated and done with far less execution time.

See [1] for benchmarks and further explanation.

[1] http://seclists.org/nmap-dev/2009/q2/0624.html

------------------------------------------------------------------------
r13964 | batrick | 2009-06-29 06:37:49 -0700 (Mon, 29 Jun 2009) | 10 lines

[NSE] Fixed a rare (and usually undetectable) bug that can cause a SEGFAULT.
The NSE nsock library binding may attempt to push values on the stack of
a thread that ended due to an error. It is possible that the internal
Lua stack was completely full and any further pushed values would result
in a segmentation memory violation.

This bug is very hard to reproduce with a SEGFAULT but is usually visible
when Lua assertion checks are turned on. A socket handler routine must be
called AFTER a thread has ended in error.

------------------------------------------------------------------------
r13963 | batrick | 2009-06-29 05:51:20 -0700 (Mon, 29 Jun 2009) | 3 lines

Fixed some global scoped variables to be local. This caused a many scripts to
overwrite each others' sockets, options, etc.

------------------------------------------------------------------------
r13939 | joao | 2009-06-27 16:07:35 -0700 (Sat, 27 Jun 2009) | 2 lines

Fixed port rule to include ssl pop3 port, now that pop3.lua supports SSL connections in function capabilities

------------------------------------------------------------------------
r13938 | joao | 2009-06-27 16:06:28 -0700 (Sat, 27 Jun 2009) | 2 lines

Added transparent SSL support using comm.tryssl

------------------------------------------------------------------------
r13937 | joao | 2009-06-27 16:05:19 -0700 (Sat, 27 Jun 2009) | 2 lines

Added transparent SSL support using comm.tryssl

------------------------------------------------------------------------
r13936 | joao | 2009-06-27 16:03:50 -0700 (Sat, 27 Jun 2009) | 2 lines

Added SSL transparent support using comm.tryssl

------------------------------------------------------------------------
r13935 | joao | 2009-06-27 16:02:39 -0700 (Sat, 27 Jun 2009) | 2 lines

Added SSL transparent support using comm.tryssl

------------------------------------------------------------------------
r13934 | joao | 2009-06-27 16:01:38 -0700 (Sat, 27 Jun 2009) | 2 lines

Added SSL transparent support using comm.tryssl

------------------------------------------------------------------------
r13933 | joao | 2009-06-27 16:00:27 -0700 (Sat, 27 Jun 2009) | 2 lines

SSL transparent support using comm.tryssl

------------------------------------------------------------------------
r13932 | joao | 2009-06-27 15:19:58 -0700 (Sat, 27 Jun 2009) | 2 lines

Included transparent ssl support to function pop3.capabilities using comm.tryssl

------------------------------------------------------------------------
r13931 | joao | 2009-06-27 15:19:06 -0700 (Sat, 27 Jun 2009) | 3 lines

New version of comm.lua with function tryssl, that transparently adds support to ssl connections


------------------------------------------------------------------------
r13930 | joao | 2009-06-27 14:50:38 -0700 (Sat, 27 Jun 2009) | 6 lines

Fixed buffering problem exposed by david on nmap-dev list.
The problem was solved using a buffer to receive the data, making the script work fine in cases where the ssh packets are fragmented.

A very similar solution was applied to ssh1.lua.


------------------------------------------------------------------------
r13928 | batrick | 2009-06-27 04:43:12 -0700 (Sat, 27 Jun 2009) | 18 lines

[NSE] We now propogate a NSE initiated yield on a script through all user
coroutines so that NSE may resume control. Previously, scripts that would yield
in a child coroutine (e.g. a script's child coroutine generated by Lua's
coroutine.create function) would give control back to the script. A script
would yield in this way by making a blocking socket operation. NSE would be
unable to correctly resume child coroutine when the socket operation is
finished processing.

By yielding the chain of coroutines a script has operating, we allow to NSE to
handle the socket operation properly. NSE would then resume the entire chain so
execution may correctly resume at the coroutine which initiated the socket
operation. This restores the "illusion" that a script executes without
interruption.

See [1] for more information, further explanation, and some use cases.

[1] http://seclists.org/nmap-dev/2009/q2/0586.html

------------------------------------------------------------------------
r13817 | david | 2009-06-18 15:57:29 -0700 (Thu, 18 Jun 2009) | 3 lines

Improve an OS fingerprint with a model number and broader matching.
Based on a follow-up report from a submitter.

------------------------------------------------------------------------
r13814 | josh | 2009-06-17 21:34:15 -0700 (Wed, 17 Jun 2009) | 3 lines

[zenmap] Added support to zenmap for the new SCTP options: -PY, -sY and -sZ


------------------------------------------------------------------------
r13797 | ron | 2009-06-17 11:02:18 -0700 (Wed, 17 Jun 2009) | 1 line

Applied a patch from Mak Kolibabi that enhances the output of smb-enum-processes. The output is now modeled after the output of the 'ps' tool for higher verbosity levels.
------------------------------------------------------------------------
r13795 | david | 2009-06-17 09:05:21 -0700 (Wed, 17 Jun 2009) | 6 lines

The configure script now allows cross-compiling by assuming that
libpcap is recent enough. Previously it would quit because a test
program could not be run. libpcap will always be recent enough when
the included copy is used. The patch was contributed by Mike
Frysinger.
2009-06-29 23:48:19 +00:00
batrick
68bf664db6 [NSE] Applied change to remove the old nse_macros.h header file.
Here is a mostly exhaustive list of the changes:

o Removes the SCRIPT_ENGINE_* status defines and replaces the
  instances with regular boolean integer returns or changes the
  procedure to return void. The latter case is better generally because
  the caller ignores any status return (e.g. nmap.cc calling open_nse)
  and/or the procedure raises a fatal error when unsuccessful.

o Moves the SCRIPT_ENGINE_LUA_DIR and the like to the nse_main.h header file.

o Removes the use of the SCRIPT_ENGINE_TRY (there was only one left)
  and thus changes the call to l_dnet_open to a void function called
  directly by luaopen_nsock (in nse_nsock.cc) instead of luaopen_nmap
  (in nse_nmaplib.cc). I felt moving the function was also an
  appropriate (but somewhat unrelated to the intent of the patch) change
  as opening the dnet metatable is very related to opening up the
  nsock library. This confines errors in opening the nsock library, including
  opening the dnet metatable, to the call to luaopen_nsock.

o The FILES and DIRS defines are moved in to nse_fs.h where they are
  more appropriate and localalized.
2009-06-07 01:25:53 +00:00
daniel
50830f7488 o Added initial SCTP port scanning support to Nmap. SCTP is
a layer 4 protocol used mostly for telephony related applications.
  This brings the following new features:
  o SCTP INIT chunk port scan (-sY): open ports return an INIT-ACK
    chunk, closed ones an ABORT chunk.  This is the SCTP equivalent
    of a TCP SYN stealth scan.
  o SCTP COOKIE-ECHO chunk port scan (-sZ): open ports are silent,
    closed ports return an ABORT chunk.
  o SCTP INIT chunk ping probes (-PY): host discovery using SCTP
    INIT chunk packets.
  o SCTP-specific IP protocol scan (-sO -p sctp).
  o SCTP-specific traceroute support (--traceroute).
  o The ability to use the deprecated Adler32 algorithm as specified
    in RFC 2960 instead of CRC32C from RFC 4960 (--adler32).
  o 42 well-known SCTP ports were added to the nmap-services file.
  Part of the work on SCTP support was kindly sponsored by
  Compass Security AG, Switzerland.  [Daniel Roethlisberger]
2009-06-03 23:15:45 +00:00
batrick
5c9d8c1335 Removed some old comments and old commented code. 2009-05-19 02:00:21 +00:00
batrick
9338ee98c2 [NSE] Corrected a bug in nse_nsock.cc that could result in the use of
an invalid Lua state if the thread was collected due to timeout or other even
more rare reasons. Essentially, the callbacks from the nsock library
were using a collected Lua state. I have solved this by maintaining a
reference to the Lua State Thread in the nsock userdata's environment table.
This is a temporary patch for the stable release pending a more detailed
review of the NSE nsock library binding.
2009-05-18 05:27:44 +00:00
batrick
fc4764fa34 Cleaned up the whitespace in nse_nsock.cc as per David's suggestion (I agree
with it). The whitespace was various styles in often confusing places.
The whitespace also had many evil tabs. I used the indent program and
tried to follow the whitespace of the rest of NSE C code as closely as
possible.
2009-05-17 20:50:40 +00:00
batrick
94ff7eb079 [NSE] Upon connection failure, a socket will now unlock its "socket lock"
allowing other pending socket connections to succeed sooner. This change
only slightly speeds up the process as these sockets will be collected
eventually, causing the slots to be unlocked.
2009-05-17 20:05:39 +00:00