forked from Gnoxter/mountain_goat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers.h
119 lines (96 loc) · 3.05 KB
/
layers.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef __LAYERS_H__
#define __LAYERS_H__
#include <stdint.h>
#include <stdbool.h>
#include <pcap.h>
typedef struct {
pcap_t *handle;
int raw_socket;
int stream_socket;
struct addrinfo *attacker_addr;
struct addrinfo *saddr;
struct addrinfo *daddr;
uint32_t stream_seq;
uint32_t stream_acks;
int connection_closed;
long nsec_offset;
uint32_t sequence_chunk_start;
uint32_t sequence_chunk_end;
uint32_t step;
int sequence_i;
uint32_t sequence_in_window;
uint16_t window_size;
} Session;
#pragma pack(1)
struct ipv4_header {
uint8_t ver_ihl;
uint8_t dscp_ecn; //formerly tos
uint16_t len;
uint16_t ident;
uint16_t frag_field;
uint8_t ttl;
uint8_t protocol;
uint16_t chksum;
uint32_t sourceip;
uint32_t destip;
};
extern const unsigned ipv4_header_min_size;
extern const unsigned ipv4_header_max_size;
#pragma pack(1)
struct tcp_header {
uint16_t srcport;
uint16_t destport;
uint32_t seqnum;
uint32_t acknum;
uint8_t data_ns;
uint8_t flags;
uint16_t win;
uint16_t chksum;
uint16_t urgptr;
};
#pragma pack(1)
struct pseudo_header {
uint32_t sourceip;
uint32_t destip;
uint8_t zero;
uint8_t protocol;
uint16_t tcp_len;
struct tcp_header tcp;
};
extern const unsigned tcp_header_min_size;
extern const unsigned tcp_header_max_size;
void ipv4_init(struct ipv4_header *h, Session *ctx);
void ipv4_spoof_init(struct ipv4_header *h, Session *ctx);
void ipv4_dump(struct ipv4_header *h);
void ipv4_set_dont_frag(struct ipv4_header *h);
uint8_t ipv4_get_ihl(struct ipv4_header *h);
uint8_t ipv4_get_protocol(struct ipv4_header *h);
uint16_t ipv4_get_len(struct ipv4_header *h);
struct tcp_header *ipv4_get_tcp(struct ipv4_header *h, uint32_t caplen);
void tcp_init(struct tcp_header *h, Session *ctx);
void tcp_spoof_init(struct tcp_header *h, Session *ctx);
void tcp_dump(struct tcp_header *h);
void tcp_calculate_checksum(struct ipv4_header *ip, struct tcp_header *h);
void tcp_set_syn(struct tcp_header *h);
void tcp_set_ack(struct tcp_header *h);
void tcp_set_rst(struct tcp_header *h);
void tcp_set_fin(struct tcp_header *h);
bool tcp_isset_syn(struct tcp_header *h);
bool tcp_isset_ack(struct tcp_header *h);
bool tcp_isset_rst(struct tcp_header *h);
bool tcp_isset_fin(struct tcp_header *h);
void tcp_set_seqnum(struct tcp_header *h, uint32_t seq);
uint32_t tcp_get_seqnum(struct tcp_header *h);
void tcp_set_acknum(struct tcp_header *h, uint32_t ack);
uint32_t tcp_get_acknum(struct tcp_header *h);
void tcp_set_window_size(struct tcp_header *h, uint16_t size);
uint16_t tcp_get_window_size(struct tcp_header *h);
void disable_ip_header(Session *ctx);
void enable_ip_header(Session *ctx);
Session *new_session(char *attacker_ip, int attacker_source_port, char *source_ip, char *destination_ip, int destination_port);
void session_connect(Session *ctx);
struct tcp_header *session_read_packet(Session *ctx);
void session_set_source_port(Session *ctx, uint16_t port);
uint16_t session_get_source_port(Session *ctx);
void session_reconnect_increase(Session *ctx);
#endif