arp -a does not list all devices - arp

I have an app which checks whether a certain IP is on the local network. The IP belongs to a raspberry pi working as a homeautomation device.
Running the command
arp -a
from terminal or from within my app I get a list of all devices on the local network, but my raspberry pi is not always listed. After pinging the device, it appears on the list every time.
Any ideas what is going wrong?

That's the way ARP works. ARP entries are created only when they're needed. The first time you need to communicate with an IP on the local network, your device broadcasts an ARP query, then caches the response. There's nothing that proactively fills in the cache for all IPs on the LAN.
In addition, old entries may be removed from the cache if they haven't been used in a while.

Related

Ettercap - ARP poisoning unsuccessful

Yesterday I successfully performed a MITM attack by ARP poisoning between my router and my Windows7 computer. I used Ettercap on a Linux machine.
However, today, running the same command does not work anymore. It looks like Ettercap cannot reach my computer, which IP is 192.168.0.17.
Here is what I got :
We can see that the only host added to the list is the router one (192.168.0.1)... What I don't understand is that it was working few hours ago.
I noticed also another thing.
using the command
sudo arpspoof -i wlp20s0 -t 192.168.0.17 192.168.0.1
The ARP poisonning DOES work this time. But now the problem is that it is acting like a DDOS on my victim... It completely loses internet connection.
And before it was not, it was working as expected.
So I guess something has changed on my victim computer but I cannot figure what.
Thank you.
IP forwarding is the ability for an operating system to accept incoming network packets on one interface, recognize that it is not meant for the system itself, but that it should be passed on to another network, and then forwards it accordingly.
From https://openvpn.net/faq/what-is-and-how-do-i-enable-ip-forwarding-on-linux/
When you perform MITM packets that don't match your IP are being sent to you and are not passed on correctly so the victim can reach out to the internet. With IP forwarding enabled your computer will reroute the packets correctly and the attacked computer will have access to the internet.
On Linux if I remember correctly:
echo 1 > /proc/sys/net/ipv4/ip_forward
will fo the job.
Arp replies are stored in cache, so first of all do some tricks here:
Remove arp cache from windpws with cmd.
(Cause the first priority is the cache and if host cant find the mac address it will generate an ARP request,then your router will repliy with ARP reply)
issue this command to see arp table:
arp -a
When you do Mitm with arp spoof and your computer looses internet connectivity it might be your DNS misconfiguration.
You ll need to enable dns server.
(If wan to brows web pages)
Try to do it with ettercap and enable arp poision and dns spoof module.

Programmatically get IP of directly connected device

Using C I am trying to discover the IP of a locally connected device without knowing any information about the device.
[ my box ]--eth0--------------[ unknown device ]
I can't seem to find a way to arp/broadcast to get the IP of the device. I understand that if I use multicast the device itself has to be a member of the group. When I arp or arp-scan they ask me to assign my eth0 interface an IP but I don't have one assigned, I can put one if I need to but I am unsure what it needs to be set to in order to discover anything.
Example: I have a Linksys wireless IP camera and I want to find the IP/Subnet. Without knowing its subnet/netmask I wouldn't know what to set my eth0 to.
I have written a C program to parse the arp table in Linux but I cannot seem to get the IP from the locally connected device in it. As mentioned above, I cannot use these tools without setting eth0 to something.
I think Your best chance to find something is by capturing all incoming network traffic, especially while unknown device is booting (using tcpdump, wireshark or something similar). Just filter out traffic, which is sent from my box.
Most likely You'll see DHCP requests and maybe ARP requests. If device is using DHCP, the easyest solution would be to run DHCP server on eth0 (so You can assign IP to this device).
If for some reason You need to program in C (and network capture gives expected results), libpcap may be usefull.
If evrything else fails, You can try to dicover unknown IP using fake ARP packets (so You don't need to change IP on eth0) and capturing any responses.

How to receive broadcasts from nodes with the same ip address?

I have a device that is made up of separate modules running embedded linux. The modules are all the same hardware and software but perform different tasks depending upon their location in the device. All the modules talk to each other over an internal network. The ip addresses of the modules are set statically based on the location in the device. This is done by having the modules read a physically set device that returns a 0-15 number. It plugs into the modules but is physically attached to the location in the device. A device might have 6 racks, so there are 6 of these plugs set 1-6.
I want the device to determine if any module is incorrectly set as this would cause two or more modules to have the same IP address. This could be caused by either an incorrectly set or broken location dongle. The modules communicate with each other using broadcast UDP messages. One of the data members of the message is a unique 48-bit serial number, the MAC address.
My initial plan was to have all the modules compare the messages that are from themselves with their serial number and throw an error if they don't match. The problem is the modules only receive the broadcast packets that are either from themselves or another IP address. They are not seeing packets that are from the same IP address but a different module.
When I check the interface using ifconfig I can see the Rx packets increasing, but when I use netstat -su I see nothing. The UDP Rx packets never increment. Therefore, at some point they're being dropped from the stack.
Is there a way around this? I know I can rely on a third node to tell it is receiving broadcast packets from the same IP address but different MACs, but I was hoping have each module be self aware of this problem.
Upon startup the modules should broadcast an ARP packet annoncing their MAC and IP. This is the 'normal' solution for duplicate IP addresses, you could listen to these broadcasts and send one new one, this way your modules will detect someone else on the network is using the same IP.

Finding all connected computers to network and getting their IP adresses - Windows C

just as title says.
Let's assume this situation:
I have a network and I need to know IP adresses and everything else related of all computers connected to mantain socket sending via Winsock under Windows.
Is there better way than looping throught IP Adresses range and sending something like:
"Are You there?" and waiting for answer from client?
Performing an ARP scan would tell you which devices are active on the network, regardless of device type or operating system. So this would include PCs, laptops, phones, routers, and any other devices with a NIC. This is the most reliable way of scanning for live hosts on a network.
ARP is the protocol that translates IP addresses into MAC addresses, or vice versa. It allows routing devices to translate between the logical network and the physical network. When you send a packet to, say, 192.168.1.99, your system first sends out an ARP request for 192.168.1.99, saying something along the lines of "Who has 192.168.1.99? Tell [my MAC]". Other devices on the network see this packet, and the owner of that IP address will reply "Hi [MAC], I'm 192.168.1.99, my MAC is 00:12:34:56:78:90".
You can (ab)use this protocol to discover network devices. If you know you're on 192.168.1.x, you send ARP requests for 192.168.1.1 through 192.168.1.254, and record the results. Every reply you get indicates a live system at the defined IP address.
Keep in mind that not all your users will be on 192.168.1.0/24, so you'll need to check the current network configuration first.
As far as doing this in C goes, it's not a simple task. However, you can take a look at this example which implements ARP scanning.
An alternative to the ARP scan suggested by #Polynomial is the PING scan.
Same concept, PING each address in your subnet, and record the results.
Just as an ARP scan may give you false positives (because there is a router saying "I'll deal what that address" whether there is a device on it or not), so too, PING can give you false negatives (as some systems disable the ICMP/PING command).
There is a tool called fping that implements this kind of PING scan in a massively parallel way. Fping is originally a *NIX program, but there are Windows versions out there. You should be able to find the source to peruse if you want to learn the gory details.

simulate different PC with different IP addresses in linux environment

im new to linux environment and any help/feedback would be appreciated. Im actually trying to develop a client-server (MULTICAST) program, so, i would like to test one client sending information to different servers (one-to-many relationship). thus, i would like to simulate different server side in linux with different IP addresses in one computer.
Did you try using different ports instead? I didn't try it myself, but perhaps that can help you in the mid-time.
If you're really multicasting, you don't need to worry about physical host-specific IP:s, all you should need to do is make sure all the programs (clients and servers) are using the same multicast group addresses. Then they should all see each other's traffic automatically.
There's nothing stopping you from running multiple clients on the same machine that also runs the server, in this case.
I sounds like you want to test your code with different IP's. You can create IP aliases on your interface and simulate multiple IP's on one computer.
for e.g. if eth0 is you're active interface with IP, say 192.168.5.11 you can assign another IP to eth0:0 (an alias to eth0) as below.
ifconfig eth0:0 192.168.5.12 netmask255.255.255.0 up
ifconfig eth0:1 192.168.5.13 netmask255.255.255.0 up
run your server on one of the IP's and distribute clients to all your aliases
Use either of the following when you do not have sufficient hardware:
Multicast loop which has the IP stack redirect outbound packets to local receivers.
Virtual machines.
Be aware that semantics of the socket option for #1 change depending on the operating system; for #2 only some virtual machines support multicast, refer to the vendor for details.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms739161(v=vs.85).aspx
Ultimately though you must test with different machines due to specific artifacts of how hosts manage multicast groups. You can for instance create send-only membership which will block every other application on the host. Also consider that an internet, lower case 'I', will introduce further artifacts regarding group joining and propagation delays and drops that your application may need to be aware of.
You can create multiple IP for same machine with help of IP alias. As mentioned above.
But to create multiple Server at one PC you must need different port for each server if you want to simulate the all server behavior with network as well.
I mean for one port multicast traffic always goes to that and some process in the PC will be receiving the packet and has to serve for all server in the PC, Means you have one packet only and all server is receiving with locally manipulation.
But really simulation would be you have multiple server at 1 PC and all are receiving multicast traffic from network rather then from local process.
my Solution: You keep number for server == number of port at the PC. Client send the multicast traffic over all port simultaneously and all server at the PC end will be receiving multicast packet from corresponding port from the Network.
Please correct me if my understanding is wrong.

Resources