DEV Community

Chris
Chris

Posted on

Analyzing NMAP scans for fun (Part 1)

CAVEAT: This post is a few years old, its been sitting in my draft folder since 2021.

Introduction

In this post, I'm going to describe a tool that I created which can be used to analyse and react to TCP data sent by NMAP scan probes. The analysis of NMAP scan probes can be used to answer questions like "What does an NMAP scan look like on the TCP stack?" or "How can I identify NMAP scans on my network?". Also let me add that this is not "new" research, analysing NMAP and its probes has been done many times before. I'm a fan of reinventing the wheel for my own amusement which generally helps me understand things better and of course, it's been a while since I've seen any new NMAP deep-dives. Enjoy :)

The analysis of the NMAP probes can be used as a detection canary that can be used by blue-teamers to identify if an actor is running NMAP scans on their network infrastructure. Additionally, the analysis of NMAP probes can be used by red-teamers to understand how their tools behave and "look on the wire".

Okay that was a lot for an introduction so let's break the tool down and see what it does.

TCP Socket Handling

First and foremost, this tool is essentially a multi-threaded TCP socket server. This functionality is used by the tool so that NMAP scans can be directed at the tool and the operator of the tool can observe the behaviour of the TCP socket connections made by NMAP. NMAP makes use of threads so by making the tool able to handle multiple connections concurrently. This is super useful because you can process all the connection probes made by NMAP. Let's go ahead and run the tool and scan it with some NMAP defaults.

NOTE: I am running all of this in Docker and the tool is configured via Environmental variables.

In one Docker container, build and run the tool to listen on port 80 and set TERM=nmap. "TERM" is the search term(string) we tell the tool to look for in the TCP data received:

root@78b5ecfeb870:/work# export PORT=80
root@78b5ecfeb870:/work# export TERM=nmap
root@78b5ecfeb870:/work# go build -o garbanzo && ./garbanzo 
2020/06/10 12:02:40 $GARBANZO_WEB must be set
2020/06/10 12:02:40 $GARBANZO_HOST must be set
2020/06/10 12:02:40 [+] Initialised Listener on Port: 80
Enter fullscreen mode Exit fullscreen mode

And in another Docker container, we launch an NMAP scan against the server container which has the IP address 172.17.0.2. We are using the "-sT" flag because we are in a non-privileged container and do not have the required Linux Capabilities to create raw sockets [1].

root@f5f84eb31bc0:# nmap -sT 172.17.0.2
Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-02 UTC
Nmap scan report for 172.17.0.2
Host is up (0.00014s latency).
Not shown: 999 closed ports
PORT   STATE SERVICE
80/tcp open  http
Enter fullscreen mode Exit fullscreen mode

and after the scan is done, we can see that NMAP detected port 80 to be open, which is correct.

Our server output will look like this:

root@78b5ecfeb870:/work# export PORT=80
root@78b5ecfeb870:/work# export TERM=nmap
root@78b5ecfeb870:/work# go build -o garbanzo && ./garbanzo 
2020/01/01 12:12:12 $GARBANZO_WEB must be set
2020/01/01 12:12:12 $GARBANZO_HOST must be set
2020/01/01 12:12:12 [+] Initialised Listener on Port: 80
2020/01/01 12:12:12 [+] [d5eff754572a65e648960245a43eba98beb0ce714c4d7dd95d7278a7063acbfb] Port:80 Connection:1 from:172.17.0.3:49106
2020/01/01 12:12:12 [ERROR] [d5eff754572a65e648960245a43eba98beb0ce714c4d7dd95d7278a7063acbfb] read tcp4 172.17.0.2:80->172.17.0.3:49106: read: connection reset by peer
Enter fullscreen mode Exit fullscreen mode

The output above from the tool indicates that a single TCP connections was made to port 80 and error occurred when the server attempted to read data from the stream. The error is expected because NMAP by default will reset the connect if it can make a connection. This is all the info NMAP needs to determine if a port is open, if it can successfully open a connection, then it must be open. In the output above, there is a SHA256 hash "d5eff754572a65e648960245a43eba98beb0ce714c4d7dd95d7278a7063acbfb" which is a unique identifier for the connection. This is useful for when there are multiple connections. The tool uses this hash with all activities associated to a connection. We'll see more of this in the section.

NMAP Service and Version Detection

Let's now use the "-sV" flag with our NMAP command as we want NMAP to try and extract "metadata" or the service and version of the open ports. This is useful from an attackers perspective because we want to gather as much information as possible on our target. We can try this by running the following command from our NMAP container:

root@f5f84eb31bc0:/go# nmap -sT -sV 172.17.0.2 -p 80    
Starting Nmap 7.70 ( https://nmap.org ) at 2020-02-02  UTC
Nmap scan report for 172.17.0.2
Host is up (0.00014s latency).
Enter fullscreen mode Exit fullscreen mode

And below is the corresponding output generated by the tool:

[+] Initialised Listener on Port: 80
[+] [2b24f34f93697ce707cd9d61323b70a2b54457c3dd330f7d5e5d7bd4ebbb8f66] Port:80 Connection:1 from:172.17.0.3:51198
[ERROR] [2b24f34f93697ce707cd9d61323b70a2b54457c3dd330f7d5e5d7bd4ebbb8f66] read tcp4 172.17.0.2:80->172.17.0.3:51198: read: connection reset by peer
[+] [8297b9be5c9314c96c57af36e56dd5b14cf32884a16227906199ca8ddf8ee431] Port:80 Connection:2 from:172.17.0.3:51200
[+] [02210c50dac4565cb66cb1623623b9e4efe9d5638e666160e25769458679ee6d] Port:80 Connection:3 from:172.17.0.3:51202
[+] [14746282e65da35beba19df6fa78bde2419b8a16e072a1a95ad8bc807f5f9716] Port:80 Connection:4 from:172.17.0.3:51204
[+] [74264732650f84c3084ed23f15be3aa6290e3faf1289ce276bd20b0c3a168cf5] Port:80 Connection:5 from:172.17.0.3:51206
[+] [2cb82e31bbb4b06ad2c3ccb234e07a8aec8c5c75e046af3096740260842e4bac] Port:80 Connection:6 from:172.17.0.3:51208
[+] [51be251174fd9ee7424ba7a27bf512c2f2097f285dd46ca212240ae4209587d9] Port:80 Connection:7 from:172.17.0.3:51210
[+] [9e5be1a5dce881f7ba3ef51d5a66b2f17f2fb7014b0324d14ff8e273248a044c] Port:80 Connection:8 from:172.17.0.3:51212
[+] [31f2d6fb2c6b769be4948a987deb4a62d2f67392c86d6faa7d1e4bd02c174254] Port:80 Connection:9 from:172.17.0.3:51214
[+] [6dd8b57b9bd35fea1490b872c6c729d9bc882e3af29f1b24993749921eb5e0fd] Port:80 Connection:10 from:172.17.0.3:51216
[+] [d1fc77dbec734b6958203c3102bf98c2562539e9825216e200b3bdce0211e3f2] Port:80 Connection:11 from:172.17.0.3:51218
[+] [635da8a96fe12207e71977854eb49e95fa315a3ec712da9e79bda4aa03338273] Port:80 Connection:12 from:172.17.0.3:51220
[+] [ed6270327f3ef77886ea3e4cb6c07866d0750154f38ad1f21f2ffce7ddef70b7] Port:80 Connection:13 from:172.17.0.3:51222
[+] [4099a9996900ca19503a60b0434ce295ebb7400ad7f84002f16be2a47dacbb68] Port:80 Connection:14 from:172.17.0.3:51224
[+] [1dab93852e0749e263bb9c5deca00fed53fe8a5001b719d116016ed7d1d43e81] Port:80 Connection:15 from:172.17.0.3:51226
[+] [f2354e58c621369521f4de50a0b7d430b3bc79f395ea237ac5ca2f979e638353] Port:80 Connection:16 from:172.17.0.3:51228
[+] [f442e24b6110226e818d96c399b8cb56c8936381df4126ba80101f4c8ac6a1cd] Port:80 Connection:17 from:172.17.0.3:51230
[+] [0bd2ae1db2c1c1544af266eeba31f7ed6ee24ad7582f24a6c9a50735dd9747e2] Port:80 Connection:18 from:172.17.0.3:51232
[+] [628883d43eec1ce919a06b7dc39ed8962918f14342d2f389fda82e3bac6e1888] Port:80 Connection:19 from:172.17.0.3:51234
[+] [18d9fb07f6254ff16a27159a0c8f4d6d4d729de94a0f1361a10347c6265729fd] Port:80 Connection:20 from:172.17.0.3:51236
[+] [5f5660a93b7802af41fc135f0bb1e4cd4cec0f19d9875ba194aeb3518423ff9c] Port:80 Connection:21 from:172.17.0.3:51238
[+] [0f2d4808a0826f65efcb2491efe957835a5b18853dae03cc5e8d1957919b6cf8] Port:80 Connection:22 from:172.17.0.3:51240
[+] [39c77dc5d34efd2871b8315a5e0778e31ff4a124a4bcd91345047ce666375f43] Port:80 Connection:23 from:172.17.0.3:51242
[+] [b041e718af47ea6c851c9a5cbaf50290a47099c327b3ffcbfaedffc970ff73d5] Port:80 Connection:24 from:172.17.0.3:51244
[+] [346cbcbc95c1ae7f2fc82acb85d6e8a51ab44a7c894929843d8740ba6feebc2a] Port:80 Connection:25 from:172.17.0.3:51246
[+] [6128ee2cbdb3618ed21e147e8874fc7a534e0f1da4c8286de7d0012646cadebb] Port:80 Connection:26 from:172.17.0.3:51248
[+] [098a8bee69382aabb4acd7130e7c66791666e5fa189902ef17f1cd44cf223b1b] Port:80 Connection:27 from:172.17.0.3:51250
[+] [eeb53a2542d3ea71f725353cf8b1d064ab11e8667eb29e023124b6103aa097ae] Port:80 Connection:28 from:172.17.0.3:51252
[+] [875091a5aabf395a62db73a49c0f844d6f4cde28cdc0bf27b0346f6de4be299b] Port:80 Connection:29 from:172.17.0.3:51254
[+] [effa187e4a8757b2356bc23fdac4c28b2fc9b3dd6983538d3b9c3fd7c30bb764] Port:80 Connection:30 from:172.17.0.3:51256
[+] [0600560cc19cdf6185663d128ebaee3550cdf4a17ceb5a89c68500d9593a6d46] Port:80 Connection:31 from:172.17.0.3:51258
[+] [2e3fe6ada0d67914119272dcf6f9b7367b841b2773c8999a341b09120cd6cfd9] Port:80 Connection:32 from:172.17.0.3:51260
[+] [8a7ced242e7d833644403eec43543f0b2250af048b594e1dd96c12ac148b4f1d] Port:80 Connection:33 from:172.17.0.3:51262
[+] [8a7ced242e7d833644403eec43543f0b2250af048b594e1dd96c12ac148b4f1d] nmap Probe:1 from connection: 33 :[GET /nmaplowercheck1591880218 HTTP/1.1
][474554202f6e6d61706c6f776572636865636b3135393138383032313820485454502f312e310d0a]
[+] [d30f053fbd9b19ddf4ceb2fc4a43f900584ad7f58130ebb7c16f634701ab00ef] Port:80 Connection:34 from:172.17.0.3:51264
[+] [b4ac67dec3cc4c117e69057b5edc7e71350c0d2ccba6c8369159a589ccaf1285] Port:80 Connection:35 from:172.17.0.3:51266
[+] [b4ac67dec3cc4c117e69057b5edc7e71350c0d2ccba6c8369159a589ccaf1285] nmap Probe:2 from connection: 35 :[GET /nmaplowercheck1591880218 HTTP/1.1
][474554202f6e6d61706c6f776572636865636b3135393138383032313820485454502f312e310d0a]
[+] [5db9eee927b2f08180debcbc69e626fd31cbbd2b78d038fc9077e47c5eeb556e] Port:80 Connection:36 from:172.17.0.3:51268
[+] [cf407790610951aa8966c88322aa0a3e7d46f4ace9cc89e8427acdf5bfbcdf0d] Port:80 Connection:37 from:172.17.0.3:784
Enter fullscreen mode Exit fullscreen mode

Woah okay that's a lot of output, lets break it down and see what it says. Firstly, we can see that NMAP made a total of 37 connections to the tool

...Port:80 Connection:37...

. We can also see that the tool identified probes that contained our search "term" which we set to "nmap". Remember, this term basically tells the tool to search for that character sequence (case insensitive btw) in any data sent from the client (NMAP). Here's the first probe that the tool detected:

...
[+] [8a7ced242e7d833644403eec43543f0b2250af048b594e1dd96c12ac148b4f1d] Port:80 Connection:33 from:172.17.0.3:51262
[+] [8a7ced242e7d833644403eec43543f0b2250af048b594e1dd96c12ac148b4f1d] nmap Probe:1 from connection: 33 :[GET /nmaplowercheck1591880218 HTTP/1.1][474554202f6e6d61706c6f776572636865636b3135393138383032313820485454502f312e310d0a]
[+] [d30f053fbd9b19ddf4ceb2fc4a43f900584ad7f58130ebb7c16f634701ab00ef] Port:80 Connection:34 from:172.17.0.3:51264
...
Enter fullscreen mode Exit fullscreen mode

From the output above, we can see that it was connection 33 that sent the request that contained an HTTP request that contained the term "nmap". Okay that's interesting, we now know that behaves differently with the -sV flag in terms of the amount of TCP connections made and the data sent from NMAP. We can also see that NMAP continues the behaviour of "connecting" and "resetting" the connection first to determine if the port is opened, this can be seen with the following output specifically:

[+] Initialised Listener on Port: 80
[+] [2b24f34f93697ce707cd9d61323b70a2b54457c3dd330f7d5e5d7bd4ebbb8f66] Port:80 Connection:1 from:172.17.0.3:51198
[ERROR] [2b24f34f93697ce707cd9d61323b70a2b54457c3dd330f7d5e5d7bd4ebbb8f66] read tcp4 172.17.0.2:80->172.17.0.3:51198: read: connection reset by peer
[+] [8297b9be5c9314c96c57af36e56dd5b14cf32884a16227906199ca8ddf8ee431] Port:80 Connection:2 from:172.17.0.3:51200
Enter fullscreen mode Exit fullscreen mode

Below is the NMAP out from the scan we just analysed:

nmap -sT -sV 172.17.0.2 -p 80
Starting Nmap 7.70 ( https://nmap.org ) at 2020 UTC
Nmap scan report for 172.17.0.2
Host is up (0.000099s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port80-TCP:V=7.70%I=7%D=6/11%Time=5EE229CA%P=x86_64-pc-linux-gnu%r(GetR
SF:equest,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x0e4\xc86\xab\xd1\x0
SF:e\x8b&\xd1\xfa\xbaX\xc1\x91\x20\xcb\x0f8\xc4Q\x89\xf2!\xe8V\|wj\xeb\xc3
SF:zk#`\x01A{\?\xd7\x89\x15\x07\x8d\xb2o\xeb\(\x13G\xb7#\x95\x15~\xa9\x9d\
SF:x8d\xcf\]\xbc\xbbg\x1c\xeeC\xc1\x11Y\x01\xef\xc9\xb7\xa0>:`\xd9\0\x85\x
SF:c5Zv\xc8Qa`\xc7\x93\x0f\xd7\x0b\\\xe7\x14rD\x87\x92{~\xbc\xfd\xa5\x06Z\
SF:xe1\xc4wi\xf7\xe3:\x9ep\xb8\xea\x05>\xc6p\[\x7f,\xa1\x8e\xd1\xed\xf5\xa
SF:6x\xa80\xa6\x058U\xc8\x8f\xbd{\xc3\x9dk\x04\xc61\xdb>r\\\x80\xe8K\xa6l\
SF:x9a}\xd2F\x1a\xde\xfaZ\xaa\x91\|\x1b\x1b\x8d!\xfe\x125\0\]\xb2\xde\x88G
SF:\xd1\xe9\x0f\xbf\"\xc1\"a\x02\xeb\xd4V\(L:\xe8\x87\xcb\x9f\xbf\xfb\xfc\
SF:xc6c\xe4Nz\x0eb\x94\xd5\x8b\x12\x9d\x10\xf9\x94k9@y\x82\x8a\x02\xbe\x03
SF:\xf5hs@q\xd9n\xf8\xb3\xb0\x15~\xb3\xb7\x0b\xa5\xdfGU@\xdeJ\x80\x94p\xe2
SF:\x08\xd7\xe6!\xf8\xcd\xdf\xc0s\xe4\xff");
MAC Address: 02:42:AC:11:00:02 (Unknown)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 87.86 seconds
Enter fullscreen mode Exit fullscreen mode

The above output shows us that NMAP was able to detect that port 80 was indeed open but could not verify the service and version, which makes sense and we'll dig into why a bit later in this post.

NMAP Service and Version Detection and Scan Intensity

NMAP has useful functionality to adjust how "intensely" it scans the target according to its documentation[2]. If we look at the flag "--version-intensity" which we haven't used directly yet, we can see in the docs[2] that the flag "-sV" sets "--version-intensity" to 7 by default. Lets now go ahead and change ""--version-intensity" and observe how NMAP behaves:

First setup our tool

root@78b5ecfeb870:/work# export PORT=80
root@78b5ecfeb870:/work# export TERM=nmap
root@78b5ecfeb870:/work# go build -o garbanzo && ./garbanzo 
2020/06/10 12:02:40 $GARBANZO_WEB must be set
2020/06/10 12:02:40 $GARBANZO_HOST must be set
2020/06/10 12:02:40 [+] Initialised Listener on Port: 80
Enter fullscreen mode Exit fullscreen mode

Execute NMAP:

root@f5f84eb31bc0:/go# nmap -sT -sV 172.17.0.2 -p 80 --version-intensity 1
Enter fullscreen mode Exit fullscreen mode

Below we get the following tool output from the NMAP command above:

[+] [e76bfa77f3047f2162bf0ca697d24cd38be99ecf96960ca5f324c33801babcd3] Port:80 Connection:1 from:172.17.0.3:51270
[ERROR] [e76bfa77f3047f2162bf0ca697d24cd38be99ecf96960ca5f324c33801babcd3] read tcp4 172.17.0.2:80->172.17.0.3:51270: read: connection reset by peer
[+] [ca32700fb09ad58490ab340fd19d5bfd17a77f5a4b39357341e93ec0ee868721] Port:80 Connection:2 from:172.17.0.3:51272
[+] [6b991cc7ea35a78d63af16555c5b404b78a74c62eede3acaed6f5cda6a650e66] Port:80 Connection:3 from:172.17.0.3:51274
[+] [343b98c09fefc41ecb2e0eb48c918ed8f5b1d0af02dc05b781abb5a4d57e7e7a] Port:80 Connection:4 from:172.17.0.3:51276
[+] [61c11e4bfa44083c4ac764fbbe1546e4a70d38434b4d39fd287cbc26bd1631dd] Port:80 Connection:5 from:172.17.0.3:51278
[+] [0958fca1885269f9797a039aedcbccc67d5153f71f5396ffee23dc707d714a8c] Port:80 Connection:6 from:172.17.0.3:51280
[+] [322a686505032b68a7903a68b98ec502f87710d7ed60cd71bc5d6708fe214af0] Port:80 Connection:7 from:172.17.0.3:51282
[+] [610f9f80d0b616267fb567fbe5b437653fd3d3ac3d524ca92baac642d599e102] Port:80 Connection:8 from:172.17.0.3:51284
[+] [12f40d18ad44fee3eef5371c571883efcac00b7576dcee35ebb8fd12af37571f] Port:80 Connection:9 from:172.17.0.3:51286
Enter fullscreen mode Exit fullscreen mode

The above output from the tool shows us that NMAP continues the behaviour of checking if port 80 is open by connecting and resetting. We can also see that 9 connections were made but no "nmap" terms were identified. If we run the NMAP command several times with "--version-intensity" set to "1", we will see the above pattern repeated, first a connection and reset which is then followed by 8 probes.

Below is the associate NMAP output:

root@f5f84eb31bc0:/go# nmap -sT -sV 172.17.0.2 -p 80 --version-intensity 1
Starting Nmap 7.70 ( https://nmap.org ) at 2020-002-02 UTC
Nmap scan report for 172.17.0.2
Host is up (0.000083s latency).

PORT   STATE SERVICE VERSION
80/tcp open  http?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port80-TCP:V=7.70%I=1%D=6/11%Time=5EE23E9F%P=x86_64-pc-linux-gnu%r(GetR
SF:equest,270,"\xb5rHF\xbc\xe9\xde\xf9\xbc\xf6\x15Y\x8e\xb9\x1f\x9a\0\xe64
SF:xrB\xb4\x9a\xcd#S:W\x01\|K\x8e\x1ft\x95\x90\n\xaf\xaf\x004k\xf9\xc1\x99
SF:\xf7\x88s\xef\x8e\x13\x03\xf1Gp-\x99\xe4\xd6\xf2e\x94\xb2Z\r\x94C\x07EY
SF:\?>\\8D\xear\xa0y\xae\xf3\x86\xda\xab<\xe2\xc6C\xa9\xf1IMw\x0b-\xb6\xce
SF:\x0b\x9b\xe6\x15S\xdd\xe2\$\.\x9e\xe4\x8f\x965\xf1\x11\xee`\xe2\x04\x95
SF:\x1b\xc0\xe5-\xceM\xe9\x97\xbcd\xea\xc2\xed\n\x03\tU\x97\x01\xbe\xaf\x0
SF:2\xce-SH\xfaZ\xdeV\xc7#\xd9W\xf0X~1-Es\xb4\xf6\xe2\xcf\x07\xa5\*m\xe5i\
SF:^\x88\x03d\xf7\xe1\x05\x12\x90\rN\x84\x17\xed\]\x1a\xf0n\xbc\xeb\xe9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4\xe0\x0b\xdb\xdeV\xa0\x8d\xfb\xf9\)\xbd\xac{\xd2\+
SF:\xb1\x075s\xdc_\x0e\xc5\xe3ZJ\xc1Z\xc7\xe8\xa2>}\xbe\"\xac\xab\x04\xcc\
SF:xac\xab\x92F\x99w\xfb\xc7t\xcc\xedHp\xee\xa3\x9a-\xa7\xd4\x1c\xba\x87d\
SF:xb9\x83R\xbb\x04\x84m{CS\x8b\xa0\"w\xb7\xd3\+g\x18\x20\x93x\x93\xeaOs\x
SF:ff");
MAC Address: 02:42:AC:11:00:02 (Unknown)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 11.83 seconds
Enter fullscreen mode Exit fullscreen mode

From the output above, we can see that NMAP was able to determine that port 80 was open but could not verify the service and version.

If we take a look at what we have determined at this point, we now know that the -sV defaults will send probes that contain the string "nmap" and "--version-intensity" set to 1 will result in no probes containing the string "nmap". So this leads to a natural question, at which intensity level does the string "nmap" get sent with the NMAP probes? Well easy-peasy-lemon-squeezy, lets use our tool to help us. Lets setup our server again with:

root@78b5ecfeb870:/work# export PORT=80
root@78b5ecfeb870:/work# export TERM=nmap
root@78b5ecfeb870:/work# go build -o garbanzo && ./garbanzo 
2020/06/10 12:02:40 $GARBANZO_WEB must be set
2020/06/10 12:02:40 $GARBANZO_HOST must be set
2020/06/10 12:02:40 [+] Initialised Listener on Port: 80
Enter fullscreen mode Exit fullscreen mode

and run NMAP with "--version-intensity" set to 2.

root@f5f84eb31bc0:/go# nmap -sT -sV 172.17.0.2 -p 80 --version-intensity 2
Enter fullscreen mode Exit fullscreen mode

which results in the following tool output:

[+] Initialised Listener on Port: 80
[+] [cb2cfd7735d96677652e77940170a0a4c695b4145fa93f7c885628df551671d7] Port:80 Connection:1 from:172.17.0.3:51288
[ERROR] [cb2cfd7735d96677652e77940170a0a4c695b4145fa93f7c885628df551671d7] read tcp4 172.17.0.2:80->172.17.0.3:51288: read: connection reset by peer
[+] [50982846ac83afffab217e22573baae530ad966028d29b4c0f1d77c71c8dce16] Port:80 Connection:2 from:172.17.0.3:51290
[+] [6d95e9d08c551bda3d97565334aa089396600c62b9b4fae5847156ef596a6d5e] Port:80 Connection:3 from:172.17.0.3:51292
[+] [71fbba3e7c6949cfed8bb15ab2708a34cc20cbe5d4d5c60ca6d139ef0a3e3a4b] Port:80 Connection:4 from:172.17.0.3:51294
[+] [c774af05a3d1e12d779d86d8a23eb6daac54a3ebed1d4af18d68378ad47bc6af] Port:80 Connection:5 from:172.17.0.3:51296
[+] [dcd29b657bd7399ada9d76144cef8fc56615d356dcee1e448ea9dd675c8d5af3] Port:80 Connection:6 from:172.17.0.3:51298
[+] [be510f1d5fdb54ee007f0bf7613e9df76a8d9e17cb106a999f6c78c5865e7967] Port:80 Connection:7 from:172.17.0.3:51300
[+] [9ffc5a4a8c704547d2f7d9d995d8c55d4ad807d01124642fff9500bb7615c091] Port:80 Connection:8 from:172.17.0.3:51302
[+] [460ec7db181855235ef0f78e2f99f0779af42fcf083ccd42e23e05dd6b2d8d2a] Port:80 Connection:9 from:172.17.0.3:51304
Enter fullscreen mode Exit fullscreen mode

Okay so intensity level 2 has no "nmap" term in the probes. If we repeat this process(left to the reader to do) and increase the intensity +1, we'll determine that level 7 is the level where NMAP sends the term "nmap" in its probes. Another interesting observation is that the number of connections made by NMAP also increases with the intensity level. For example, the follow NMAP command:

bash nmap -sT -sV 172.17.0.2 -p 80 --version-intensity 6

results in 24 connections made by NMAP. I'll leave it to you, the reader to verify this statement :)

References

1.https://nmap.org/book/scan-methods-connect-scan.html
2.https://nmap.org/book/man-version-detection.html

Top comments (0)