-Sending ARP, ICMP Packet (libtins Examples)-


[ARP]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <tins/tins.h>
#include <unistd.h>
 
int main()
{
    Tins::PacketSender sender;
    //Libtins packetsender(Virtual L1 Physical Layer)
 
    Tins::IPv4Address target = Tins::IPv4Address("192.168.43.1");
    //Target IP
 
    Tins::NetworkInterface iface = Tins::NetworkInterface::default_interface();
    Tins::NetworkInterface::Info info = iface.addresses();
    //Get addresses from network interface
 
    Tins::EthernetII eth = Tins::EthernetII("ff:ff:ff:ff:ff:ff", info.hw_addr);
    //Set L2 Ethernet Packet as Broadcast Packet
 
    Tins::ARP testARP = Tins::ARP(target, info.ip_addr, "00:00:00:00:00:00", info.hw_addr);
    //Setup L3 ARP Packet (target_ip, sender_ip, target_hw, sender_hw)
 
    testARP.opcode(Tins::ARP::Flags::REQUEST);
    //Set ARP flag as Request
 
    eth /= testARP;
    //Build-up ARP Protocol on Ethernet
 
    printf("Send!\n");
    sender.send(eth, iface);
    //Send Packet
    return 0;
}
 
 
cs

Source Code


Request Packet (Crafted by libtins)


Reply Packet (Android Nexus5x)




[ICMP]


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <tins/tins.h>
#include <unistd.h>
 
int main()
{
    Tins::PacketSender sender;
    //Libtins packetsender(Virtual L1 Physical Layer)
 
    Tins::IPv4Address target = Tins::IPv4Address("192.168.43.1");
    //Target IP
 
    Tins::NetworkInterface iface = Tins::NetworkInterface::default_interface();
    Tins::NetworkInterface::Info info = iface.addresses();
    //Get addresses from network interface
 
    Tins::EthernetII eth = Tins::EthernetII("ff:ff:ff:ff:ff:ff", info.hw_addr);
    //Set L2 Ethernet Packet as Broadcast Packet
 
    Tins::IP ip = Tins::IP(target, info.ip_addr);
    ip.protocol(Tins::IP::ICMP);
    //Set L3 IPv4 Packet
 
    Tins::ICMP testICMP = Tins::ICMP();
    testICMP.code(Tins::ICMP::ECHO_REQUEST);
    //Set L3 ICMP Packet as ECHO_REQUEST Packet
 
    eth /= ip;
    eth /= testICMP;
    //Build-up IPv4&ICMP Protocol
 
    printf("Send!\n");
    sender.send(eth, iface);
    //Send Packet
    return 0;
}
 
 
cs

Source Code

Request Packet (Crafted by libtins)


Reply Packet (Android Nexus5x)



'Network' 카테고리의 다른 글

[Network/libtins] Wi-Fi auto deauthentication attack (C++)  (0) 2016.06.27
[Network/ARP] ARP Request/Reply  (0) 2016.06.25
[Network/Ethernet] EthernetII header  (0) 2016.06.21
Posted by RevDev
,