Skip to content

Commit

Permalink
Initial incomplete work to include wifi info in JSON data.
Browse files Browse the repository at this point in the history
  • Loading branch information
codebutler committed Nov 18, 2010
1 parent a8205bb commit 08b849f
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 23 deletions.
9 changes: 7 additions & 2 deletions backend/src/http_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

#include "http_packet.hpp"

HttpPacket::HttpPacket(string from, string to)
: m_from(from), m_to(to), m_complete(false)
HttpPacket::HttpPacket(string from, string to, WifiInfo info)
: m_from(from), m_to(to), m_complete(false), m_wifi_info(info)
{
memset(&m_settings, 0, sizeof(m_settings));
m_settings.on_header_field = header_field_cb_wrapper;
Expand Down Expand Up @@ -96,6 +96,11 @@ HeaderMap HttpPacket::headers()
return m_headers;
}

WifiInfo HttpPacket::wifi_info()
{
return m_wifi_info;
}

void HttpPacket::add_header(string name, string value)
{
HeaderMap::iterator iter;
Expand Down
6 changes: 5 additions & 1 deletion backend/src/http_packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <vector>
#include <boost/algorithm/string.hpp>
#include "http-parser/http_parser.h"
#include "wifi_info.hpp"

using namespace std;

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

class HttpPacket {
public:
HttpPacket(string from, string to);
HttpPacket(string from, string to, WifiInfo wifiInfo);
bool parse(const char *payload, int payload_size);

bool isComplete();
Expand All @@ -65,6 +66,8 @@ class HttpPacket {
string cookies();

HeaderMap headers();

WifiInfo wifi_info();

private:
http_parser m_parser;
Expand All @@ -78,6 +81,7 @@ class HttpPacket {
string m_tmp_header_name;
string m_tmp_header_value;
bool m_complete;
WifiInfo m_wifi_info;

HTTP_PARSER_DATA_CALLBACK(url);
HTTP_PARSER_DATA_CALLBACK(header_field);
Expand Down
38 changes: 21 additions & 17 deletions backend/src/http_sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ void HttpSniffer::start()
void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *packet)
{
/* Declare pointers to packet headers */
const struct radiotap_header *radiotap; /* The Radiotap header */
const struct wifi_header *hdr80211; /* The 802.11 header */
const struct snap_llc_header *snap_llc; /* The SNAP LLC header */
const struct sniff_ethernet *ethernet; /* The Ethernet header [1] */
const struct sniff_ip *ip = NULL; /* The IP header */
const struct sniff_ip6 *ip6 = NULL; /* The IPv6 header */
const struct sniff_tcp *tcp; /* The TCP header */
const char *payload; /* Packet payload */
const struct radiotap_header *radiotap; /* The Radiotap header */
const struct wifi_header *hdr80211; /* The 802.11 header */
const struct snap_llc_header *snap_llc; /* The SNAP LLC header */
const struct sniff_ethernet *ethernet; /* The Ethernet header [1] */
const struct sniff_ip *ip = NULL; /* The IP header */
const struct sniff_ip6 *ip6 = NULL; /* The IPv6 header */
const struct sniff_tcp *tcp; /* The TCP header */
const char *payload; /* Packet payload */

/* Declare header lengths */
int size_ip; /* Size of IP header in bytes */
int size_tcp; /* Size of TCP header << */
int size_payload; /* Size of data in bytes << */
int size_radiotap; /* Size of Radiotap header << */
int size_80211; /* Size of 802.11 header << */
int size_ip; /* Size of IP header in bytes */
int size_tcp; /* Size of TCP header */
int size_payload; /* Size of data in bytes */
int size_radiotap; /* Size of Radiotap header */
int size_80211; /* Size of 802.11 header */

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

WifiInfo wifi_info;

/* 802.11 monitor support... */
if (m_wifimon) {
/* Get Radiotap header length (variable) */
radiotap = (struct radiotap_header*)(packet);
radiotap = (struct radiotap_header*)(packet);
size_radiotap = radiotap->it_len;

/* Calculate 802.11 header length (variable) */
Expand Down Expand Up @@ -146,6 +148,8 @@ void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *pac
return;
}
ip_len = ntohs(ip->ip_len);

wifi_info = WifiInfo(hdr80211, radiotap);
} else {
/* Define ethernet header */
ethernet = (struct sniff_ethernet*)(packet);
Expand Down Expand Up @@ -222,9 +226,9 @@ void HttpSniffer::got_packet(const struct pcap_pkthdr *header, const u_char *pac
PacketCacheMap::iterator iter;
iter = m_pending_packets.find(key);

if (iter == m_pending_packets.end())
http_packet = new HttpPacket(from, to);
else {
if (iter == m_pending_packets.end()) {
http_packet = new HttpPacket(from, to, wifi_info);
} else {
http_packet = iter->second;
m_pending_packets.erase(iter);
}
Expand Down
8 changes: 8 additions & 0 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ void received_packet(HttpPacket *packet)
data_obj.push_back(json_spirit::Pair("host", packet->host()));
data_obj.push_back(json_spirit::Pair("cookies", packet->cookies()));
data_obj.push_back(json_spirit::Pair("userAgent", packet->user_agent()));

if (!packet->wifi_info().is_empty()) {
json_spirit::Object wifi_info_obj;
wifi_info_obj.push_back(json_spirit::Pair("bssid", packet->wifi_info().bssid()));
wifi_info_obj.push_back(json_spirit::Pair("source", packet->wifi_info().source()));
wifi_info_obj.push_back(json_spirit::Pair("dest", packet->wifi_info().dest()));
data_obj.push_back(json_spirit::Pair("wifi_info", wifi_info_obj));
}

string data = json_spirit::write_string(json_spirit::Value(data_obj), false);
cout << data << endl;
Expand Down
11 changes: 8 additions & 3 deletions backend/src/tcpip.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef TCPIP_H
#define TCPIP_H

#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Expand Down Expand Up @@ -71,9 +74,9 @@ PACK_START
struct wifi_header {
u_int16_t fc;
u_int16_t duration;
u_int8_t da[6];
u_int8_t sa[6];
u_int8_t bssid[6];
u_int8_t addr1[6];
u_int8_t addr2[6];
u_int8_t addr3[6];
u_int16_t seq_ctrl;
}PACK_END;

Expand Down Expand Up @@ -172,3 +175,5 @@ struct sniff_tcp {

#undef PACK_START
#undef PACK_END

#endif
95 changes: 95 additions & 0 deletions backend/src/wifi_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// wifi_info.hpp: 802.11 header processing
// Part of the Firesheep project.
//
// Copyright (C) 2010 Eric Butler
//
// Authors:
// Eric Butler <eric@codebutler.com>
//
// This program 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 3 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

#ifndef WIFI_INFO_H
#define WIFI_INFO_H

#include <string>
#include <cstdio>
#include "tcpip.h"

using namespace std;

This comment has been minimized.

Copy link
@CCCCDDDDDDDD

CCCCDDDDDDDD Nov 7, 2016

lñkhdfsdfhls
+


class WifiInfo
{
public:
WifiInfo() : m_is_empty(true) {}

WifiInfo(const wifi_header *wifi, const radiotap_header *radiotap) : m_is_empty(false) {
string addr1_str = macToString(wifi->addr1);
string addr2_str = macToString(wifi->addr2);
string addr3_str = macToString(wifi->addr3);

// FIXME: This might not be right.
if (FC_FROM_DS(wifi->fc) && (!FC_TO_DS(wifi->fc))) {
m_da = addr1_str;
m_bssid = addr2_str;
m_sa = addr3_str;
} else if ((!FC_FROM_DS(wifi->fc)) && (!FC_TO_DS(wifi->fc))) {
m_da = addr1_str;
m_sa = addr2_str;
m_bssid = addr3_str;
} else if ((!FC_FROM_DS(wifi->fc)) && (FC_TO_DS(wifi->fc))) {
m_bssid = addr1_str;
m_sa = addr2_str;
m_da = addr3_str;
} else if (FC_FROM_DS(wifi->fc) && (FC_TO_DS(wifi->fc))) {
// FIXME: ???
throw runtime_error("Not implemented");
} else {
throw runtime_error("Impossible exception.");
}

// FIXME: Parse radiotap header, extract channel info.
}

bool is_empty() {
return m_is_empty;
}

string bssid() {
return m_bssid;
}

string source() {
return m_sa;
}

string dest() {
return m_da;
}

private:
bool m_is_empty;
string m_bssid;
string m_sa;
string m_da;

// FIXME: Not good enough?
string macToString(const u_int8_t mac[]) const {
char buf[18];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return string(buf);
}
};

#endif

0 comments on commit 08b849f

Please sign in to comment.