Skip to content

Commit 08b849f

Browse files
committed
Initial incomplete work to include wifi info in JSON data.
1 parent a8205bb commit 08b849f

File tree

6 files changed

+144
-23
lines changed

6 files changed

+144
-23
lines changed

backend/src/http_packet.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
#include "http_packet.hpp"
2424

25-
HttpPacket::HttpPacket(string from, string to)
26-
: m_from(from), m_to(to), m_complete(false)
25+
HttpPacket::HttpPacket(string from, string to, WifiInfo info)
26+
: m_from(from), m_to(to), m_complete(false), m_wifi_info(info)
2727
{
2828
memset(&m_settings, 0, sizeof(m_settings));
2929
m_settings.on_header_field = header_field_cb_wrapper;
@@ -96,6 +96,11 @@ HeaderMap HttpPacket::headers()
9696
return m_headers;
9797
}
9898

99+
WifiInfo HttpPacket::wifi_info()
100+
{
101+
return m_wifi_info;
102+
}
103+
99104
void HttpPacket::add_header(string name, string value)
100105
{
101106
HeaderMap::iterator iter;

backend/src/http_packet.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <vector>
3030
#include <boost/algorithm/string.hpp>
3131
#include "http-parser/http_parser.h"
32+
#include "wifi_info.hpp"
3233

3334
using namespace std;
3435

@@ -50,7 +51,7 @@ typedef map<string, string> HeaderMap;
5051

5152
class HttpPacket {
5253
public:
53-
HttpPacket(string from, string to);
54+
HttpPacket(string from, string to, WifiInfo wifiInfo);
5455
bool parse(const char *payload, int payload_size);
5556

5657
bool isComplete();
@@ -65,6 +66,8 @@ class HttpPacket {
6566
string cookies();
6667

6768
HeaderMap headers();
69+
70+
WifiInfo wifi_info();
6871

6972
private:
7073
http_parser m_parser;
@@ -78,6 +81,7 @@ class HttpPacket {
7881
string m_tmp_header_name;
7982
string m_tmp_header_value;
8083
bool m_complete;
84+
WifiInfo m_wifi_info;
8185

8286
HTTP_PARSER_DATA_CALLBACK(url);
8387
HTTP_PARSER_DATA_CALLBACK(header_field);

backend/src/http_sniffer.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ void HttpSniffer::start()
7878
void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *packet)
7979
{
8080
/* Declare pointers to packet headers */
81-
const struct radiotap_header *radiotap; /* The Radiotap header */
82-
const struct wifi_header *hdr80211; /* The 802.11 header */
83-
const struct snap_llc_header *snap_llc; /* The SNAP LLC header */
84-
const struct sniff_ethernet *ethernet; /* The Ethernet header [1] */
85-
const struct sniff_ip *ip = NULL; /* The IP header */
86-
const struct sniff_ip6 *ip6 = NULL; /* The IPv6 header */
87-
const struct sniff_tcp *tcp; /* The TCP header */
88-
const char *payload; /* Packet payload */
81+
const struct radiotap_header *radiotap; /* The Radiotap header */
82+
const struct wifi_header *hdr80211; /* The 802.11 header */
83+
const struct snap_llc_header *snap_llc; /* The SNAP LLC header */
84+
const struct sniff_ethernet *ethernet; /* The Ethernet header [1] */
85+
const struct sniff_ip *ip = NULL; /* The IP header */
86+
const struct sniff_ip6 *ip6 = NULL; /* The IPv6 header */
87+
const struct sniff_tcp *tcp; /* The TCP header */
88+
const char *payload; /* Packet payload */
8989

9090
/* Declare header lengths */
91-
int size_ip; /* Size of IP header in bytes */
92-
int size_tcp; /* Size of TCP header << */
93-
int size_payload; /* Size of data in bytes << */
94-
int size_radiotap; /* Size of Radiotap header << */
95-
int size_80211; /* Size of 802.11 header << */
91+
int size_ip; /* Size of IP header in bytes */
92+
int size_tcp; /* Size of TCP header */
93+
int size_payload; /* Size of data in bytes */
94+
int size_radiotap; /* Size of Radiotap header */
95+
int size_80211; /* Size of 802.11 header */
9696

9797
/* Layer 3 header offset */
9898
int l3hdr_off = SIZE_ETHERNET;
@@ -105,10 +105,12 @@ void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *pac
105105
string from;
106106
string to;
107107

108+
WifiInfo wifi_info;
109+
108110
/* 802.11 monitor support... */
109111
if (m_wifimon) {
110112
/* Get Radiotap header length (variable) */
111-
radiotap = (struct radiotap_header*)(packet);
113+
radiotap = (struct radiotap_header*)(packet);
112114
size_radiotap = radiotap->it_len;
113115

114116
/* Calculate 802.11 header length (variable) */
@@ -146,6 +148,8 @@ void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *pac
146148
return;
147149
}
148150
ip_len = ntohs(ip->ip_len);
151+
152+
wifi_info = WifiInfo(hdr80211, radiotap);
149153
} else {
150154
/* Define ethernet header */
151155
ethernet = (struct sniff_ethernet*)(packet);
@@ -222,9 +226,9 @@ void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *pac
222226
PacketCacheMap::iterator iter;
223227
iter = m_pending_packets.find(key);
224228

225-
if (iter == m_pending_packets.end())
226-
http_packet = new HttpPacket(from, to);
227-
else {
229+
if (iter == m_pending_packets.end()) {
230+
http_packet = new HttpPacket(from, to, wifi_info);
231+
} else {
228232
http_packet = iter->second;
229233
m_pending_packets.erase(iter);
230234
}

backend/src/main.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ void received_packet(HttpPacket *packet)
105105
data_obj.push_back(json_spirit::Pair("host", packet->host()));
106106
data_obj.push_back(json_spirit::Pair("cookies", packet->cookies()));
107107
data_obj.push_back(json_spirit::Pair("userAgent", packet->user_agent()));
108+
109+
if (!packet->wifi_info().is_empty()) {
110+
json_spirit::Object wifi_info_obj;
111+
wifi_info_obj.push_back(json_spirit::Pair("bssid", packet->wifi_info().bssid()));
112+
wifi_info_obj.push_back(json_spirit::Pair("source", packet->wifi_info().source()));
113+
wifi_info_obj.push_back(json_spirit::Pair("dest", packet->wifi_info().dest()));
114+
data_obj.push_back(json_spirit::Pair("wifi_info", wifi_info_obj));
115+
}
108116

109117
string data = json_spirit::write_string(json_spirit::Value(data_obj), false);
110118
cout << data << endl;

backend/src/tcpip.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// You should have received a copy of the GNU General Public License
2222
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2323

24+
#ifndef TCPIP_H
25+
#define TCPIP_H
26+
2427
#include <sys/types.h>
2528
#include <netinet/in.h>
2629
#include <arpa/inet.h>
@@ -71,9 +74,9 @@ PACK_START
7174
struct wifi_header {
7275
u_int16_t fc;
7376
u_int16_t duration;
74-
u_int8_t da[6];
75-
u_int8_t sa[6];
76-
u_int8_t bssid[6];
77+
u_int8_t addr1[6];
78+
u_int8_t addr2[6];
79+
u_int8_t addr3[6];
7780
u_int16_t seq_ctrl;
7881
}PACK_END;
7982

@@ -172,3 +175,5 @@ struct sniff_tcp {
172175

173176
#undef PACK_START
174177
#undef PACK_END
178+
179+
#endif

backend/src/wifi_info.hpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// wifi_info.hpp: 802.11 header processing
3+
// Part of the Firesheep project.
4+
//
5+
// Copyright (C) 2010 Eric Butler
6+
//
7+
// Authors:
8+
// Eric Butler <[email protected]>
9+
//
10+
// This program is free software: you can redistribute it and/or modify
11+
// it under the terms of the GNU General Public License as published by
12+
// the Free Software Foundation, either version 3 of the License, or
13+
// (at your option) any later version.
14+
//
15+
// This program is distributed in the hope that it will be useful,
16+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
// GNU General Public License for more details.
19+
//
20+
// You should have received a copy of the GNU General Public License
21+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
23+
#ifndef WIFI_INFO_H
24+
#define WIFI_INFO_H
25+
26+
#include <string>
27+
#include <cstdio>
28+
#include "tcpip.h"
29+
30+
using namespace std;
31+
32+
class WifiInfo
33+
{
34+
public:
35+
WifiInfo() : m_is_empty(true) {}
36+
37+
WifiInfo(const wifi_header *wifi, const radiotap_header *radiotap) : m_is_empty(false) {
38+
string addr1_str = macToString(wifi->addr1);
39+
string addr2_str = macToString(wifi->addr2);
40+
string addr3_str = macToString(wifi->addr3);
41+
42+
// FIXME: This might not be right.
43+
if (FC_FROM_DS(wifi->fc) && (!FC_TO_DS(wifi->fc))) {
44+
m_da = addr1_str;
45+
m_bssid = addr2_str;
46+
m_sa = addr3_str;
47+
} else if ((!FC_FROM_DS(wifi->fc)) && (!FC_TO_DS(wifi->fc))) {
48+
m_da = addr1_str;
49+
m_sa = addr2_str;
50+
m_bssid = addr3_str;
51+
} else if ((!FC_FROM_DS(wifi->fc)) && (FC_TO_DS(wifi->fc))) {
52+
m_bssid = addr1_str;
53+
m_sa = addr2_str;
54+
m_da = addr3_str;
55+
} else if (FC_FROM_DS(wifi->fc) && (FC_TO_DS(wifi->fc))) {
56+
// FIXME: ???
57+
throw runtime_error("Not implemented");
58+
} else {
59+
throw runtime_error("Impossible exception.");
60+
}
61+
62+
// FIXME: Parse radiotap header, extract channel info.
63+
}
64+
65+
bool is_empty() {
66+
return m_is_empty;
67+
}
68+
69+
string bssid() {
70+
return m_bssid;
71+
}
72+
73+
string source() {
74+
return m_sa;
75+
}
76+
77+
string dest() {
78+
return m_da;
79+
}
80+
81+
private:
82+
bool m_is_empty;
83+
string m_bssid;
84+
string m_sa;
85+
string m_da;
86+
87+
// FIXME: Not good enough?
88+
string macToString(const u_int8_t mac[]) const {
89+
char buf[18];
90+
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
91+
return string(buf);
92+
}
93+
};
94+
95+
#endif

0 commit comments

Comments
 (0)