1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-14 19:59:02 +00:00
Commit Graph

149 Commits

Author SHA1 Message Date
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
david
51e7f1f4f9 Make hexify in nse_nsock.cc take an unsigned char * to work around an assertion
in Visual C++ in Debug mode. The isprint, isalpha, etc. functions from ctype.h
have an assertion that the value of the character passed in is <= 255. If you
pass a character whose value is >= 128, it is cast to an unsigned int, making
it a large positive number and failing the assertion. This is the same thing
that was reported in http://seclists.org/nmap-dev/2007/q2/0257.html, in regard
to non-ASCII characters in nmap-mac-prefixes.
2009-05-04 17:57:27 +00:00
david
4816c7880e Fix misleading indentation in nse_nsock.cc. 2009-05-03 22:09:25 +00:00
batrick
0924a6826f This patch fixes a bug reported here [1]. The bug was due to the nsock_yield
struct not being set in any of the pcap functions. Because of this,
the callback routines would attempt to use a NULL pointer for the lua_State *
and would then SEGFAULT.

[1] http://seclists.org/nmap-dev/2009/q2/0180.html
2009-04-25 10:06:58 +00:00
david
d122b91891 Merge from /nmap-exp/david/nmap-ssl, /nmap-exp/david/ncat-ssl, and
/nmap-exp/david/nsock-ssl. This brings in secure SSL connections for
Ncat. See http://seclists.org/nmap-dev/2009/q2/0183.html.
2009-04-25 03:24:00 +00:00
batrick
947de27dfc Corrected the name confliction for the yield struct reported in:
http://seclists.org/nmap-dev/2009/q2/0171.html
2009-04-22 23:31:05 +00:00
batrick
37bbb40520 Merge of nse-lua (nse-lua-merge) minus most enchancements that were
not directly related to the change from C++ to Lua for the NSE main
procedures.

The changes are discussed in the nse-lua thread here:
http://seclists.org/nmap-dev/2009/q1/0047.html
2009-04-05 06:01:27 +00:00
david
4fc92b216c Tone down the Nsock trace level with --packet-trace, --version-trace,
and --script-trace. It was set at 5, now it's 2. That's enough to see
all the Nsock events and the contents of reads and writes. At 3 you
start to get messages like
	PCAP do_actual_pcap_read READ (IOD #%li) (EID #%li) size=%i
The message "wait_for_events" isn't printed until level 4. Getting rid
of that is the main reason for this change.
2009-03-27 21:37:14 +00:00
batrick
07cfc5aee4 Corrected many #includes for header files (where they are included).
Moved the includes for Lua headers to the .cc files so they are
not needlessly, repeatedly included.

Similarly, moved some standard headers to the .cc files and reorganized
includes to be uniform for all nse_* source files.

Fixed whitespace (removed tabs).
2009-03-10 05:56:10 +00:00
david
a173fe6ce1 Add the stdnse.sleep function. 2009-02-23 23:57:39 +00:00
fyodor
e3dcefe207 Change 'SCRIPT ENGINE' prefix in log messages to the shorter 'NSE' 2009-02-04 08:13:41 +00:00
batrick
3016193c11 Improvements to the nmap library. See [1] for discussion and a full listing of
the changes.

[1] http://seclists.org/nmap-dev/2008/q4/0663.html
2008-12-29 21:59:08 +00:00
david
c1b3ea6db3 Remove a line of dead code. 2008-10-16 22:54:37 +00:00
david
76dd72ba94 Add a guard against getaddrinfo returning an empty list of addresses in
l_nsock_connect. It hasn't been reported to cause problems but will cause a
crash if it ever happens.
2008-09-04 14:36:48 +00:00
sven
801e537697 Fix a bug in --script-trace hex dump output resulting in bytes with highest bit set to be prefixed by ffffff. 2008-09-03 22:09:15 +00:00
batrick
ce9d484281 Made nsock functions get the proper environment. (bad use of setfenv earlier).
nsock:connect function gets the global environment.
2008-08-09 23:12:52 +00:00
batrick
cd674d4f6d Cleaned up the nsock:connect function's source to be
passed its upvalues rather than having them given globally.
2008-08-09 22:55:57 +00:00
batrick
35553f80bd [NSE] Added fix for deadlocks on sockets. Now, 10 or max.parallelism threads
can have as many sockets open as they need. Previously, only 10 sockets could
be open.

See: http://seclists.org/nmap-dev/2008/q3/0130.html
2008-07-31 07:35:19 +00:00
kris
ffb3d8202d Documenting an earlier change and adding a new, related one:
o Nsock now supports binding to a local address and setting IPv4 options
  with nsi_set_localaddr() and nsi_set_ipoptions(), respectively. [Kris]

o Nmap's Nsock-utilizing subsystems (DNS, NSE, version detection) have been
  updated to support the -S and --ip-options flags. [Kris]
2008-07-14 19:52:31 +00:00
batrick
3ae4bcfa9e Removed nse_string. Equivalent procedures are placed in
nse_main and nse_nsock. nse_main now uses Lua to create printable output
while a cleaner hexify procedure has been placed in nsock.
nse_string is removed as a result.
2008-07-07 17:31:38 +00:00
bmenrigh
dea5974643 Migrated remaining *alloc() calls to safe_*alloc() 2008-06-22 04:56:02 +00:00
batrick
d0bc640db8 Large recode of nse_init.cc
Now does most of it's work through Lua:

From Nmap-dev: "Many of the changes consist of changing how Nmap interfaces
with Lua that were sometimes awkward or inflexible. Most of the functions 
have been made to be callable directly by Lua which offers many technical
advantages: stack management is alleviated, errors are handled cleanly and
are more descriptive, and there is increased reusability."

Additionally:
   -- Moved all lua_State * symbols from "l" to "L". This is to maintain
      consistency with other Lua libraries (convention) and to make our macros portable.
   -- Moved file system manipulation over to nse_fs.cc (from nse_init.cc)
2008-05-31 02:39:27 +00:00
batrick
742ff67100 Removed nse_auxiliar. Updated Script Argument parsing. Fixed typos in
documentation. Improved MySQLinfo.nse. Nsock/dnet metatabels are now
protected.
2008-05-31 02:19:24 +00:00
fyodor
5551c5a311 o Fixed a bunch of code to avoid compilation warning messages (at
least on some Linux machines) [Andrew J. Bennieston]
2008-04-09 02:11:20 +00:00
kris
8dc6b8d978 changing a couple log_write()s to use the SCRIPT_ENGINE macro rather than "SCRIPT ENGINE" literals 2008-01-21 17:18:51 +00:00
stoiko
1b143f2c36 move the check, wheter a socket is open, before connecting it again to l_nsock_queued() - otherwise there are problems with the returned values.. 2007-12-12 18:23:19 +00:00
stoiko
24cca96f14 if nse's connect is issued on an open socket, close the old connection before
connecting - this should prevent starvation, in case a single script opens many
connections
2007-12-12 14:00:40 +00:00
majek04
4ed4ffa219 Added promiscuous.nse for detecting local NIC in promisc mode. First script using pcap for nse. 2007-11-27 18:59:53 +00:00
david
1c59946d7a Throw an exception instead of calling luaL_argerror in l_nsock_connect when an SSL connection is requested but OpenSSL isn't available. 2007-11-21 02:31:07 +00:00
fyodor
57070b12a5 canonicalize capitalization 2007-09-08 05:56:15 +00:00
fyodor
082ee50244 trivial capitalization tweak 2007-09-08 04:52:00 +00:00
fyodor
8c87b5f34b remove excess debugging messages 2007-08-30 22:27:51 +00:00
fyodor
72948b35a5 Integrate a patch from Marek which sets a cap on the number of sockets opened by NSE scripts. I made some changes to use a value derived from o.max_parallelism rather than a static define 2007-08-30 21:31:01 +00:00
stoiko
e765af4103 added --script-args to the usage-text (nmap.cc)
fixed to typos in error messages (nse_nsock.cc)
added a short description of --script-args to refguide.xml
2007-08-16 10:51:27 +00:00
kris
0b50c16b38 Adding Snprintf() and Vsnprintf() to nbase/nbase_str.c. This is because of Windows' stupid implementation where it doesn't write a NULL byte at the end of the buffer if the result is truncated. I would've just #defined snprintf and vsnprintf to some wrapper function for Windows, but this doesn't work as libdnet and libpcap (and libpcap includes under mswin32) define snprintf to _snprintf and vsnprintf to _vsnprintf like we do, and through the many defines they end up being available in the Nmap sources. Vsnprintf() uses vsnprintf() (and writes a NULL byte at the end if truncated), and Snprintf uses Vsnprintf(). 2007-08-14 06:46:54 +00:00
fyodor
c124e918b7 merge soc07 r5360:5367 - Merge Majek's raw packet NSE patch 2007-08-11 06:13:25 +00:00
fyodor
62d7e3ed87 merge soc07 r5317:5322 - NSE buffered receives and script arguments 2007-08-11 06:09:50 +00:00
fyodor
8dc9673928 merge soc07 r5085 - Changing bare printf()s to log_write(LOG_PLAIN,)s because these were always printed even when things like XML and greppable output were sent to stdout (e.g. -oX -). This also adds o.scriptTrace() to make --script-trace behave more like --packet-trace and --version-trace. Nsock tracing was done unconditionally in NSE, and that has been changed to only be done when o.scriptTrace() is true. 2007-08-11 05:13:16 +00:00
fyodor
83ec445bcf merge soc07 r5005:5013 - URL manipulation lib from LuaSocket with a couple funcs added; added garbage collection for nsock-objects in lua 2007-08-11 04:46:43 +00:00
fyodor
58522c59f6 merge soc07 r4822 - Reduce the number of build dependencies. 2007-08-11 03:35:46 +00:00
fyodor
cb8101dbcc merge soc07 r4821 - fix nse build system issues 2007-08-11 03:35:12 +00:00
fyodor
b361685be8 NSE committed 2006-12-11 00:34:26 +00:00