diff --git a/backend/src/http_packet.cpp b/backend/src/http_packet.cpp index eba3526..f41466a 100644 --- a/backend/src/http_packet.cpp +++ b/backend/src/http_packet.cpp @@ -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; @@ -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; diff --git a/backend/src/http_packet.hpp b/backend/src/http_packet.hpp index f3371ee..91673f1 100644 --- a/backend/src/http_packet.hpp +++ b/backend/src/http_packet.hpp @@ -29,6 +29,7 @@ #include #include #include "http-parser/http_parser.h" +#include "wifi_info.hpp" using namespace std; @@ -50,7 +51,7 @@ typedef map 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(); @@ -65,6 +66,8 @@ class HttpPacket { string cookies(); HeaderMap headers(); + + WifiInfo wifi_info(); private: http_parser m_parser; @@ -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); diff --git a/backend/src/http_sniffer.cpp b/backend/src/http_sniffer.cpp index a5757ee..c1986d2 100644 --- a/backend/src/http_sniffer.cpp +++ b/backend/src/http_sniffer.cpp @@ -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; @@ -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) */ @@ -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); @@ -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); } diff --git a/backend/src/main.cpp b/backend/src/main.cpp index 8840a13..6c8d5d9 100644 --- a/backend/src/main.cpp +++ b/backend/src/main.cpp @@ -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; diff --git a/backend/src/tcpip.h b/backend/src/tcpip.h index ed30fd0..32990c7 100644 --- a/backend/src/tcpip.h +++ b/backend/src/tcpip.h @@ -21,6 +21,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#ifndef TCPIP_H +#define TCPIP_H + #include #include #include @@ -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; @@ -172,3 +175,5 @@ struct sniff_tcp { #undef PACK_START #undef PACK_END + +#endif diff --git a/backend/src/wifi_info.hpp b/backend/src/wifi_info.hpp new file mode 100644 index 0000000..f9ef86f --- /dev/null +++ b/backend/src/wifi_info.hpp @@ -0,0 +1,95 @@ +// +// wifi_info.hpp: 802.11 header processing +// Part of the Firesheep project. +// +// Copyright (C) 2010 Eric Butler +// +// Authors: +// Eric Butler +// +// 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 . + +#ifndef WIFI_INFO_H +#define WIFI_INFO_H + +#include +#include +#include "tcpip.h" + +using namespace std; + +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