-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.hpp
87 lines (69 loc) · 1.99 KB
/
dns.hpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <cstdint>
#include <cstdlib>
#include <arpa/inet.h>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <sstream>
#include <map>
#include <set>
struct DNSQuery{
const char * name;
uint16_t type;
uint16_t class_;
std::string to_bytes();
std::string get_name();
};
struct DNSResponse{
uint16_t name;
uint16_t type;
uint16_t class_;
uint32_t time_to_live;
uint16_t data_length;
uint32_t address;
std::string to_bytes();
void calculate_name();
};
struct DnsSection{
uint16_t transaction_ID;
uint16_t flags;
uint16_t questions;
uint16_t answer_PRs;
uint16_t authority_PRs;
uint16_t additional_PRs;
std::vector<DNSQuery> queries;
std::vector<DNSResponse> answers;
std::string to_bytes();
};
struct DNSVictim{
std::string ip;
std::string spoofed_source_ip;
std::map<std::string,std::string> sites;
};
class PcapError: public std::runtime_error
{
public:
PcapError(const std::string& what_arg):
std::runtime_error(what_arg){};
PcapError( const char* what_arg ):
std::runtime_error(what_arg){};
};
template<class T>
void write_bytes_to_stream(const T& t, std::ostringstream& oss){
static_assert(std::is_same<T, uint32_t >::value or std::is_same<T, uint16_t >::value, "Invalid type passed");
oss.write(reinterpret_cast<const char*>(&t), sizeof(T));
}
uint32_t bytes_to_int(const char* bytes, ssize_t len);
DnsSection parse_dns_section(const char * bytes, ssize_t len);
uint16_t calculate_ipv4_checksum(const iphdr* ip_hdr);
void send_dns_response(DnsSection dns_section_response, std::string destination_ip, u_int16_t port);
DnsSection construct_dns_section_response(DnsSection query, const std::string& ip);
void stop_dns_spoofing();
/*
* @param victims: map<VICTIM_IP, map<DNS_TO_SPOOF, IP_ADDR>>
*/
void run_dns_spoof(const std::string& interface, std::vector<DNSVictim>* victims);