Monkey.org Developments
Honeyd Discussion Forums :: View topic - honeyd and nmap - the solution?

Support Honeyd

Search:
Keywords:

Search Amazon
Honeyd Discussion Forums
Everything relating to Honeyd
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

honeyd and nmap - the solution?

 
Post new topic   Reply to topic    Honeyd Discussion Forums Forum Index -> General
View previous topic :: View next topic  
Author Message
jons



Joined: 03 Feb 2007
Posts: 32

PostPosted: Tue Jul 10, 2007 6:53 pm    Post subject: honeyd and nmap - the solution? Reply with quote

A number of people have posted about problems with honeyd and nmap, usually along the lines of "It doesnt work". Well honeyd works fine with nmap in most cases. There is one configuration which does cause problems, where the nmap scanner and the honeypot are on the same network and you're using arpd (farpd) to direct traffic to the honeypot.

If you're short of time, here's the quick answer:
By default nmap will use an arp scan to determine if a host on the local network is up. Arpd is too slow to respond to the arp request, so nmap thinks the host is down and wont perform a scan. You need to patch arpd - the patch is below.

Here's the long answer, and a solution:
From the nmap manpage:
Quote:
If no host discovery options are given, Nmap sends a TCP ACK packet destined for port 80 and an ICMP Echo Request query to each target machine. An exception to this is that an ARP scan is used for any targets which are on a local ethernet network.

Note that ARP scans are performed even if the -P0 option is used. ARP discovery can be disabled using the --scan-ip option. So if you are scanning a honeypot on the local network use "nmap --scan-ip" to get the scan running.
Of course, what most people want is for their honeypots to respond to malicious nmap scans. To get that working you will need to patch arpd.
By default arpd works like this: if it sees an ARP request arpd will send its own ARP request to see if the IP address is already allocated. Two ARP requests are sent, and if arpd doesnt get a reply it will claim the IP address by sending a fake ARP reply. If another ARP request is seen before this process has completed the request is logged as "still discovering". If an ARP reply is received the reply is logged and no fake reply will be sent.
nmap runs an aggressive ARP discovery, and it cant be configured: the source code contains this fragment in targets.cc:
Code:

    /* Default timout should be much lower for arp */
    hostbatch[targetno]->to.timeout = MIN(o.initialRttTimeout(), 100) * 1000;

The most obvious way of speeding up the arpd response is to drop one of the ARP requests:
This patch does the trick:
Code:
--- arpd/arpd.c 2007-07-10 23:19:35.000000000 +0000
+++ arpd.new/arpd.c     2007-07-10 23:44:04.000000000 +0000
@@ -329,3 +329,3 @@

-       if (req->cnt < 2) {
+       if (req->cnt < 1) {
                arpd_send(arpd_eth, ARP_OP_REQUEST,
@@ -406,3 +406,3 @@

-                       if (req->cnt >= 3) {
+                       if (req->cnt >= 1) {
                                arpd_send(arpd_eth, ARP_OP_REPLY,

The result of this is that arpd only sends ONE ARP request before its ready to send the fake ARP reply. THIS HAS THE POTENTIAL TO BREAK YOUR NETWORK. It increases the likelihood that arpd will send a fake reply for an IP address that is already allocated.

This doesnt, however, solve the problem in itself.
Running nmap in debug mode against a patched arpd shows why:
Quote:
The max # of sockets we are using is: 0
--------------- Timing report ---------------
hostgroups: min 1, max 100000
rtt-timeouts: init 1000, min 100, max 10000
msx-scan-delay: TCP 1000, UDP 1000
parallelism: min 0, max 0
max-retries: 10, host-timeout: 0
---------------------------------------------
Initiating ARP Ping Scan at 23:44
Scanning 172.16.1.100 [1 port]
Pcap filter: arp and ether dst host FE:FD:00:00:00:04
Packet capture filter (device eth0): arp and ether dst host FE:FD:00:00:00:04
SENT (0.1070s) ARP who-has 172.16.1.100 tell 172.16.1.5

(FE:FD:00:00:00:04 is the MAC address of the nmap host)

nmap is looking for an ARP reply. But arpd sends the fake ARP reply as a broadcast - you can see this by sniffing the traffic -

23:40:25.820509 arp reply 172.16.1.100 is-at fe:fd:00:00:00:02 (oui Unknown)
0x0000: ffff ffff ffff fefd 0000 0002 0806 0001
0x0010: 0800 0604 0002 fefd 0000 0002 ac10 0164
0x0020: ffff ffff ffff ac10 0105

That ffffffffffff is a broadcast address - nmap simply doesnt see this reply.

The answer is to patch arpd so that it sends ARP replies to the host which issued the initial ARP request - the relevant code is in arpd.c in arpd_recv_cb function:
Code:
       addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
            ETH_ADDR_BROADCAST, ETH_ADDR_LEN);


If we replace the reference to ETH_ADDR_BROADCAST with the MAC address from the initial ARP request, then we get a directed fake ARP reply. The full patch look like this:
Code:

--- arpd/arpd.c 2007-07-10 23:19:35.000000000 +0000
+++ arpd.new/arpd.c     2007-07-10 23:44:04.000000000 +0000
@@ -329,3 +329,3 @@

-       if (req->cnt < 2) {
+       if (req->cnt < 1) {
                arpd_send(arpd_eth, ARP_OP_REQUEST,
@@ -362,3 +362,3 @@
        addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
-           ETH_ADDR_BROADCAST, ETH_ADDR_LEN);
+            ethip->ar_sha, ETH_ADDR_LEN);
        addr_pack(&src.arp_pa, ADDR_TYPE_IP, IP_ADDR_BITS,
@@ -406,3 +406,3 @@

-                       if (req->cnt >= 3) {
+                       if (req->cnt >= 1) {
                                arpd_send(arpd_eth, ARP_OP_REPLY,

And now nmap works:
Quote:

The max # of sockets we are using is: 0
--------------- Timing report ---------------
hostgroups: min 1, max 100000
rtt-timeouts: init 1000, min 100, max 10000
msx-scan-delay: TCP 1000, UDP 1000
parallelism: min 0, max 0
max-retries: 10, host-timeout: 0
---------------------------------------------
Initiating ARP Ping Scan at 23:24
Scanning 172.16.1.100 [1 port]
Pcap filter: arp and ether dst host FE:FD:00:00:00:04
Packet capture filter (device eth0): arp and ether dst host FE:FD:00:00:00:04
SENT (0.0820s) ARP who-has 172.16.1.100 tell 172.16.1.5
**TIMING STATS**: IP, probes active/freshportsleft/retry_stack/outstanding/retranwait/onbench, cwnd/ccthresh/delay, timeout/srtt/rttvar/
Groupstats (1/1 incomplete): 1/*/*/*/*/* 10.00/50/* 100000/-1/-1
172.16.1.100: 1/0/0/1/0/0 10.00/50/0 100000/-1/-1
RCVD (0.0850s) ARP reply 172.16.1.100 is-at FE:FD:00:00:00:02
Timeout vals: srtt: -1 rttvar: -1 to: 100000 delta 3401 ==> srtt: 3401 rttvar: 5000 to: 100000
Timeout vals: srtt: -1 rttvar: -1 to: 100000 delta 3401 ==> srtt: 3401 rttvar: 5000 to: 100000
Completed ARP Ping Scan at 23:24, 0.06s elapsed (1 total hosts)
mass_rdns: Using DNS server 194.72.0.98
Initiating SYN Stealth Scan at 23:24
Scanning target (172.16.1.100) [1697 ports]
Pcap filter: dst host 172.16.1.5 and (icmp or (tcp and (src host 172.16.1.100)))
Packet capture filter (device eth0): dst host 172.16.1.5 and (icmp or (tcp and (src host 172.16.1.100)))
Packet capture filter (device eth0): dst host 172.16.1.5 and (icmp or (tcp and (src host 172.16.1.100)))
SENT (0.1690s) TCP 172.16.1.5:56115 > 172.16.1.100:389 S ttl=59 id=42796 iplen=44 seq=1381261536 win=4096 <mss 1460>
SENT (0.1980s) TCP 172.16.1.5:56115 > 172.16.1.100:443 S ttl=42 id=47474 iplen=44 seq=1381261536 win=3072 <mss 1460>
SENT (0.1980s) TCP 172.16.1.5:56115 > 172.16.1.100:113 S ttl=54 id=42001 iplen=44 seq=1381261536 win=3072 <mss 1460>
SENT (0.1980s) TCP 172.16.1.5:56115 > 172.16.1.100:554 S ttl=38 id=11066 iplen=44 seq=1381261536 win=3072 <mss 1460>



This has the benefit of minimising the potential for network damage, since the fake ARP reply is directed at the querying host.

Its only a quick hack, and not perfect. Since the fake ARP isnt being broadcast its limited in potential, but it is a quick way to have your honeypots responding to nmap scans from the local network.

j
Back to top
View user's profile Send private message
billylebegue



Joined: 22 May 2007
Posts: 11
Location: France

PostPosted: Wed Jul 11, 2007 1:43 am    Post subject: Reply with quote

I have to test, but before that : I LOVE YOU ! Shocked


EDIT : dam*, i only find sources 0.2 for farpd. I tried to apply the patch to 0.2-8 it doesn't seem to work. When i configure i have missing libraries (which are installed of course, farpd was working before)

EDIT2 : problem solved.

jons you're a genious Embarassed
Hmmm but a strange thing, maybe because I compiled and installed (make, make install) over an existing installation... Doesn't work when i launch farpd, but when i launch arpd it works...

I can now finish my work !!!!! Shocked Shocked Shocked Very Happy Very Happy Very Happy (emoticons flood)
Back to top
View user's profile Send private message
CK76



Joined: 11 Jul 2007
Posts: 3

PostPosted: Wed Jul 11, 2007 12:07 pm    Post subject: Reply with quote

I've never really delt with code before, so I don't know how the farpd.c file should look. Should I replace
Code:

addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
            ETH_ADDR_BROADCAST, ETH_ADDR_LEN);

With
Code:

--- arpd/arpd.c 2007-07-10 23:19:35.000000000 +0000
+++ arpd.new/arpd.c     2007-07-10 23:44:04.000000000 +0000
@@ -329,3 +329,3 @@

-       if (req->cnt < 2) {
+       if (req->cnt < 1) {
                arpd_send(arpd_eth, ARP_OP_REQUEST,
@@ -362,3 +362,3 @@
        addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
-           ETH_ADDR_BROADCAST, ETH_ADDR_LEN);
+            ethip->ar_sha, ETH_ADDR_LEN);
        addr_pack(&src.arp_pa, ADDR_TYPE_IP, IP_ADDR_BITS,
@@ -406,3 +406,3 @@

-                       if (req->cnt >= 3) {
+                       if (req->cnt >= 1) {
                                arpd_send(arpd_eth, ARP_OP_REPLY,

?

Thanks in advance to anyone pointing me in the right direction. Very Happy
Back to top
View user's profile Send private message
billylebegue



Joined: 22 May 2007
Posts: 11
Location: France

PostPosted: Wed Jul 11, 2007 11:10 pm    Post subject: Reply with quote

It took time for me too to understand that lol
Quote:
--- arpd/arpd.c 2007-07-10 23:19:35.000000000 +0000
+++ arpd.new/arpd.c 2007-07-10 23:44:04.000000000 +0000

Edit the file arpd.c

Quote:

@@ -329,3 +329,3 @@

Line 329

Quote:

- if (req->cnt < 2) {
+ if (req->cnt < 1) {
arpd_send(arpd_eth, ARP_OP_REQUEST,

replace 2 by 1. The line below is already in the code

Quote:

@@ -362,3 +362,3 @@

Line 362

Quote:

addr_pack(&src.arp_ha, ADDR_TYPE_ETH, ETH_ADDR_BITS,
- ETH_ADDR_BROADCAST, ETH_ADDR_LEN);
+ ethip->ar_sha, ETH_ADDR_LEN);
addr_pack(&src.arp_pa, ADDR_TYPE_IP, IP_ADDR_BITS,

Replace ETH_ADDR_BROADCAST by ethip->ar_sha

Quote:

@@ -406,3 +406,3 @@

Line 406

Quote:

- if (req->cnt >= 3) {
+ if (req->cnt >= 1) {
arpd_send(arpd_eth, ARP_OP_REPLY,

Replace 3 by 1
Back to top
View user's profile Send private message
jons



Joined: 03 Feb 2007
Posts: 32

PostPosted: Thu Jul 12, 2007 2:22 am    Post subject: Reply with quote

It's a diff file - it shows the differences between files. To save manual editing you can apply the diff file by using the patch command.
Have a look at the manpages for diff and patch.

j
Back to top
View user's profile Send private message
CK76



Joined: 11 Jul 2007
Posts: 3

PostPosted: Thu Jul 19, 2007 2:39 pm    Post subject: Reply with quote

jons wrote:
Have a look at the manpages for diff and patch.


Exactly what I needed. Thanks, I got it patched and OS fingerprinting works perfectly.

Quote:

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2007-07-19 15:39 PDT
Interesting ports on [snip] (192.168.101.137):
Not shown: 1675 closed ports
PORT STATE SERVICE
21/tcp open ftp
137/tcp open netbios-ns
139/tcp open netbios-ssn
1080/tcp open socks
3128/tcp open squid-http
MAC Address: 00:03:47:C1:1A:38 (Intel)
Device type: general purpose
Running: Microsoft Windows NT/2K/XP
OS details: Microsoft Windows XP Pro SP1

Nmap finished: 1 IP address (1 host up) scanned in 2.350 seconds

Laughing Laughing Laughing

PS - Sorry it took me so long to respond. I got busy and had to put the honeyd box aside for a bit. Smile
Back to top
View user's profile Send private message
nielsprovos
Site Admin


Joined: 01 Aug 2005
Posts: 79

PostPosted: Mon Jul 30, 2007 9:24 am    Post subject: Reply with quote

Hmm. Did the arp support in Honeyd itself (either by using DHCP or by directly assigning an ethernet mac address to a template) not work for people?
Back to top
View user's profile Send private message
CK76



Joined: 11 Jul 2007
Posts: 3

PostPosted: Mon Jul 30, 2007 12:22 pm    Post subject: Reply with quote

nielsprovos wrote:
Hmm. Did the arp support in Honeyd itself (either by using DHCP or by directly assigning an ethernet mac address to a template) not work for people?

I'm, not, really, sure Embarassed

All the guides I've found/used said to use arpd to forword arp to your honeyd host, so that's what I did.
Back to top
View user's profile Send private message
jons



Joined: 03 Feb 2007
Posts: 32

PostPosted: Tue Jul 31, 2007 2:40 pm    Post subject: Reply with quote

Hi Niels

The arp support in honeyd works fine (nice work Smile ), and doesnt generate any problems with nmap. I guess it's because most people use arpd to get traffic to their honeypots that we see the posts about nmap not working. The note was specific to one common scenario, and I tried to make this clear in the posting:
Quote:
Well honeyd works fine with nmap in most cases. There is one configuration which does cause problems, where the nmap scanner and the honeypot are on the same network and you're using arpd (farpd) to direct traffic to the honeypot.

j
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Honeyd Discussion Forums Forum Index -> General All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.9 © 2001, 2002 phpBB Group