-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.cpp
133 lines (108 loc) · 3.39 KB
/
headers.cpp
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//#include <bits/stdc++.h>
//#include <tins/tins.h>
#include "json.hpp"
#define d 256
using namespace Tins;
using namespace std;
// compile using : c++ headers.cpp -ltins
ofstream myfile;
vector<string> v{"Cache-Control: no-store", "Content-Security-Policy: frame-ancestors 'none'", "Content-Type", "Strict-Transport-Security", "X-Content-Type-Options: nosniff", "X-Frame-Options: DENY"};
int q = 101;
/**************************************
LPS function
***************************************/
void lps_func(string txt, vector<int>&Lps){
Lps[0] = 0;
int len = 0;
int i=1;
while (i<txt.length()){
if(txt[i]==txt[len]){
len++;
Lps[i] = len;
i++;
continue;
}
else{
if(len==0){
Lps[i] = 0;
i++;
continue;
}
else{
len = Lps[len-1];
continue;
}
}
}
}
/**************************************
KMP Function
***************************************/
void KMP(string pattern,string text){
int n = text.length();
int m = pattern.length();
vector<int>Lps(m);
int flag = 0;
lps_func(pattern,Lps);
int i=0,j=0;
while(i<n){
if(pattern[j]==text[i]){i++;j++;}
if (j == m) {
cout<<"\033[1;32m[+] Header "<< pattern <<" found at index "<<i - m <<"\033[0m"<<endl;
j = Lps[j - 1];
flag = 1;
}
else if (i < n && pattern[j] != text[i]) {
if (j == 0)
i++;
else
j = Lps[j - 1];
}
}
if(!flag){
cout <<"\033[1;33m[!] Header "<< pattern <<" is not found \033[0m"<< endl;
}
}
bool handler(const PDU& pkt) {
// Lookup the TCP PDU
const TCP &tcp = pkt.rfind_pdu<TCP>();
// Extract the RawPDU object.
//const RawPDU& raw = tcp.rfind_pdu<RawPDU>();
// Finally, take the payload (this is a vector<uint8_t>)
/*const RawPDU::payload_type& payload = raw.payload();
for(const auto &query : payload){
cout << query;
}*/
if(tcp.sport() == 8080){
string resp = "";
const RawPDU& raw = tcp.rfind_pdu<RawPDU>();
const RawPDU::payload_type& payload = raw.payload();
for(const auto &query : payload){
resp += query;
}
if(resp[0] != '0'){
cout << "\n\033[1;37m****************************************************\033[0m"<< endl;
cout << "\n\033[1;37m New Request \033[0m"<< endl;
cout << "\n\033[1;37m****************************************************\033[0m\n"<< endl;
cout << "\n\033[1;35m- Security Headers :\033[0m\n" << endl;
for(auto x : v){
KMP(x, resp);
}
cout << "\n\033[1;35m- DoS Attacks :\033[0m\n" << endl;
//system("python3 pyflooder.py localhost 80 4000");
}
}
// We need source/destination port to be 53
/*if (udp.sport() == 53 || udp.dport() == 53) {
// Interpret it as DNS. This might throw, but Sniffer catches it
DNS dns = pkt.rfind_pdu<RawPDU>().to<DNS>();
// Just print out each query's domain name
for (const auto &query : dns.queries()) {
std::cout << query.dname() << std::endl;
}
}*/
return true;
}
int main() {
Sniffer("docker0").sniff_loop(handler);
}