Nmap Development mailing list archives

Re: [PATCH]in big-endian platform, nmap failed to resolve the service name


From: David Fifield <david () bamsoftware com>
Date: Mon, 24 Sep 2012 22:11:18 -0700

On Tue, Sep 25, 2012 at 12:01:58PM +0800, hejianet wrote:


in bigendian platform, nmap failed to get the mapping relationship because 
all protocols are stored in protocol_table[0].

[root@host nmap-6.01]# ./nmap -sO localhost

Starting Nmap 6.01 ( http://nmap.org ) at 2012-09-24 20:41 CDT
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000016s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 249 closed protocols
PROTOCOL STATE         SERVICE
1        open          unknown
2        open|filtered unknown
6        open          unknown
17       open          unknown
103      open|filtered unknown
136      open|filtered unknown
255      open|filtered unknown

Nmap done: 1 IP address (1 host up) scanned in 1.60 seconds
[root@host nmap-6.01]# uname -m
ppc64

Signed-off-by: Jia<hejianet () linux vnet ibm com>
Tested-by: Jia<hejianet () linux vnet ibm com> 
--- nmap-6.01/protocols.cc.ori        2012-09-24 20:42:45.019985471 -0500
+++ nmap-6.01/protocols.cc    2012-09-24 20:44:01.130938317 -0500
@@ -145,7 +145,7 @@ static int nmap_protocols_init() {
     protno = htons(protno);
 
     /* Now we make sure our protocols don't have duplicates */
-    for(current = protocol_table[0], previous = NULL;
+    for(current = protocol_table[protno%PROTOCOL_TABLE_SIZE], previous = NULL;
      current; current = current->next) {
       if (protno == current->protoent->p_proto) {
      if (o.debugging) {
@@ -164,7 +164,7 @@ static int nmap_protocols_init() {
     current->protoent = (struct protoent *) cp_alloc(sizeof(struct protoent));
     current->next = NULL;
     if (previous == NULL) {
-      protocol_table[protno] = current;
+      protocol_table[protno%PROTOCOL_TABLE_SIZE] = current;
     } else {
       previous->next = current;
     }

test results:
PROTOCOL STATE         SERVICE
1        open          icmp
2        open|filtered igmp
6        open          tcp
17       open          udp
103      open|filtered pim
136      open|filtered udplite
255      open|filtered unknown

Thank you for finding this. I looked into the problem and decided that
there was more wrong than just the hard-coded insertion into bucket 0.
The bigger problem was the call
        protno = htons(protno);
which mapped byte values into integers like 0x0100, 0x0200, 0x0300, ....
This caused all protocols to end up in bucket 0, even with your fix. I
committed a more extensive revision in r29859.

David Fifield
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: