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

130 Commits

Author SHA1 Message Date
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
batrick
325a5231a5 Fixed a compiler error I introduced in 15357. 2009-08-29 06:03:04 +00:00
batrick
d788c5e3be Added function comments for the C NSE API. The comments include changes made on
the stack similar to Lua's C API.
2009-08-29 05:42:09 +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
e807b92459 [NSE] Scripts are able to access hosts from a previous host group which were scanned
and freed. This is unintended and may cause a segfault. We fix this by replacing
the current_hosts table with a new empty table when scanning a new host group.
See [1] for more information.

[1] http://seclists.org/nmap-dev/2009/q3/0782.html
2009-08-28 21:01: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
35f94dcaf3 Removed two functions no longer being used. 2009-07-15 08:53:19 +00:00
david
dab741f30f Make nse_selectedbyname return false if the "NSE_SELECTED_BY_NAME" key
is not in the registry. That function is called indirectly by
nmap.verbosity, which may be called before _R["NSE_SELECTED_BY_NAME"]
has been given a value. I was getting this error with any script scan:

NSE: failed to initialize the script engine:
attempt to call a nil value
stack traceback:
        [C]: in function 'verbosity'
        ./nse_main.lua:136: in function 'print_verbose'
        ./nse_main.lua:680: in main chunk
        [C]: ?

QUITTING!
2009-07-15 02:54:03 +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
david
47e79670b6 Add a comment explaining how the NSE_YIELD, NSE_DESTRUCTOR et al.
registry keys are used.
2009-07-09 22:56:04 +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
249c1e7179 Removed an arbitrary empty line. 2009-06-13 06:51:51 +00:00
batrick
93b5922a60 [NSE] Set L_NSE to NULL if NSE is closed (close_nse is called).
Currently NSE is only opened and closed once in Nmap so this doesn't actually
fix a visible bug.
2009-06-07 01:31:35 +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
98e51ec007 [NSE] Added Boolean Operators for --script. You may now use a boolean operator
("and", "or", or "not") combined with categories, filenames, and filenames with
a '*', wildcard, to match many files.  This change requires the script database
to be recompiled. Please see the thread at
http://seclists.org/nmap-dev/2009/q2/0100.html for more information.
2009-04-30 05:49:47 +00:00
jah
6b1421db69 Fixed leading backslash appearing in script filenames after running
--script-updatedb which caused an error when choosing which scripts to be run.
See: http://seclists.org/nmap-dev/2009/q2/0266.html
2009-04-29 23:51:28 +00:00
batrick
ea388dc454 Corrected the bug reported here http://seclists.org/nmap-dev/2009/q2/0192.html
by Michael Pattrick.
2009-04-25 01:31:58 +00:00
david
071046e385 Sort script names and categories when writing them to script.db. 2009-04-24 18:44:12 +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
592fa70389 Fixed the LUA_GCCOLLECT define. 2009-03-28 01:08:26 +00:00
batrick
794a0778a8 Similarly to /nmap-exp/patrick/nse-lua-merge:
Changed the garbage collection cycle after all threads in running are run
from a step to a full collection cycle. It can take quite a few steps before
sockets are finally collected so other threads may finish making a connection.
2009-03-28 00:48:49 +00:00
david
15fb78f042 Fix a small memory leak in thread_record::get_id. 2009-03-11 02:15:33 +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
111146a717 Use script ids instead of full paths in NSE start/finish/error debug output. 2009-02-16 17:40:55 +00:00
david
0b3ff10e1d Simplify the retrieval of script ids. Make get_id a method of struct
thread_record. Pass that directly to ScritpResult::set_id. The function
process_getScriptId is no longer needed.
2009-02-16 17:37:14 +00:00
david
40878cecf9 Change the pattern used to decide which NSE output characters to escape. It was
"[^%w%s%p]"; it's now "[^\t\r\n\032-\126]". The old pattern missed the form
feed character, ASCII 12, which is illegal in XML.
2009-02-10 05:57:51 +00:00
david
3c4f855e6d Print NSE event messages with --script-trace also. 2009-01-07 19:50:25 +00:00
david
37913d1986 Add times to the NSE event messages. 2009-01-07 04:12:00 +00:00
david
13b7a324e8 Include the script file name, target, and port in the debug messages for each
script event: start, finish, timeout, and error. The file name is now stored as
a std::string in struct thread_record so we have it when we don't have access
to the thread's environment.
2009-01-07 00:10:10 +00:00
david
57efc72d8d Reformat script event debugging output slightly. Handle the formatting of the
script target in a dedicated function. Print the thread address only at -d2 and
above.
2009-01-06 22:14:10 +00:00
david
5a745de5c7 Put the "SCRIPT ENGINE:" prefix before NSE script start/stop messages. 2009-01-06 21:57:51 +00:00
david
1c936c60cd Break out NSE event reporting into separate functions. Include the script file
name when a script fails without error. In that case we can grab the file name
directly from the thread.
2009-01-06 21:54:59 +00:00
david
a1631b4d6b Commit Patrick's NSE patch from http://seclists.org/nmap-dev/2008/q4/0750.html. This provides a -d1 message whenever a script begins or ends. 2009-01-06 21:19:32 +00:00
david
dde1d7aac3 Remove a declaration of the function cleanup_threads, which doesn't exist. 2009-01-02 19:32:05 +00:00
david
db9e8e751c Add some more documentation to process_preparethread to note what's on the
thread's stack when it is initialized.
2009-01-02 19:21:27 +00:00
batrick
38394e9f24 Corrected an output line that Ron left in from a patch I gave him.
The script's filename cannot be acessed when a thread's target times out
because we do not have access to the thread's environment when it is yielded.
All we can do is print out which target timed out. This output can
unfortunately be printed out many times for each thread (it is currently
difficult to track).
2008-12-24 08:40:03 +00:00
ron
773000b65a Merging changes from my experimental branch; the new versions of this scripts, which have significant changes to their core functionality, managed to hold their own against Brandon's network. More testing would be very helpful, though, especially with credentials (most of Brandon's scans were anonymous). 2008-12-24 00:53:01 +00:00
david
c561222685 Fix spelling in some identifiers. wierd_responses -> weird_responses,
printStatsIfNeccessary -> printStatsIfNecessary.
2008-12-04 17:04:48 +00:00
david
bb8be37ece Use a longer name (L_script_scan) for the persistent Lua state variable. 2008-11-19 01:51:25 +00:00
david
3dd89201dc Initialize one global Lua state for running script scans, and reuse it in calls
to script_scan. This makes the NSE registry persist though all host groups.
2008-11-19 01:44:09 +00:00
david
f14d86eccb Rearrange and comment the code that initializes the lists of host and port
rules.
2008-11-19 01:14:32 +00:00
batrick
085eecbac7 Removed some old debug code no longer used/needed. Added a new stack dump
function that provides a clean output of the stack with positive
and negative stack indices.
2008-11-18 23:24:17 +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
david
5464198f6b Remove the feature that showed the full path of a script when debugging was 2
or higher. Nmap already shows "Will run" messages with the full paths. This is
so that script ids are consistent in XML output.
2008-11-17 21:50:51 +00:00
david
4863d506c1 Remove script ids. Scripts are identified by file name in output (just the
basename without ".nse", or the full path with debugging level 2 or higher).
This includes documentation changes in scripting.xml.
2008-11-05 00:52:55 +00:00
batrick
20ff1375d5 Fix for scripts returning multiple results causing the getting of the script's
ID to fail.
2008-08-18 00:34:09 +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
e74d43097d Fixed some poor grammar in a comment. 2008-07-29 05:12:34 +00:00