Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 0bbb049

Browse files
committed
Added output that maps number of clients to SSID
1 parent f2687d3 commit 0bbb049

File tree

8 files changed

+83
-15
lines changed

8 files changed

+83
-15
lines changed

pi_sniffer/pi_sniffer.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<file type="kml" enabled="true" />
1111
<file type="client_csv" enabled="true"/>
1212
<file type="probe_csv" enabled="true"/>
13+
<file type="ap_clients_csv" enabled="true"/>
1314
</output>
1415
</pi_sniffer>

pi_sniffer/src/configuration.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Configuration::Configuration() :
1616
m_wigle(false),
1717
m_kml(false),
1818
m_client_csv(false),
19-
m_probe_csv(false)
19+
m_probe_csv(false),
20+
m_ap_clients_csv(false)
2021
{
2122
}
2223

@@ -150,6 +151,14 @@ void Configuration::parse_output(const pugi::xml_node& p_output)
150151
m_probe_csv = true;
151152
}
152153
}
154+
else if (type.compare("ap_clients_csv") == 0)
155+
{
156+
std::string enabled(p_output.attribute("enabled").as_string());
157+
if (enabled.compare("true") == 0)
158+
{
159+
m_ap_clients_csv = true;
160+
}
161+
}
153162
}
154163
else if (!path.empty())
155164
{

pi_sniffer/src/configuration.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class Configuration
6161
return m_probe_csv;
6262
}
6363

64+
bool get_ap_clients_csv() const
65+
{
66+
return m_ap_clients_csv;
67+
}
68+
6469
bool has_wep_key(const std::string& p_bssid) const;
6570

6671
bool has_wpa_key(const std::string& p_ssid) const;
@@ -103,6 +108,9 @@ class Configuration
103108

104109
//! indicates if we should write out the probes to a csv file
105110
bool m_probe_csv;
111+
112+
//! indicates if we should write out the ap client csv file
113+
bool m_ap_clients_csv;
106114
};
107115

108116
#endif

pi_sniffer/src/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ namespace
8585
IEEE80211 link_layer;
8686
PCAP file_input(p_file);
8787
file_input.initialize();
88+
89+
std::cout << "Reading: " << p_file << std::endl;
8890
while (file_input.get_packet(p_packet))
8991
{
9092
link_layer.handle_packet(p_packet);
@@ -283,6 +285,10 @@ int main(int p_argCount, char* p_argArray[])
283285
{
284286
packet.write_probe_csv_output(packet.m_startTime);
285287
}
288+
if (packet.get_const_config().get_ap_clients_csv())
289+
{
290+
packet.write_ap_clients_csv_output(packet.m_startTime);
291+
}
286292
}
287293
}
288294

@@ -307,6 +313,10 @@ int main(int p_argCount, char* p_argArray[])
307313
{
308314
packet.write_probe_csv_output(packet.m_startTime);
309315
}
316+
if (packet.get_const_config().get_ap_clients_csv())
317+
{
318+
packet.write_ap_clients_csv_output(packet.m_startTime);
319+
}
310320
}
311321
catch (const std::runtime_error& e)
312322
{

pi_sniffer/src/packet.cpp

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ void Packet::write_wigle_output(const std::string& p_time)
233233
char buffer[32] = {0};
234234
std::string time;
235235

236-
std::string most;
237-
std::size_t count = 0;
238-
239236
// loop over the router
240237
boost::upgrade_lock<boost::shared_mutex> readLock(m_router_mutex);
241238
for (boost::ptr_unordered_map<boost::uint64_t, AP>::iterator it = m_devices.begin();
@@ -251,12 +248,6 @@ void Packet::write_wigle_output(const std::string& p_time)
251248
os << it->second->get_ssid() << ",";
252249
}
253250

254-
if (it->second->get_client_count() > count && !it->second->get_ssid().empty() && it->second->get_ssid() != "<Unknown>")
255-
{
256-
count = it->second->get_client_count();
257-
most.assign(it->second->get_ssid());
258-
}
259-
260251
if (it->second->get_encryption().find("/") != std::string::npos)
261252
{
262253
os << "[WPA-PSK][WPA2-PSK]";
@@ -287,7 +278,6 @@ void Packet::write_wigle_output(const std::string& p_time)
287278
os << "WIFI" << "\n";
288279
}
289280

290-
std::cout << most << ":" << count << std::endl;
291281
// close it
292282
wigle_output.close();
293283
}
@@ -361,6 +351,50 @@ void Packet::write_probe_csv_output(const std::string& p_time)
361351
client_output.close();
362352
}
363353

354+
void Packet::write_ap_clients_csv_output(const std::string& p_time)
355+
{
356+
std::string filename(m_configuration.get_output_path() + "pi_sniffer_ap_clients_" + p_time + ".csv");
357+
358+
// create the file
359+
std::filebuf ap_clients_output;
360+
ap_clients_output.open(filename, std::ios::out);
361+
if (!ap_clients_output.is_open())
362+
{
363+
std::cerr << "Failed to write " << filename << std::endl;
364+
return;
365+
}
366+
std::ostream os(&ap_clients_output);
367+
368+
// data fields
369+
os << "Clients,SSID,MAC,\n";
370+
371+
// loop over the router
372+
boost::upgrade_lock<boost::shared_mutex> readLock(m_router_mutex);
373+
for (boost::ptr_unordered_map<boost::uint64_t, AP>::iterator it = m_devices.begin();
374+
it != m_devices.end(); ++it)
375+
{
376+
if (it->second->get_mac() == "00:00:00:00:00:00")
377+
{
378+
continue;
379+
}
380+
381+
os << it->second->get_client_count() << ",";
382+
if (it->second->get_ssid() == "<Unknown>")
383+
{
384+
os << ",";
385+
}
386+
else
387+
{
388+
os << it->second->get_ssid() << ",";
389+
}
390+
391+
os << it->second->get_mac() << std::endl;
392+
}
393+
394+
// close it
395+
ap_clients_output.close();
396+
}
397+
364398
void Packet::add_probe_network(const std::string& p_network, const std::string& p_client)
365399
{
366400
if (p_network.size() < 3)

pi_sniffer/src/packet.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Packet
6464
void write_kml_output(const std::string& p_time);
6565
void write_client_csv_output(const std::string& p_time);
6666
void write_probe_csv_output(const std::string& p_time);
67+
void write_ap_clients_csv_output(const std::string& p_time);
6768

6869
private:
6970

pi_sniffer/src/protocols/ieee80211.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,20 @@ bool IEEE80211::handle_packet(Packet& p_packet)
6161
return true;
6262
}
6363

64-
AP* IEEE80211::get_ap(Packet& p_packet,
65-
std::size_t p_ssid_offset)
64+
AP* IEEE80211::get_ap(Packet& p_packet, std::size_t p_ssid_offset, int p_depth)
6665
{
6766
boost::uint64_t bssid_mac = (*reinterpret_cast<const boost::uint64_t*>(
6867
p_packet.m_data + p_ssid_offset));
6968

7069
bssid_mac = (bssid_mac >> 16);
7170
bssid_mac = (bssid_mac << 16);
7271
bssid_mac = be64toh(bssid_mac);
72+
73+
if (bssid_mac == 0 && p_depth == 1)
74+
{
75+
return get_ap(p_packet, p_ssid_offset - 6, 0);
76+
}
77+
7378
return p_packet.find_ap(bssid_mac);
7479
}
7580

@@ -135,7 +140,7 @@ void IEEE80211::do_beacon(Packet& p_packet)
135140
m_pcap_out.add_packet(p_packet);
136141
}
137142

138-
AP* found = get_ap(p_packet, 14);
143+
AP* found = get_ap(p_packet, 14, 1);
139144

140145
p_packet.m_stats.increment_beacons();
141146

pi_sniffer/src/protocols/ieee80211.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IEEE80211
2020

2121
private:
2222

23-
AP* get_ap(Packet& p_packet, std::size_t p_ssid_offset);
23+
AP* get_ap(Packet& p_packet, std::size_t p_ssid_offset, int p_depth = 0);
2424

2525
Client* get_client(Packet& p_packet, std::size_t p_src_offset, bool p_associated);
2626

0 commit comments

Comments
 (0)