1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 06:01:28 +00:00
Commit Graph

60 Commits

Author SHA1 Message Date
david
7db7da0007 Merge again from /nmap-exp/david/nmap-mem; this fixes a couple of bugs. 2009-12-20 03:22:19 +00:00
david
1c6030709b Revert r16307:16309, the merge from nmap-mem. I just found a
segmentation fault which I am investigating.
2009-12-19 22:49:16 +00:00
david
b838242e01 Merge from /nmap-exp/david/nmap-mem. This brings in two memory-reducing
changes. The first is that Port objects don't allocate memory for
service and RPC results unless that information is set. This reduces the
size of a bare Port from 92 to 40 bytes on my machine. The second change
is that PortList now has the notion of a "default port state," which is
the state of any ports that didn't receive a response. These ports don't
need an allocated Port object, which saves a lot of memory in scans
where most ports didn't get a response.
2009-12-19 21:26:14 +00:00
david
e2315ae075 Remove the unused Port::owner member. 2009-11-20 20:17:33 +00:00
batrick
2b3df5882f [NSE] Patch to add worker threads to NSE for scripts to use. Right
now a script is limited in parallelism to working on one socket at any
time. A script can now create a worker thread that will be capable of
doing work on sockets in parallel with the parent script. See [1] for
more information.

This patch also comes with condition variables that are similar to
POSIX condition variables. They are used in the same fashion as
NSE's mutexes (nmap.mutex).

[1] http://seclists.org/nmap-dev/2009/q4/294
2009-11-12 01:33:52 +00:00
batrick
68a9147b69 [NSE] Fixed some bugs in the vhosts patch applied in 15342:
o Stack indices for the 'ip' and 'targetname' strings were wrong.
  o Moved the lightuserdatum check right before done so a nil can't slip
    through.
2009-08-29 20:21:58 +00:00
batrick
3c14c0d7b1 [NSE] Added
nse_gettarget (lua_State *L, int index);
to replace the current_hosts static variable shared between nse_main.cc
and nse_nmaplib.cc. This improves locality and offers a clearer interface.
2009-08-29 01:24:29 +00:00
batrick
b61ed83e14 [NSE] Patch to allow virtual hosts (specified by name on the command line)
which resolve to the same IP to have script output placed under the correct
(virtual) host.  Previously, all script output would be "randomly but
deterministically" placed under one of these hosts.  Other problems include
having port information changed for only one of the virtual hosts.
2009-08-28 02:48:56 +00:00
batrick
6bbfb06704 Check the stack size before moving elements to the thread.
Some threads have truncated stacks after finishing with an error causing
a Lua assertion failure when we put elements on the stack without first
checking whether space is available.
2009-08-11 05:56:10 +00:00
batrick
4ec75b15b7 Removed an unnecessary intermediary buffer for string copying. 2009-08-09 02:55:29 +00:00
batrick
01c25ab29e [NSE] Patch to move the call NSE_SELECTED_BY_NAME to nse_main.cc for
improved locality. Other Lua Registry functions called by C were wrapped in
a C API inside nse_main.cc.
2009-07-14 22:41:25 +00:00
batrick
490c0c3b57 Add destructor for mutex "trylock" case (was forgotten in mutex destructor
patch).
2009-07-14 11:36:39 +00:00
david
276a2f195c [NSE] Scripts that are listed by name with the --script option now
have their verbosity level automatically increased by one. Many
will print negative results ("no infection found") at a higher
verbosity level. The idea is that if you ask for a script
specifically, you are more interested in such results.
2009-07-12 19:35:56 +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
93c4f35f2e [NSE] When a script ends for any reason, all mutexes are now unlocked.
Some scripts would fail due to an error (whois.nse) causing other
scripts to become deadlocked on a mutex that would never unlock. This
patch fixes this problem. See [1] for more information.

[1] http://seclists.org/nmap-dev/2009/q2/0533.html
2009-06-03 03:40:13 +00:00
batrick
3e4950eec2 Minor patch to change error messages to be lowercase as is common.
Also moved to an enumeration of mutex operations rather than hard coded
constants inside the switch.
2009-06-02 05:27:48 +00:00
batrick
fc6d15eb4f Removed some extraneous whitespace. 2009-05-17 19:43:21 +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
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
batrick
9a81f00641 Removed INITIAL from port version enum (it was accidently left in). 2009-03-09 10:56:45 +00:00
david
a173fe6ce1 Add the stdnse.sleep function. 2009-02-23 23:57:39 +00:00
batrick
1a22089dd0 Changed nil or none to be acceptable for the first value of the try function. 2008-12-30 06:56:44 +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
batrick
e6505d9954 Corrected nmap.print_debug_unformatted to print if the verbosity is greater
than or _equal_ to the specified verbosity.
See http://nmap.org/nsedoc/modules/stdnse.html#print_debug
2008-12-07 09:22:29 +00:00
batrick
c361d17734 Cleaned up some code for mutexes. 2008-12-07 01:25:14 +00:00
batrick
0f28f2818b Fixed host.os table to be a 1 based array rather than 0 based. 2008-11-20 20:30:43 +00:00
david
c2deb92228 Remove dead code from nse_nmaplib.cc. 2008-11-20 17:29:36 +00:00
david
20cf487b33 Replace the mix of spaces and tabs in the main NSE files with uniform two-space
indents, which seems to be the dominant style.
2008-11-18 21:11:27 +00:00
pgpickering
0e7549c485 added nmap.get_dns_servers() to the NSE 2008-08-21 09:25:28 +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
batrick
49a919f401 Fixed nmap library which was returning it's first argument
instead of the library table.
2008-06-22 18:38:53 +00:00
batrick
ac52d97c25 Updated library handling in nse_init, and made
nmap library properly return its library table.
2008-06-21 13:28:03 +00:00
batrick
bb07552e94 Changed a bad reference to the table.remove function for the mutex code.
The main branch does not yet have the changes to init that includes all
Lua functions being in the Registry with shorthand names.
2008-06-20 07:28:58 +00:00
batrick
f117619044 Added mutex code. 2008-06-20 07:19:37 +00:00
batrick
00c55e7e42 Removed old commented code. 2008-06-20 07:07:13 +00:00
fyodor
92e39aa66f o Update the HTTP library to use the new timing_level functionality to
set connection and response timeouts. An error preventing the new
  timing_level feature from working was also fixed.  [Jah]
2008-06-18 00:15:27 +00:00
fyodor
ac12ab6b41 o Added a new timing_level() function to NSE which reports the Nmap
timing level from 0 to 5, as set by the Nmap -T option.  The default
  is 3. [Thomas Buchanan]
2008-06-14 00:22:05 +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
david
c7017806cc Remove some dead gen-1 OS code. 2008-04-11 03:54:44 +00:00
kris
5f81cca485 When using the NSE nmap.set_port_state(), check if the requested port is already in the requested state. Otherwise, "Duplicate port" messages are printed, and the inaccurate "script-set" state reason is used. This mostly just occurs when -sV is used (I first spotted this when using Brandon's nbstat.nse with -sV, although other scripts do the same thing) 2008-03-27 22:15:50 +00:00
fyodor
61b976a45c o Nmap now saves the target name (if any) specified on the command
line, since this can differ from the reverse DNS results.  It can be
  particularly important when doing HTTP tests against virtual hosts.
  The data can be accessed from target->HostName() from Nmap proper
  and host.targetname from NSE scripts.  The NSE HTTP library now uses
  this for the Host header.  Thanks to Sven Klemm for adding this
  useful feature.
2008-02-04 22:10:29 +00:00
kris
1dd2fa821d adding nmap.fetchfile() function so scripts can find the nmap-* data files 2007-12-22 06:56:22 +00:00
diman
6229774103 fixed a problem which caused a segfault when using set_port_version with a version table which does not have all of its values set 2007-12-04 10:30:54 +00:00
david
53752ad8de Change l_exc_finalize to recognize both nil and false as exception indicators.
Previously only nil did this but most of NSE's internal functions return nil. A
value of true means there was no exception and anything else is a fatal error.
2007-11-22 08:31:13 +00:00
david
3782d2c020 Add an nmap.have_ssl NSE function and use it in the script showHTMLTitle.nse to
avoid doing an SSL probe if SSL is not available.
2007-11-22 06:38:23 +00:00
kris
7f1654e3ac Adding a couple free()s when having an early return in l_port_accessor() in nse_nmaplib.cc. Coverity (CID 32) found function_name, I added target_ip. 2007-11-16 02:20:09 +00:00
fyodor
acdaac1464 Update port state reason to script-set when an NSE script changes the --reason of a port state. Also make reason element available in port-table. Patch by Matthew Boyle 2007-11-15 21:03:00 +00:00
kris
c3b2e9af3f Adding nmap.verbosity() and nmap.debugging() for scripts so they can get the o.verbose and o.debugging values 2007-09-15 01:04:53 +00:00