我正在使用Linux并试图弄清楚如何查询(通过API)特定条目的NDP表.到目前为止,我发现的唯一示例(在iproute2的源代码中)使用Netlink并获取整个表.有没有办法在特定接口上查询Netlink以获取特定的IPv6地址?还是有一种不同于使用Netlink的方式我应该去做呢?
我捕获了一些流量,并将其存储在.pcap文件中。在那里发生了ARP中毒攻击。
有没有一种方法可以在Python脚本中使用Scapy检测攻击者的IP和MAC地址以及受害者的IP和MAC地址?
我正在编写一个用于创建,发送,接收和解释ARP数据包的程序.我有一个表示ARP头的结构,如下所示:
struct ArpHeader
{
unsigned short hardwareType;
unsigned short protocolType;
unsigned char hardwareAddressLength;
unsigned char protocolAddressLength;
unsigned short operationCode;
unsigned char senderHardwareAddress[6];
unsigned char senderProtocolAddress[4];
unsigned char targetHardwareAddress[6];
unsigned char targetProtocolAddress[4];
};
Run Code Online (Sandbox Code Playgroud)
这仅适用于长度为6的硬件地址和长度为4的协议地址.地址长度也在标题中给出,因此要正确,结构必须如下所示:
struct ArpHeader
{
unsigned short hardwareType;
unsigned short protocolType;
unsigned char hardwareAddressLength;
unsigned char protocolAddressLength;
unsigned short operationCode;
unsigned char senderHardwareAddress[hardwareAddressLength];
unsigned char senderProtocolAddress[protocolAddressLength];
unsigned char targetHardwareAddress[hardwareAddressLength];
unsigned char targetProtocolAddress[protocolAddressLength];
};
Run Code Online (Sandbox Code Playgroud)
这显然不起作用,因为在编译时不知道地址长度.模板结构也不是一个选项,因为我想填充结构的值,然后将它从(ArpHeader*)转换为(char*)以获得可以在网络上发送的字节数组或转换从(char*)到(ArpHeader*)的接收字节数组,以便解释它.
一种解决方案是创建一个包含所有头字段作为成员变量的类,一个创建表示可以在网络上发送的ARP头的字节数组的函数,以及一个只占用一个字节数组(在网络上接收)的构造函数并通过读取所有头字段并将其写入成员变量来解释它.这不是一个很好的解决方案,因为它需要更多的代码.
相反,例如UDP报头的类似结构是简单的,因为所有报头字段具有已知的恒定大小.我用
#pragma pack(push, 1)
#pragma pack(pop)
Run Code Online (Sandbox Code Playgroud)
围绕结构声明,以便我可以实际进行简单的C样式转换,以获得在网络上发送的字节数组.
我可以在这里使用哪种解决方案接近结构,或者至少不需要比结构更多的代码?我知道结构中的最后一个字段(如果它是一个数组)不需要特定的编译时大小,我可以使用类似的东西来解决我的问题吗?只是将这4个数组的大小留空将编译,但我不知道它将如何实际起作用.从逻辑上讲,它不起作用,因为如果第一个数组的大小未知,编译器将不知道第二个数组的起始位置.
我尝试使用WINDOWS XP(但这不是重点),虽然我认为我无法使用Raw Winsock发送或接收ARP数据包,但是来自Internet的一些文件说是,如果是这样,如何设置Winsock功能?
我正在转储传出流量。我只想要发往局域网外的 TCP 和 UDP 数据包,别无其他。我只是在 tcpdump 中使用了以下过滤器:
ip and (tcp or udp) and (not icmp) and src host myIPAddr and not dst net myNet/myNetBits and not ip broadcast
Run Code Online (Sandbox Code Playgroud)
但我捕获了以下数据包:
###[ Ethernet ]###
dst = ff:ff:ff:ff:ff:ff
src = 00:1e:4a:e0:9e:00
type = 0x806
###[ ARP ]###
hwtype = 0x1
ptype = 0x800
hwlen = 6
plen = 4
op = who-has
hwsrc = 00:1e:4a:e0:9e:00
psrc = X.X.X.X
hwdst = 00:00:00:00:00:00
pdst = Y.Y.Y.Y
###[ Padding ]###
load = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?我以为我只转储IP …
我熟悉BSD插座,翻阅手册sendto,我碰到了MSG_CONFIRM旗帜,这对我来说是非常神秘的.
描述说:
告诉链接层转发进度:您从另一方获得了成功的回复.如果链路层没有得到这个,它将定期重新修复邻居(例如,通过单播ARP).仅在SOCK_DGRAM和SOCK_RAW套接字上有效,目前仅针对IPv4和IPv6实现.
在快速查看手册之后arp,我明白标记某些东西MSG_CONFIRM可以防止ARP映射MAC地址remote远程机器的IP地址被认为是陈旧的.
现在我很奇怪,因为我看不出有任何理由,我应该不会把它,因此,他们为什么不执行直接在库中.为什么应用层应该处理在链路层发生的任何事情.
所以我错过了什么?我什么时候应该设置它,还是不设置它?
I am trying to extract MAC address from arp table without but it is returning a empty line.
I tried to use the command:
arp -a | grep eth1 | grep '^\A(([0-9a-fA-F]{2}):){5}([0-9a-fA-F]{2})$\z'
Run Code Online (Sandbox Code Playgroud)
The 'arp -a' command return:
? (192.168.36.20) at 80:e0:1d:43:b0:60 [ether] on eth1
? (192.168.0.1) at 34:4b:50:b7:ef:08 [ether] on usb0
? (172.17.140.200) at 10:c3:7b:c4:82:04 [ether] on eth0
Run Code Online (Sandbox Code Playgroud)
Thanks
我理解ARP的机制,但我想知道为什么即使我们有收件人的IP地址我们也使用它?依靠收件人的IP地址发送数据包而不是采取额外的步骤来查找匹配的MAC地址是不够的?
谢谢.
networking network-programming mac-address communication arp
我是一名学生,想了解更多有关 C# 中的 ARP 和套接字的信息
为此,我尝试使用SocketC# 中的原始数据发送 ARP 请求和回复。
我已经在字节数组中手动重建了 ARP 回复,并且尝试使用该Socket.Send方法发送它。
static void Main(string[] args)
{
// Create a raw socket
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Raw);
// Setup ARP headers
byte[] buffer = new byte[]
{
0x34, 0x97, 0xf6, 0x22, 0x04, 0xe8, // Ethernet Destination mac
0x70, 0x1c, 0xe7, 0x51, 0x94, 0x0b, // Ethernet source mac
0x08, 0x06, // Type: ARP
00, 0x01, // Hardware type: Ethernet
0x08, 0x00, // Protocol type: IPv4 …Run Code Online (Sandbox Code Playgroud) 我想知道如何发送语言C的ARP数据包,从套接字发送和发送的函数通过TCP或UDP发送,但我没有找到如何使用ARP.