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

196 Commits

Author SHA1 Message Date
josh
881fc1777f Changed the default port for UDP probing. Also changed the ICMP id in ICMP
pinging to be a nonzero number.
2009-06-05 03:29:10 +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
josh
fe069f1420 Fixed a bug with the --defeat-rst-ratelimit option. 2009-05-28 23:36:45 +00:00
david
439e991985 When handling ICMP ping probe replies, make sure we match up with the
right type of probe (0 with 8, 14 with 13, 18 with 17). With the new
default ping, I was scanning a network where an echo reply would
mistakenly be interpreted as a response to a timestamp request, even
though that host didn't respond to timestamp requests. That host would
become the global ping host, and all its probes would be dropped,
slowing the scan way down. A ping scan of a /24 took over 1,000 seconds
when it should have taken about 10.
2009-05-27 22:08:24 +00:00
david
1538e21724 There is a new default ping probe set: -PE -PS443 -PA80 -PP. In
exhaustive testing of 90 different probes, this one emerged as the
best four-probe combination, finding 14% more Internet hosts than
the previous default, -PE -PA80. The default for nonroot users is
-PS80,443, replacing the previous default of -PS80. In addition,
ping probes are now sent in order of effectiveness (-PE first) so
that less likely probes may not have to be sent.
2009-05-27 18:21:28 +00:00
david
ea36c6c890 Require -d3, not just -d, for the message
Found whacked packet protocol 17 in get_ping_pcap_result
and rewrite it
	Received packet with protocol 17; ignoring.

The message is printed when we receive a packet we can't use during a
ping scan, but it's not "whacked" to receive a UDP packet during a TCP
scan for example.
2009-04-20 16:37:11 +00:00
fyodor
d0e21e1d03 Suggest that people send patches to nmap-dev rather than to me directly 2009-04-15 00:37:03 +00:00
david
7872aafa5d Update the global o.numhosts_scanning variable within ultra_scan, so
that it is set properly for ping scan. Previously status reports during
ping scan always looked like

Stats: 25:34:33 elapsed; 991232 hosts completed (72530 up), 0 undergoing Ping Scan

Note the "0 undergoing". Now that number will be set to 4096 or whatever
the current ping scan group size happens to be.
2009-03-31 18:29:52 +00:00
fyodor
eccc235d5a Increase copyright year to 2009, simplify/reword some derivative works text, and remove a confusing clause about selling proprietary front-ends to Nmap 2009-03-31 04:16:12 +00:00
david
77a304fb24 Eliminate a couple of (false) uninitialized variable warnings in
scan_engine.cc. Patch by Daniel Roethlisberger.
2009-02-13 16:14:20 +00:00
david
83cb7d60b9 Clean up usage of the goodseq variable for checking trynum and pingseq. Remove
it from places it's not used. Limit its scope to the places it is used. Patch
from Daniel Roethlisberger.
2009-02-09 18:29:57 +00:00
david
f99573f069 Fix an embarrassing error: In nmap-perf I had moved the bit of code that
increases the scan dealy with an increase in max_successful_tryno. When I
reverted a bunch of changes in r11651, I removed the moved code, leaving the
scan delay increase nowhere. This puts it back in ultrascan_port_probe_update
where it was before.
2009-01-08 23:44:08 +00:00
david
90ba6b97d0 Merge from /nmap-exp/david/nmap-perf. A summary of changes:
Don't make a host the global ping host until it moves to the completed
hosts list, and only change the global ping probe if the new probe is no
worse than the old (according to pingprobe_is_better).

Restore the ping magnifier for host congestion window updates.

Ignore the timing of certain ICMP errors that are likely to be rate
limited and don't change the port or host state. Avoid making timing
pings out of probes that elicit such errors. This used to be done only
for port scans and only at -T4 and above (and didn't prohibit the
creation of timing pings). Now it is done for host discovery too, and at
all timing levels.

Gracefully handle updates from the recent past in RateMeter. Doesn't
affect performance, but avoids a rare assertion failure.
2009-01-08 22:54:07 +00:00
david
8ede562551 Broaden the scope of a comment in scan_engine.cc: We don't adjust timing on
timeout of any non-ping probe, not just those with tryno == 0.
2009-01-07 23:57:40 +00:00
david
3ed62451bb Put the test for HOST_DOWN or HOST_UP once again after the test for
num_probes_active == 0 in HostScanStats::completed. The reason for this is
fairly subtle and I didn't realize it at first: We have to make sure there are
no active probes because once in the completed list, probes don't time out.
Probes that are active stay active in the count. If the congestion window ever
falls below the number of these active probes, the program will hang waiting
for them to time out.

We could get away with this in the case of up hosts, because we call
HostScanStats::destroyAllOutstandingProbes in that case. We could do that in
the down case too, but that would prohibit a down host from being found up
later on. That's currently a matter of some luck; we don't keep sending probes
after a host is down but will accept replies to any other probes that have
already been sent.
2009-01-04 16:45:17 +00:00
david
b3b06477c3 Pull out the stuff that ignored timing for ICMP destination unreachables if the
source address didn't match the target address. Fyodor correctly pointed out
that this is wrong for UDP scans, when we need to slow down for a firewall
sending unreachables to know which probes don't elicit one. I'm going to try
something a little different in nmap-perf.
2009-01-04 01:20:05 +00:00
david
d32794e2b6 Fix indentation in a line. 2009-01-03 23:35:30 +00:00
david
3b1f4fb755 Remove the unused HostScanStats::probes_outstanding_empty method. 2009-01-03 22:17:21 +00:00
david
da0b2c98c8 When a global ping times out, don't just destroy it, update timing too. Without
this, global pings never gave negative feedback, only positive feedback.
2009-01-03 22:15:06 +00:00
david
6998d72ccc Short-circuit HostScanStats::completed in host discovery: once we know the host
is up or down, we can move it to the completed list, regardless of any active
probes. However I can imagine changing this so that we move it when it is found
up, or when it is found down and there are no probes left to send. That would
give a down host a chance to become up with a different probe later on.
2009-01-03 22:04:43 +00:00
david
b0b0c0926a Just as during port scans, during host discovery don't adjust timing and don't
set a ping probe when an ICMP destination unreachable doesn't come directly
from the target.
2009-01-03 21:53:38 +00:00
david
76b7a7383f Use pingprobe.type != PS_NONE rather than pingprobe_state != PORT_UNKNOWN when
checking if a pingprobe has been set. We always use PORT_UNKNOWN during host
discovery (rather than HOST_UP or HOST_DOWN) to avoid conflicts with other
PORT_* constants. See the log for r8784.
2009-01-03 21:29:17 +00:00
david
e039a96715 Send global pings when num_probes_active == 0, not when
num_probes_outstanding() == 0. The active probes are probes that haven't timed
out; the outstanding probes includes those and some timed-out probes. When a
host makes it to the completed list with outstanding probes, it is unlikely
they will ever be removed, so we weren't sending any global pings in some
cases. A host only moves to the completed list with it has no active probes,
and any active probes it has after that are global pings.

Also remove only timed-out ping probes from the ping host. All other probes are
timed out but waiting for a response.
2009-01-03 20:43:37 +00:00
david
7b68aaa455 Restore the setting of the global ping host. This was mistakenly removed (by
me) in r8784 when I made the change to retain ping probes between ping scanning
and port scanning.

It only gets set during host discovery scans, because that's how it was before,
but it might be advantageous to set it during port scans as well.
2009-01-03 07:06:13 +00:00
david
d24ccae322 Don't adjust timing when we get an ICMP response that is not directly from the
target. In my testing, TCP scanning certain hosts, other hosts send back ICMP
destination unreachables (admin prohibited) for some ports (the Microsoft
ports). If that's the only response we got from a host, we would make it the
timing ping probe. But the admin-prohibiteds come back at some very slow rate,
much slower than the 1.25/s ping interval. So most of them are dropped, keeping
the congestion window perpetually at 1 and slowly increasing the scan delay. In
a -F scan these hosts could take over twice as long as any other host.

I also put in some missing adjust_timing arguments to the host and ping update
functions whenever adjust_timing could be false (the default is true). I think
those were just oversights. I also made it so that we don't select a new ping
probe when adjust_timing is false; there's no point sending ping probes whose
responses we're going to ignore.
2009-01-02 01:45:04 +00:00
david
3414659676 Give TCP probes that result in a filtered state a lower rank. When a TCP gets a
positive response that results in being marked filtered, the reply was an ICMP
error. Such probes are now ranked a 2 along with UDP, IP proto, and other
probes that get ICMP replies that are likely to be rate limited. Previously
they got the highest rank, 6, because they were TCP probes other than SYN to an
open port. SYN to an open port retains its rank of 3.
2008-12-30 23:45:28 +00:00
david
bc32baff98 Destroy connect scan probes that aren't otherwise handled (thereby closing the
socket). It's possible to get an EHOSTUNREACH or EHOSTDOWN (and possibly other
errors) against a nonexistent LAN host and formerly the socket wasn't closed.
This allowed Nmap's internal count of sockets to be less that the true count of
open sockets. It would eventually try to open too many sockets and quit with
the message

Socket creation in sendConnectScanProbe: Too many open files (24)

Be aware that in this message 24 is the errno, not the number of open files.
2008-12-26 22:26:17 +00:00
david
a246aaf469 Only increase max_successful_tryno when we have a positive response to a probe;
i.e., the probe didn't just time out. This was the case before r11253 when I
mistakenly removed it. I meant only to allow ultrascan_adjust_timing to be
called when rcvdtime == NULL, but as a side effect I also allowed
max_successful_tryno to increase in that case too. I was able to get that bit
of code to run with rcvdtime == NULL in a normal scan, but I don't think it
happens often.

I also improved the comments in that block of code.
2008-12-23 02:29:04 +00:00
david
e37bb72cd1 Remove the unused HOST_FIREWALLED and HOST_BROADCAST flags. The only flags used
are HOST_UNKNOWN, HOST_UP, and HOST_DOWN, and they're not "flags" as such
because they are mutually exclusive.
2008-12-04 17:20:07 +00:00
david
c561222685 Fix spelling in some identifiers. wierd_responses -> weird_responses,
printStatsIfNeccessary -> printStatsIfNecessary.
2008-12-04 17:04:48 +00:00
david
88143d667b Run probe send events through a HostScanStats::probeSent before passing them to
GroupScanStats::probeSent. This will allow updating timing variables for a
per-host rate limiter.

This fixes a bug, which was that decoy probes were not recorded by the scan
rate meter. Decoy scans would show a lower scan rate than the actual: with four
decoys the rate printed would be 1/5 of actual. This only affects printed
output, not the actual scan rate.
2008-12-04 00:12:25 +00:00
david
55482759d3 Move the code that handles --nogcc so it doesn't split up the code that handles
--min-rate and --max-rate. Doesn't affect functionality.
2008-12-03 22:16:19 +00:00
david
12a4288aa8 Don't increase the congestion window increment scaling factor until a probe is
replied to or times out. Previously the scaling factor was increased as soon a
s a probe was sent. So if you sent 10 probes right away at the beginning of the
scan, the first reply that came back would be scaled by 10 (= 10/1, and the
next by 9/2, etc.). Now if every probe is replied to then the scaling factor
will be exactly 1 throughout the scan.
2008-12-03 21:22:52 +00:00
david
85f6d12256 Standardize some terminology in scan_engine.cc: "quick start" -> "slow start,"
"congestion control" -> "congestion avoidance," "ccthresh" -> "ssthresh."
2008-12-03 18:55:49 +00:00
david
4ff30d9b99 Show a warning whenever raw socket sending is attempted on Windows--not just
when using --send-ip.
2008-11-24 17:52:25 +00:00
david
47c268568d Use the math function floor instead of casting to an int to truncate OS scan
match percentages. Casting to an int rounds (0.98 * 100) to 97 on some
architectures.
2008-11-20 17:03:11 +00:00
kris
98ee3211f2 Fixing port numbers in output. The "%hi" conversion modifier was being used
which treats port numbers as signed shorts, and this caused high ports numbers
to wrap around and be shown as negative.
2008-10-24 00:48:19 +00:00
david
5a34d64f8e Fix a test condition in the ICMP response checking code for ping scans. A test
that should have fired whenever !USI->ptech.rawprotoscan wrongly had the
additional condition && o.debugging, meaning that it worked properly only when
debugging was enabled. See http://seclists.org/nmap-dev/2008/q4/0130.html and
http://seclists.org/nmap-dev/2008/q4/0206.html for problem reports.
2008-10-20 16:52:42 +00:00
kris
74e98e3beb o Reduced memory consumption for some longer running scans by removing
completed hosts from the lists after two minutes.  These hosts are
  kept around in case there is a late response, but this draws the
  line on how long we wait and hence keep this information in memory.
  See http://seclists.org/nmap-dev/2008/q3/0902.html for more.
2008-09-24 19:37:06 +00:00
david
f776c9c9a5 Use TIMEVAL_AFTER(...) instead of TIMEVAL_SUBTRACT(...) > 0 when deciding
whether a probe response counts as a drop for scan delay purposes. This avoids
an integer overflow in TIMEVAL_SUBTRACT that caused all responses to probes
retransmitted from the retry stack to be counted as drops. This would cause the
scan to grind to a near-halt, with the scan delay at 1000 ms, if even a few
hundred probes were retransmitted from the bench.

    Increased max_successful_tryno for 192.168.0.190 to 1 (packet drop)
    Increased max_successful_tryno for 192.168.0.190 to 2 (packet drop)
    Increasing send delay for 192.168.0.190 from 0 to 5 due to 216 out of 718 dropped probes since last increase.
    Increased max_successful_tryno for 192.168.0.190 to 3 (packet drop)
    Increasing send delay for 192.168.0.190 from 5 to 10 due to 92 out of 305 dropped probes since last increase.
    Increasing send delay for 192.168.0.190 from 10 to 20 due to 11 out of 11 dropped probes since last increase.
    Increasing send delay for 192.168.0.190 from 20 to 40 due to 11 out of 11 dropped probes since last increase.
    Increasing send delay for 192.168.0.190 from 40 to 80 due to 11 out of 11 dropped probes since last increase.
    Increasing send delay for 192.168.0.190 from 80 to 160 due to 11 out of 11 dropped probes since last increase.
    Increasing send delay for 192.168.0.190 from 160 to 320 due to 11 out of 11 dropped probes since last increase.
    ...

The problem was in this bit of code:

  if ((!rcvdtime && TIMEVAL_SUBTRACT(probe->sent, hss->sdn.last_boost) > 0) ||
      (probe->tryno > 0 && TIMEVAL_SUBTRACT(probe->prevSent, hss->sdn.last_boost) > 0)) {

the TIMEVAL_SUBTRACT(probe->prevSent, hss->sdn.last_boost) > 0) to be specific.
When a probe is retransmitted, the time it was sent is recorded in the prevSent
member of the retransmit probe. prevSent is properly set in retransmitProbe,
but it is not set in sendNextRetryStackProbe, which sends probes that have been
moved from the bench to the retry stack. The problem is that when probes are
moved to the bench they are compressed to probespecs and lose most of their
auxiliary information, like the send time. When they are retransmitted as real
UltraProbe objects, their prevSent message is left initialized to { 0, 0 }.
That led to the integer overflow, with TIMEVAL_SUBTRACT returning a nonsense
(but positive) value.

I fixed it by using TIMEVAL_AFTER(...), which works like
TIMEVAL_SUBTRACT(...) > 0 except that it is immune to integer overflows. Every
other timeval is after { 0, 0 }, so the condition is false for probes
retransmitted from the bench, as it should be. However this is not the most
correct solution. Better would be to somehow store each probe's send time with
it on the bench so it could be restored when it is retransmitted. The way the
bench and the retry stack work makes that cumbersome though, and this is the
only place prevSent is used, so I think this solution is acceptable.
2008-09-19 16:25:10 +00:00
david
da19b9a23d Fix an assertion failure where raw TCP timing ping probes were wrongly used
during a TCP connect scan:
nmap: scan_engine.cc:2843: UltraProbe* sendIPScanProbe(UltraScanInfo*, HostScanStats*, const probespec*, u8, u8): Assertion `USI->scantype != CONNECT_SCAN' failed.
2008-09-08 15:53:32 +00:00
david
e0435b8b98 Go back to the old method of calculating the completion percentage. My clever
formula algebraically reduced to
1.0 - gstats->numprobes / host->freshPortsLeft(), which doesn't regard the
number of sent probes, leading to long stalls in the completion when, for
example, maxtries is increased.
2008-08-19 17:01:44 +00:00
david
e401cb4a00 Reuse a cached copy of the result of freshPortsLeft() instead of calculating it
again.
2008-08-16 01:45:14 +00:00
david
371a19f79a Make a tiny whitespace fix. 2008-08-16 01:12:36 +00:00
david
debfc5f683 Change RateMeter to be more general, measuring just one quantity. Add a
PacketRateMeter specialized for measuring packet and byte rates, and use that
in scan_engine.cc.
2008-08-16 01:05:11 +00:00
david
116ba8fb91 Change the completion percentage algorithm to estimate the total number of
probes that will be sent and calculate from that. This makes the 100%
completion match up closely with the end of the scan, as the estimate gets
better as the scan gets closer to finishing. It also works against filtered
hosts. There is still the related problem that the completion time estimate
uses a global average to estimate completion rate, so it tends to
underestimate.
2008-08-15 05:59:05 +00:00
david
e6d4512f4d Revert to the previous method of calculating completion percentage. Just
counting the ratio of finished to total ports fails against filtered ports,
which are not marked completed until the very end.
2008-08-14 15:35:29 +00:00
david
47aa010d2e Factor out the code that calculates the completion percentage into its own
subroutine. It was present in two places.
2008-08-14 14:19:39 +00:00
david
8e6576f00e Use only the number of completed ports when computing completion time
estimates, and don't consider the number of outstanding probes or number of
retries. The old code would overestimate completion, causing a period of 99.99%
completion at the end of a scan (which caused earlier estimates to be too
soon). For a long UDP scan this puts the completion estimate right on after a
little time to allow for convergence. See
http://www.bamsoftware.com/wiki/Nmap/CompletionTimeEstimates.
2008-08-14 07:00:24 +00:00
david
227adcd664 Remove the code that catches up the --max-rate scheduled send time to
the present. This allows the sending rate to temporarily exceed the
maximum to keep from being slowed too much by other delays in the scan
engine. See the discussion at http://seclists.org/nmap-dev/2008/q3/0236.html.
2008-08-11 16:26:17 +00:00