使用 pcap、MAC 地址过滤器进行无线嗅探

发布于 2025-01-02 08:59:10 字数 846 浏览 5 评论 0原文

我正在用 C 语言编写一个无线数据包嗅探器程序。我已经使用airmon-ng 将无线接口设置为监视模式,现在我正在嗅探接口“mon0”。我使用的是linux(ubuntu 10.10)。

我想将 MAC 地址设置为数据包的过滤器。 我已经这样做了,如下所示,但它说 “mon0没有分配IPV4地址”

 pcap_lookupnet(dev,&net,&mask,errbuf);
    printf("%s\n",errbuf);
    /* Open the session in promiscuous mode */
    handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
    if (handle == NULL) {
        printf("Couldn't open device %s: %s\n", dev, errbuf);
        return 2;
    }
    if(pcap_compile(handle,&fp,argv[0],0,net)==-1){
        fprintf(stderr,"Error calling pcap_compile\n");exit(1);}
    if(pcap_setfilter(handle,&fp) == -1){
        fprintf(stderr,"Error setting filter\n");exit(1);}
    /* The call pcap_loop() and pass our callback function */
    pcap_loop(handle, 10, my_callback, NULL);

请帮助我,我如何设置MAC地址过滤器?

I am writing a wireless packet sniffer program in C. I have set my wireless interface in monitor mode using airmon-ng, and now i am sniffing on the interface "mon0". I am using linux(ubuntu 10.10).

I want to set MAC address as the filter for the packets.
I have done it as shown below, but it says
"mon0 no IPV4 address assigned"

 pcap_lookupnet(dev,&net,&mask,errbuf);
    printf("%s\n",errbuf);
    /* Open the session in promiscuous mode */
    handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
    if (handle == NULL) {
        printf("Couldn't open device %s: %s\n", dev, errbuf);
        return 2;
    }
    if(pcap_compile(handle,&fp,argv[0],0,net)==-1){
        fprintf(stderr,"Error calling pcap_compile\n");exit(1);}
    if(pcap_setfilter(handle,&fp) == -1){
        fprintf(stderr,"Error setting filter\n");exit(1);}
    /* The call pcap_loop() and pass our callback function */
    pcap_loop(handle, 10, my_callback, NULL);

Please help me, how i can set the filter for MAC address??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

她说她爱他 2025-01-09 08:59:10

“未分配 IPV4 地址”是来自 pcap_lookupnet() 的错误。这意味着您尝试捕获的网络接口没有分配 IPv4 地址。 airmon-ng 所做的是为 Wi-Fi 适配器创建一个“监控”接口;适配器的常规网络接口可能分配有一个 IP 地址,但监视器接口不会有一个 IP 地址。

IP 地址唯一重要的地方是 IP 广播过滤器表达式;如果您没有过滤 IPv4 广播地址(您可能不会这样做),则无需获取 IPv4 地址。引用 pcap_compile() 手册页:

如果程序不知道正在捕获数据包的网络的网络掩码,或者如果正在可以在多个网络上捕获的 Linux“任何”伪接口上捕获数据包,则值为可以提供0个; IPv4 广播地址的测试将无法正确完成,但过滤器程序中的所有其他测试都可以。

因此只需将 0 作为“net”参数传递给 pcap_compile() 即可。

如果你想搜索发送到特定MAC地址的数据包,你可以使用wlan dst XX:XX:XX:XX:XX:XX;如果您想搜索从特定 MAC 地址发送的数据包,您可以使用 wlan src XX:XX:XX:XX:XX:XX ;如果您想搜索发送到或来自特定 MAC 地址的数据包,您可以使用 wlan host XX:XX:XX:XX:XX:XX。如果您关心接入点地址,而不是工作站地址,则需要使用过滤器,例如 wlan ra XX:XX:XX:XX:XX:XXwlan ta XX:XX:XX:XX:XX:XX,至少对于较新版本的 libpcap 是这样。 (请参阅 pcap-filter 手册页,或者,如果您没有 pcap-filter 手册页,请参阅 tcpdump 手册页了解详细信息。)

"no IPV4 address assigned" is an error from pcap_lookupnet(). All it means is that the network interface on which you're trying to capture does not have an IPv4 address assigned to it. What airmon-ng did was to create a "monitor" interface for the Wi-Fi adapter; the regular network interface for the adapter might have an IP address assigned to it, but the monitor interface won't have one.

The only place where the IP address matters is for ip broadcast filter expressions; if you're not filtering for IPv4 broadcast addresses, which you probably won't be, there's no need to get the IPv4 address. To quote the pcap_compile() man page:

If the netmask of the network on which packets are being captured isn't known to the program, or if packets are being captured on the Linux "any" pseudo-interface that can capture on more than one network, a value of 0 can be supplied; tests for IPv4 broadcast addreses won't be done correctly, but all other tests in the filter program will be OK.

so just pass 0 as the "net" argument to pcap_compile().

If you want to search for packets being sent to a particular MAC address, you can just use wlan dst XX:XX:XX:XX:XX:XX; if you want to search for packets being sent from a particular MAC address, you can just use wlan src XX:XX:XX:XX:XX:XX; if you want to search for packets being sent to or from a particular MAC address, you can just use wlan host XX:XX:XX:XX:XX:XX. If you care about the access point address, rather than the station address, you'll need to use filters such as wlan ra XX:XX:XX:XX:XX:XX or wlan ta XX:XX:XX:XX:XX:XX, at least with newer versions of libpcap. (See the pcap-filter man page or, if you don't have a pcap-filter man page, the tcpdump man page for details.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文