-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumpfile_string.cc
155 lines (119 loc) · 3.85 KB
/
dumpfile_string.cc
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
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "dumpfile_string.h"
#include "phy_80211.h"
int dumpfilestring_chain_hook(CHAINCALL_PARMS) {
Dumpfile_String *auxptr = (Dumpfile_String *) auxdata;
return auxptr->chain_handler(in_pack);
}
Dumpfile_String::Dumpfile_String() {
fprintf(stderr, "FATAL OOPS: Dumpfile_String called with no globalreg\n");
exit(1);
}
Dumpfile_String::Dumpfile_String(GlobalRegistry *in_globalreg) :
Dumpfile(in_globalreg) {
char errstr[STATUS_MAX];
globalreg = in_globalreg;
stringfile = NULL;
type = "string";
logclass = "string";
if (globalreg->sourcetracker == NULL) {
fprintf(stderr, "FATAL OOPS: Sourcetracker missing before "
"Dumpfile_String\n");
exit(1);
}
#if 0
if (globalreg->builtindissector == NULL) {
fprintf(stderr, "FATAL OOPS: Sourcetracker missing before "
"Dumpfile_String\n");
exit(1);
}
#endif
// Find the file name
if ((fname = ProcessConfigOpt()) == "" ||
globalreg->fatal_condition) {
return;
}
stringfile = fopen(fname.c_str(), "w");
if (stringfile == NULL) {
snprintf(errstr, STATUS_MAX, "Failed to open string dump file '%s': %s",
fname.c_str(), strerror(errno));
_MSG(errstr, MSGFLAG_FATAL);
globalreg->fatal_condition = 1;
return;
}
_MSG("Opened string log file '" + fname + "'", MSGFLAG_INFO);
globalreg->packetchain->RegisterHandler(&dumpfilestring_chain_hook, this,
CHAINPOS_LOGGING, -100);
globalreg->RegisterDumpFile(this);
// globalreg->builtindissector->SetStringExtract(2);
Kis_80211_Phy *dot11phy =
(Kis_80211_Phy *) globalreg->FetchGlobal("PHY_80211");
if (dot11phy != NULL) {
dot11phy->SetStringExtract(2);
_MSG("Dumpfile_String - forced string extraction from packets at all times",
MSGFLAG_INFO);
}
}
Dumpfile_String::~Dumpfile_String() {
globalreg->packetchain->RemoveHandler(&dumpfilestring_chain_hook,
CHAINPOS_LOGGING);
// Close files
if (stringfile != NULL) {
Flush();
fclose(stringfile);
}
stringfile = NULL;
}
int Dumpfile_String::Flush() {
if (stringfile == NULL)
return 0;
fflush(stringfile);
return 1;
}
int Dumpfile_String::chain_handler(kis_packet *in_pack) {
if (stringfile == NULL)
return 0;
kis_string_info *stringinfo = NULL;
if (in_pack->error)
return 0;
// Grab the 80211 info, compare, bail
dot11_packinfo *packinfo;
if ((packinfo =
(dot11_packinfo *) in_pack->fetch(_PCM(PACK_COMP_80211))) == NULL)
return 0;
if (packinfo->corrupt)
return 0;
if (packinfo->type != packet_data || packinfo->subtype != packet_sub_data)
return 0;
// If it's encrypted and hasn't been decrypted, we can't do anything
// smart with it, so toss.
if (packinfo->cryptset != 0 && packinfo->decrypted == 0)
return 0;
// Grab the strings
stringinfo = (kis_string_info *) in_pack->fetch(_PCM(PACK_COMP_STRINGS));
if (stringinfo == NULL)
return 0;
for (unsigned int x = 0; x < stringinfo->extracted_strings.size(); x++) {
fprintf(stringfile, "%s %s %s %s\n",
packinfo->bssid_mac.Mac2String().c_str(),
packinfo->source_mac.Mac2String().c_str(),
packinfo->dest_mac.Mac2String().c_str(),
stringinfo->extracted_strings[x].c_str());
}
dumped_frames++;
return 1;
}