forked from KTZ-Goel/PacketSniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps.cpp
More file actions
executable file
·177 lines (154 loc) · 4.94 KB
/
https.cpp
File metadata and controls
executable file
·177 lines (154 loc) · 4.94 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "https.h"
#include <arpa/inet.h>
#include <stdint.h>
#include <stdio.h>
#include "colors.h"
#include "shared.h"
#include "tags.h"
void handle_https(QList<QStandardItem*>* row, const uint8_t* https,
uint16_t size)
{
row->append(new QStandardItem("HTTPS"));
printf(CYAN " HTTPS:\n" RESET);
if (size == 0) {
printf(" This packet contains no more data\n");
row->append(new QStandardItem("Acknowledgement, no more data"));
return;
}
int totalLengthCounter = 0;
QString infoStr;
do {
uint8_t type = https[0];
uint16_t version = ntohs(((uint16_t*)(https + 1))[0]);
uint16_t length = ntohs(((uint16_t*)(https + 1))[1]);
totalLengthCounter += 5;
printf(" Content Type - ");
switch (type) {
case SSL_CTYPE_HANDSHAKE: {
printf("[22] Handshake\n");
infoStr += "[22] Handshake, ";
break;
}
case SSL_CTYPE_APP_DATA: {
printf("[23] Application Data\n");
infoStr += "[23] Application Data, ";
break;
}
default: {
printf(YELLOW "Content type [%u] not yet implemented.\n" RESET,
version);
row->append(new QStandardItem(
QString("Content type [%1] not implemented yet").arg(version)));
return;
}
}
printf(" Version ------ ");
switch (version) {
case SSL_VERSION_TLSV12: {
printf("TLSv1.2\n");
break;
}
default: {
printf(YELLOW "SSL version [0x%04X] not yet implemented." RESET "\n",
version);
break;
}
}
printf(" Total Length - %u\n", length);
char* data = (char*)https + 5;
printf(" Encrypted Data:\n");
uint16_t i = 0; // 数据索引
int n = 1;
printf("\t\t\t");
while (i < length && totalLengthCounter < size) {
char c = data[i];
putchar(IS_PRINTABLE(c) ? c : '.');
if (n == 64) {
printf("\n\t\t\t");
n = 0;
}
n++;
i++;
}
totalLengthCounter += i;
https = (uint8_t*)(data + i);
putchar('\n');
} while (totalLengthCounter < size);
row->append(new QStandardItem(infoStr));
}
void handle_https_fill(QString* infoStr, const uint8_t* https, uint16_t size)
{
infoStr->append(HEADER_TAG_START "HTTPS:" HEADER_TAG_END NEWLINE);
if (size == 0) {
infoStr->append(TAB "This packet contains no more data" NEWLINE);
return;
}
int totalLengthCounter = 0;
do {
uint8_t type = https[0];
uint16_t version = ntohs(((uint16_t*)(https + 1))[0]);
uint16_t length = ntohs(((uint16_t*)(https + 1))[1]);
totalLengthCounter += 5;
infoStr->append(TAB BOLD_TAG_START "Content Type" BOLD_TAG_END " - ");
switch (type) {
case SSL_CTYPE_HANDSHAKE: {
infoStr->append("[22] Handshake" NEWLINE);
break;
}
case SSL_CTYPE_APP_DATA: {
infoStr->append("[23] Application Data" NEWLINE);
break;
}
default: {
infoStr->append(
QString(YELLOW_FONT_START
"Content type [%1] not yet implemented." YELLOW_FONT_END
NEWLINE)
.arg(version));
return;
}
}
infoStr->append(TAB BOLD_TAG_START "Version" BOLD_TAG_END " ------ ");
switch (version) {
case SSL_VERSION_TLSV12: {
infoStr->append("TLSv1.2" NEWLINE);
break;
}
default: {
char versionBuffer[5];
snprintf(versionBuffer, sizeof(versionBuffer), "%04X", version);
infoStr->append(
QString(YELLOW_FONT_START
"SSL version [0x%1] not yet implemented." YELLOW_FONT_END
NEWLINE)
.arg(versionBuffer));
break;
}
}
infoStr->append(
QString(TAB BOLD_TAG_START "Total Length" BOLD_TAG_END " - %1" NEWLINE)
.arg(length));
char* data = (char*)https + 5; // Skip the header
infoStr->append(TAB BOLD_TAG_START "Encrypted Data:" BOLD_TAG_END NEWLINE);
uint16_t i = 0;
int n = 1;
infoStr->append(TAB TAB);
while (i < length && totalLengthCounter < size) {
char c = data[i];
if (IS_PRINTABLE(c)) {
infoStr->append(getHTMLentity(c));
} else {
infoStr->append('.');
}
if (n == 32) {
infoStr->append(NEWLINE TAB TAB);
n = 0;
}
n++;
i++;
}
totalLengthCounter += i;
https = (uint8_t*)(data + i);
infoStr->append(NEWLINE);
} while (totalLengthCounter < size);
}