-
Notifications
You must be signed in to change notification settings - Fork 0
/
DHCPFlood.h
58 lines (44 loc) · 1.42 KB
/
DHCPFlood.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Created by root on 5/6/18.
//
#ifndef DHCPFLOOD_DHCPFLOOD_H
#define DHCPFLOOD_DHCPFLOOD_H
#include <iostream>
#include <tins/dhcp.h>
#include <tins/network_interface.h>
#include <tins/utils.h>
#include <tins/ethernetII.h>
#include <tins/packet_sender.h>
#include <tins/ip.h>
#include <tins/udp.h>
#include <tins/rawpdu.h>
#include <tins/sniffer.h>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <chrono>
#include <random>
using namespace Tins;
using namespace std::chrono;
class DHCPFlood {
std::string ifname;
std::default_random_engine generator;
std::uniform_int_distribution<uint8_t> distribution8; //unsigned 8 bit number generator for MAC
std::uniform_int_distribution<uint32_t> distribution32; //unsigned 32 bit number generator for xid
std::mutex m;
std::condition_variable cv;
std::atomic<bool> received = false; //true if ack or nack received
std::atomic<bool> finished = false; //true if latest IP DHCP generated
std::thread sniffer;
private:
SnifferConfiguration getSnifferConfig();
HWAddress<6> generateRandomMAC();
/* http://www.tcpipguide.com/free/t_DHCPMessageFormat.htm */
DHCP generateRandomDHCP(const IPv4Address &ip);
void startSnifferThread();
public:
DHCPFlood(const std::string& ifname); //ifname is interface name
void start(unsigned int startIP, unsigned int endIP);
};
#endif //DHCPFLOOD_DHCPFLOOD_H