1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

156 Commits

Author SHA1 Message Date
dmiller
89f0e62679 Handle immediate write errors in NSE. 2025-07-11 19:47:06 +00:00
dmiller
209e5735d8 Correctly handle immediate return from nsock_read in NSE. Fixes #3133 2025-06-13 23:00:28 +00:00
dmiller
4ed1ce0eee Avoid passing empty string to nsock_pool_set_device
Nsock checks for NULL, but not for empty string. Rather than making
Nsock decide, each app will decide whether to call
nsock_pool_set_device, with all currently skipping the call if device is
an empty string.
2025-06-09 18:38:59 +00:00
dmiller
a62aa864eb Check for immediate return from nsock_read due to EOF 2025-04-11 14:57:56 +00:00
dmiller
06d3c923bb Simplify check for immediate return from nsock 2025-04-11 14:57:55 +00:00
dmiller
136e1c6ed7 Lua 5.4 change: userdata created with 1 uservalue by default. Set to 0 when possible 2024-06-20 20:47:10 +00:00
dmiller
633bfe00b3 Allow NSE to connect via DTLS 2024-06-03 19:00:29 +00:00
dmiller
f78be32513 Handle pcap sockets just like other nsock sockets.
Pcap nsock sockets in NSE were cached so that multiple threads opening
the "same" pcap descriptor (same device, bpf, promisc, snaplen) would
get the same socket object. This is a leftover from a very old design
that would multiplex captured packets to each thread, but for a long
time that meant that each thread would just get whatever packets were
available and miss any that another thread received. This almost never
happened because scripts don't use identical pcap descriptors generally.
But it did complicate garbage collection, resulting in segfaults and
assertion failures in certain scenarios such as double-closing a socket.
2022-01-04 18:10:45 +00:00
dmiller
026cd801d7 NSE nsock event handling improvements
If an event is canceled, report it to the waiting thread as an error.
Previous behavior left a waiting thread waiting forever, so NSE never
stopped.

If the event is killed, that means Nsock is being shut down, so this is
coming from the garbage collection handler and we don't want to restore
anything. Just return instead.
2022-01-04 18:10:44 +00:00
dmiller
88c7e9d1e8 Use less space for pcap dev name; simplify ifdef 2021-12-16 23:29:17 +00:00
dmiller
541d89cb1a Check for arg problems earlier in connect and pcap_open 2021-12-16 23:29:16 +00:00
dmiller
aaea7ab4e9 Allow a socket created/connected in one thread to be used in another. See #1233 2020-02-18 19:41:29 +00:00
dmiller
a2c75e0ef4 Abstract nsock logging function to avoid nsock.h inclusion in output.h 2020-01-11 16:03:28 +00:00
dmiller
840af24083 Clean up immediately and avoid pcap garbage collection if opening fails 2019-03-19 15:51:43 +00:00
dmiller
6d72dbb9df Add more assertions and checks for cross-thread socket use. See #1233 2018-07-07 21:13:46 +00:00
dmiller
0ff217dc53 Re-add some needed includes on Windows 2017-04-20 17:24:33 +00:00
dmiller
86edcb0e5b Remove some unused includes 2017-04-19 19:06:47 +00:00
dmiller
49eefce439 Sergey's GSOC 2016 brute.lua improvements. Closes #518 2016-12-09 15:05:51 +00:00
dmiller
18d7a9195d Mark a variable unused, since it is a byproduct of a different function and only used when OpenSSL is configured. 2016-10-18 02:24:40 +00:00
vincent
f704b6e830 Split declaration and setting of variable nsp to avoid warning
Actually this is not a problem. I've just split the variable 
declaration and assignment to fix the following compiler warning:
Compiler warning avoided: "variable nsp unused" - in case nmap has
been compiled without openssl.
Thus, this is more to bypass the warning than to fix anything at 
all.
2016-10-17 11:19:25 +00:00
dmiller
8b46e5e3c3 Be more clear about where errors come from in NSE bind 2016-08-30 18:59:55 +00:00
dmiller
610bb63f49 Port numbers are integers; bugs happen when we use floats. 2016-08-30 18:59:54 +00:00
batrick
71e3c76f95 use dynamic upval count to allow easy changes 2016-08-03 01:28:10 +00:00
dmiller
98d5fd7625 Fix a segfault due to Nsock event leak in NSE. 2016-07-21 21:36:40 +00:00
dmiller
dbc26606ca Fix crashes when assigning timeouts as floats. New NSE utility function nseU_checkinteger 2016-07-17 04:56:29 +00:00
batrick
7f5ec526fe Merge branch 'nse-lua53'
Lua 5.3 adds several awesome features of particular interest to nmap including
bitwise operators and integers, a utf8 library, and standard binary pack/unpack
functions.

In addition to adding Lua 5.3, this branch changes:

o Complete removal of the NSE bit library (in C), It has been replaced with
  a new Lua library wrapping Lua 5.3's bit-wise operators.

o Complete removal of the NSE bin library (in C). It has been replaced with a
  new Lua library wrapping Lua 5.3's string.pack|unpack functions.

o The bin.pack "B" format specifier (which has never worked correctly) is
  unimplemented.  All scripts/libraries which use it have been updated. Most
  usage of this option was to allow string based bit-wise operations which are no
  longer necessary now that Lua 5.3 provides integers and bit-wise operators.

o The base32/base64 libraries have been reimplemented using Lua 5.3's new
  bitwise operators. (This library was the main user of the bin.pack "B" format
  specifier.)

o A new "bits" library has been added for common bit hacks. Currently only has
  a reverse function.

Thanks to David Fifield, Daniel Miller, Jacek Wielemborek, and  Paulino
Calderon for testing this branch.
2016-07-02 17:02:27 +00:00
dmiller
3749c04310 Sanity check in pcap_recieve to avoid crash. Fixes #313 2016-03-07 16:44:52 +00:00
dmiller
0577e3bb1e Avoid crashing when Nsock connect calls the callback immediately due to parameter errors 2016-03-04 23:04:01 +00:00
henri
b55ff2d68f Don't associate nsock logging info to a nspool.
Make current loglevel and current log callback global
to the library. Attaching them to the nsock pool doesn't
bring any benefit and prevents from logging activity in
code sections that don't have access to a pool (such as
proxy chain specification parsing).

Updated external calls and nsock tests accordingly.
2015-06-27 08:21:53 +00:00
henri
b75233ce98 Consistently renamed nsi_XXX calls into nsock_iod_XXX
This is part of the effort to make nsock expose only
nsock_ prefixed symbols and simplify the API.
2015-06-27 08:21:33 +00:00
henri
fd40b8df08 Simplify Nsock SSL init API
Replaced nsock_pool_ssl_init_max_speed() by a NSOCK_SSL_MAX_SPEED
flag to be passed to nsock_pool_ssl_init(). Default (flag=0) means
secure.
2015-06-27 08:21:22 +00:00
henri
0348359f60 Enforce nsock naming scheme.
convert nsp_* calls into nsock_pool_*. Separate words with underscores
where appropriate.
2015-06-27 08:21:16 +00:00
dmiller
84d0e45641 Remove some unneeded includes of utils.h 2015-06-23 15:52:55 +00:00
dmiller
6a8f12e165 Prevent NSE from connecting to the wrong AF: http://seclists.org/nmap-dev/2012/q3/871 2015-05-15 19:35:18 +00:00
dmiller
2f02fa2935 Fix build when building without OpenSSL (since r33781) 2015-01-01 21:09:02 +00:00
dmiller
2871ba3e6c New function, sslcert.parse_ssl_certificate
For reasons, the function is exported from nse_ssl_cert.cc into
nmap.socket, then included and documented in sslcert.lua because it fits
better there.
2014-11-05 05:55:52 +00:00
dmiller
3ecd0452d5 Fix a memory leak in NSE's bind function 2014-09-15 22:49:17 +00:00
d33tah
421176fc00 Get rid of double newline at the EOF I accidentally introduced in the
last commit.
2014-06-18 11:30:02 +00:00
d33tah
e3d1c178e3 Add newlines at the EOF in conformance to Daniel's coding standards
proposal. This only affects Nmap's root directory. We might also need to
modify the code which autogenerates Nmap's source code files such as IPv6
fingerprinting code.
2014-06-18 10:18:58 +00:00
dmiller
c9714990c7 Remove trailing whitespace from C/C++ files
https://secwiki.org/w/Nmap/Code_Standards
2014-02-12 20:25:51 +00:00
d33tah
4816358475 Replace all tab characters at the beginnings of lines with 8 spaces.
Mixed indentation annoyed my vim.
2014-01-05 19:14:26 +00:00
henri
694a8fe825 Nsock-pcap cleanup
Make the API follow the general nsock style. Report errors properly using the
nsock logging facilities.
2013-07-31 19:11:16 +00:00
henri
4685d44ff8 Removed a superfluous nsock_set_proxychain() statement.
This call got duplicated during the merge and provoked
non-fatal nsock errors like:

NSOCK ERROR [0.0310s] nsp_set_proxychain(): Invalid call. Existing proxychain on this nsock_pool
2013-04-30 07:12:03 +00:00
henri
1b45bfef14 Made NSE use proxychains too. 2013-04-22 19:35:42 +00:00
henri
18cf677548 Let NSE use nsock proxy chains. 2013-04-22 19:33:15 +00:00
henri
99258673ad Added handling of the new NSE_STATUS_PROXYERROR case. 2013-04-22 19:32:36 +00:00
david
40dc37e30b Comment typo. 2013-02-26 05:28:33 +00:00
henri
809f1eda68 Merged nsock-logging from nmap-exp/henri/nsock-logging/
Reworked the logging infrastructure to make it more flexible
and consistent.

Updated nmap, nping and ncat accordingly.  Nsock log level can
now be adjusted at runtime by pressing d/D in nmap.
2012-12-15 10:59:30 +00:00
david
26816736b5 Revert part of r29016.
nsock_check_udata needs this parameter indicating whether to set up an
unconnected UDP socket or not. r29016 wrongly made this setup
unconditional and moved the check for connectedness into the calling
function. What went wrong is that the unconnected UDP socket could be
set up prematurely--before calling bind, for example. This broke scripts
using unconnected UDP sockets.

This was reported by Dhiru Kholia.
http://seclists.org/nmap-dev/2012/q4/422
2012-12-15 07:55:31 +00:00
batrick
9754682420 Cancel the sleep event if the thread is destroyed by NSE. This
solves an assertion failure when the thread was garbage collected
by Lua before the sleep callback occurred.

Reported by Henri Doreau [1].

[1] http://seclists.org/nmap-dev/2012/q4/43
2012-11-23 03:47:43 +00:00