-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipxor.cpp
More file actions
43 lines (35 loc) · 839 Bytes
/
ipxor.cpp
File metadata and controls
43 lines (35 loc) · 839 Bytes
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
#include "nfq.hpp"
#include <stdlib.h>
#include <string.h>
#include <tins/tins.h>
using namespace Tins;
char* key;
size_t klen;
void mask(uint8_t* data, size_t size)
{
for (size_t i = 0, j = 0; i < size; ++i, ++j) {
if (j == klen) j = 0;
data[i] ^= key[j];
}
}
inline uint8_t ver(uint8_t b) {
return (b & 0xf0) >> 4;
}
int offset;
uint32_t ipxor(uint8_t* &data, size_t &size)
{
mask(data + offset, size - offset);
// re-calculate checksums
auto vec = IP(data, size).serialize();
memcpy(data, vec.data(), size);
return NF_ACCEPT;
}
int main(int argc, char* argv[])
{
offset = atoi(argv[3]);
key = argv[2];
klen = strlen(key);
int qnum = atoi(argv[1]);
NFQ(qnum, ipxor).run();
return 0;
}