Compare commits
	
		
			19 Commits
		
	
	
		
			f1e8069afd
			...
			4f1cb82f46
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4f1cb82f46 | |||
| b7b7f6edbb | |||
| 8d67321d4b | |||
| 61f3c432c9 | |||
| 52119fe3cd | |||
| f938f8dd53 | |||
| 5b8a330e69 | |||
| 35e71ef44e | |||
| 8ef6318a56 | |||
| 9301c4e0fd | |||
| 4d8597b1d6 | |||
| 3c379a1a80 | |||
| 6710442067 | |||
| e191085cbd | |||
| f834ec7134 | |||
| 035491668a | |||
| 16028daf10 | |||
| 1ed9c84802 | |||
| a0ae919614 | 
| @ -4,8 +4,15 @@ | ||||
| #include "./packet.hpp" | ||||
| #include <string> | ||||
| 
 | ||||
| class BeaconPacket : Packet{ | ||||
|     std::string SSID; | ||||
| class BeaconPacket : public Packet{ | ||||
| public: | ||||
|     BeaconPacket() | ||||
|     {} | ||||
|     BeaconPacket(const Packet &packet) | ||||
|         : Packet(packet) | ||||
|     {} | ||||
| 
 | ||||
|     std::string ssid; | ||||
| }; | ||||
| 
 | ||||
| #endif /* FDDB997A_BCD3_4056_BFEA_9FF6A548DACF */ | ||||
|  | ||||
| @ -15,6 +15,18 @@ enum PacketType { | ||||
|     NoData, | ||||
|     Unknown | ||||
| }; | ||||
| const std::array<const char*, 10> PACKET_TYPE_NAMES({{ | ||||
|     "Beacon", | ||||
|     "Probe Request", | ||||
|     "Probe Response", | ||||
|     "Data", | ||||
|     "Request to send", | ||||
|     "Clear to send", | ||||
|     "Acknowledgment", | ||||
|     "BlockAcknowledgment", | ||||
|     "NoData", | ||||
|     "Unknown" | ||||
| }}); | ||||
| 
 | ||||
| struct Packet { | ||||
|     uint64_t timestampMicros; | ||||
|  | ||||
| @ -4,8 +4,15 @@ | ||||
| #include "./packet.hpp" | ||||
| #include <string> | ||||
| 
 | ||||
| class ProbeRequestPacket : Packet{ | ||||
|     std::string requestSSID; | ||||
| class ProbeRequestPacket : public Packet{ | ||||
| public: | ||||
|     ProbeRequestPacket() | ||||
|     {} | ||||
|     ProbeRequestPacket(const Packet &packet) | ||||
|         : Packet(packet) | ||||
|     {} | ||||
| 
 | ||||
|     std::string requestSsid; | ||||
| }; | ||||
| 
 | ||||
| #endif /* CD2BF199_8153_4F10_A85C_50883FAD66A8 */ | ||||
|  | ||||
							
								
								
									
										18
									
								
								DTO/probeResponsePacket.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								DTO/probeResponsePacket.hpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| #ifndef B199B4B3_BE27_4F0C_8DBE_5E78580AB1A9 | ||||
| #define B199B4B3_BE27_4F0C_8DBE_5E78580AB1A9 | ||||
| 
 | ||||
| #include "./packet.hpp" | ||||
| #include <string> | ||||
| 
 | ||||
| class ProbeResponsePacket : public Packet{ | ||||
| public: | ||||
|     ProbeResponsePacket() | ||||
|     {} | ||||
|     ProbeResponsePacket(const Packet &packet) | ||||
|         : Packet(packet) | ||||
|     {} | ||||
| 
 | ||||
|     std::string responseSsid; | ||||
| }; | ||||
| 
 | ||||
| #endif /* B199B4B3_BE27_4F0C_8DBE_5E78580AB1A9 */ | ||||
| @ -1,17 +0,0 @@ | ||||
| #ifndef EFFCCB40_3639_4BD4_9649_302F05987909 | ||||
| #define EFFCCB40_3639_4BD4_9649_302F05987909 | ||||
| 
 | ||||
| #include <future> | ||||
| #include <string.h> | ||||
| #include "bufHandler.hpp" | ||||
| 
 | ||||
| void asyncHandler(char *buf){ | ||||
|     // Create a copy of buf for our thread
 | ||||
|     char bufCopy[265]; | ||||
|     strcpy(bufCopy, buf); | ||||
| 
 | ||||
|     // \/ Surpress unused warning
 | ||||
|     (void)std::async(std::launch::async, bufHandler, bufCopy); | ||||
| } | ||||
| 
 | ||||
| #endif /* EFFCCB40_3639_4BD4_9649_302F05987909 */ | ||||
| @ -1,22 +1,28 @@ | ||||
| #ifndef C251BA62_6D80_4033_86B6_61F184E6F250 | ||||
| #define C251BA62_6D80_4033_86B6_61F184E6F250 | ||||
| 
 | ||||
| #include <future> | ||||
| #include <string> | ||||
| #include "textPacketHandler.hpp" | ||||
| 
 | ||||
| using namespace std::string_literals; | ||||
| 
 | ||||
| std::vector<std::string> buffer; | ||||
| void bufHandler(char *buf){ | ||||
| void bufHandler(const char *buf){ | ||||
|     std::string line = buf; | ||||
|     // Remove last char which is \n
 | ||||
|     line = line.substr(0, line.size()-1); | ||||
| 
 | ||||
|     // When first char of buf has text (no tab), we got a new packet
 | ||||
|     if(buf[0] != '\t'){ | ||||
|         // Submit the just-read text-packet
 | ||||
|         if(buffer.size() != 0) textPacketHandler(buffer); | ||||
|         buffer = std::vector<std::string>(); | ||||
|         // Submit the just-read text-packet in a new thread
 | ||||
|         if(buffer.size() != 0) { | ||||
|             (void)std::async(std::launch::async, textPacketHandler, buffer); | ||||
|         } | ||||
|         buffer = {line}; | ||||
|     } | ||||
| 
 | ||||
|     // Append part-packet
 | ||||
|     buffer.push_back(buf); | ||||
|     else | ||||
|         buffer.push_back(line);     // Append part-packet
 | ||||
| } | ||||
| 
 | ||||
| #endif /* C251BA62_6D80_4033_86B6_61F184E6F250 */ | ||||
|  | ||||
| @ -3,16 +3,20 @@ | ||||
| 
 | ||||
| #include <string> | ||||
| #include "../DTO/packet.hpp" | ||||
| #include "../DTO/beaconPacket.hpp" | ||||
| #include "../DTO/probeRequestPacket.hpp" | ||||
| #include "../DTO/probeResponsePacket.hpp" | ||||
| #include <vector> | ||||
| #include <sstream> | ||||
| #include <locale> | ||||
| #include <iomanip> | ||||
| #include "../helper/split.hpp" | ||||
| #include "../helper/string-helper.hpp" | ||||
| #include "../helper/timestampConvert.hpp" | ||||
| #include "../helper/find.hpp" | ||||
| #include "../helper/vector-stats.hpp" | ||||
| #include <unordered_map> | ||||
| 
 | ||||
| using namespace std::string_literals; | ||||
| 
 | ||||
| const std::unordered_map<std::string, PacketType> PACKET_TYPE_MAP({ | ||||
|     {"Beacon", PacketType::Beacon}, | ||||
|     {"Probe Request", PacketType::ProbeRequest}, | ||||
| @ -24,11 +28,20 @@ const std::unordered_map<std::string, PacketType> PACKET_TYPE_MAP({ | ||||
|     {"BA", PacketType::BlockAcknowledgment} | ||||
| }); | ||||
| 
 | ||||
| void textPacketHandler(std::vector<std::string> textPacket){ | ||||
| void parseHeader(Packet &packet, const std::vector<std::string> &textPacket); | ||||
| void parsePayload(Packet &packet, const std::vector<std::string> &textPacket); | ||||
| 
 | ||||
| void textPacketHandler(const std::vector<std::string> textPacket){ | ||||
|     /// Here we have to parse the packet
 | ||||
|     // Create empty packet
 | ||||
|     Packet packet; | ||||
| 
 | ||||
|     parseHeader(packet, textPacket); | ||||
|     parsePayload(packet, textPacket); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void parseHeader(Packet &packet, const std::vector<std::string> &textPacket){ | ||||
|     const std::string textHeader = textPacket[0]; | ||||
| 
 | ||||
|     const std::vector<std::string> headerData = split(textHeader, ' '); | ||||
| @ -44,8 +57,14 @@ void textPacketHandler(std::vector<std::string> textPacket){ | ||||
|     packet.frequency = std::stoi(headerData[frequencyIndex]); | ||||
| 
 | ||||
|     int signalIndex = findIs(headerData, "signal", 1, 1); | ||||
|     if(signalIndex != -1){ | ||||
|     std::string signalText = headerData[signalIndex].substr(0, 3); | ||||
|     packet.signal = std::stoi(signalText); | ||||
|     } | ||||
|     else { | ||||
|         fprintf(stderr, "Missing signal-data!\n"); | ||||
|         packet.signal = -100; | ||||
|     } | ||||
| 
 | ||||
|     // Addresses seem complicated at first, but just have many fields which might be available.
 | ||||
|     // SA and DA are src- and dst-Addresses
 | ||||
| @ -62,8 +81,8 @@ void textPacketHandler(std::vector<std::string> textPacket){ | ||||
|     int bssidIndex = findContains(headerData, "BSSID:", 1); | ||||
|     std::string bssidAddr = (bssidIndex != -1) ? headerData[bssidIndex].substr("BSSID:"s.length()) : ""; | ||||
| 
 | ||||
|     int taIndex = findContains(headerData, "SA:", 1); | ||||
|     std::string tAddr = (taIndex != -1) ? headerData[taIndex].substr("SA:"s.length()) : ""; | ||||
|     int taIndex = findContains(headerData, "TA:", 1); | ||||
|     std::string tAddr = (taIndex != -1) ? headerData[taIndex].substr("TA:"s.length()) : ""; | ||||
| 
 | ||||
|     int raIndex = findContains(headerData, "RA:", 1); | ||||
|     std::string rAddr = (raIndex != -1) ? headerData[raIndex].substr("RA:"s.length()) : ""; | ||||
| @ -92,10 +111,72 @@ void textPacketHandler(std::vector<std::string> textPacket){ | ||||
| 
 | ||||
|         // If type is in map, use map-value, otherwise keep default
 | ||||
|         if(PACKET_TYPE_MAP.find(textType) != PACKET_TYPE_MAP.end()) | ||||
|             type = PACKET_TYPE_MAP[textType]; | ||||
|             type = PACKET_TYPE_MAP.at(textType); | ||||
|          | ||||
|         if(type == PacketType::Unknown){ | ||||
|             fprintf(stderr, "Unknown package-type: %s\n", textType.c_str()); | ||||
|         } | ||||
|     } | ||||
|     packet.type = type; | ||||
| 
 | ||||
|     // Read data for specializations
 | ||||
|     if(type == PacketType::Beacon){ | ||||
|         // Create BeaconPacket from packet
 | ||||
|         BeaconPacket beaconPacket = BeaconPacket(packet); | ||||
|         packet = beaconPacket;      // Overwrite packet
 | ||||
| 
 | ||||
|         // Find ssid
 | ||||
|         int start = textHeader.find('(')+1; | ||||
|         std::string ssid = textHeader.substr(start, textHeader.find(')')-start); | ||||
| 
 | ||||
|         // Write to packet
 | ||||
|         beaconPacket.ssid = ssid; | ||||
|     } | ||||
|     else if (type == PacketType::ProbeRequest){ | ||||
|         // Create ProbeRequestPacket from packet
 | ||||
|         ProbeRequestPacket probeRequestPacket = ProbeRequestPacket(packet); | ||||
|         packet = probeRequestPacket;      // Overwrite packet
 | ||||
| 
 | ||||
|         // Find probe-request
 | ||||
|         int start = textHeader.find('(')+1; | ||||
|         std::string requestSsid = textHeader.substr(start, textHeader.find(')')-start); | ||||
| 
 | ||||
|         // Write to packet
 | ||||
|         probeRequestPacket.requestSsid = requestSsid; | ||||
|     } | ||||
|     else if (type == PacketType::ProbeResponse){ | ||||
|         // Create ProbeResponsePacket from packet
 | ||||
|         ProbeResponsePacket probeResponsePacket = ProbeResponsePacket(packet); | ||||
|         packet = probeResponsePacket;      // Overwrite packet
 | ||||
| 
 | ||||
|         // Find probe-request
 | ||||
|         int start = textHeader.find('(')+1; | ||||
|         std::string responseSsid = textHeader.substr(start, textHeader.find(')')-start); | ||||
| 
 | ||||
|         // Write to packet
 | ||||
|         probeResponsePacket.responseSsid = responseSsid; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void parsePayload(Packet &packet, const std::vector<std::string> &textPacket){ | ||||
| 
 | ||||
|     // Expect max of 16byte per line of payload
 | ||||
|     unsigned int payloadSize = 16*(textPacket.size()-1); | ||||
| 
 | ||||
|     // Go through last line
 | ||||
|     int line = textPacket.size()-1, charPos; | ||||
|     for(int f=0; f<8*2; ++f){ | ||||
|         charPos = 10 + (f/2.0*5); | ||||
| 
 | ||||
|         if(textPacket[line][charPos] == ' ') {    // When our char is space, no more data is present
 | ||||
|             // Set size
 | ||||
|             payloadSize = 16*(textPacket.size()-2)+f; | ||||
|             break; | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     // 
 | ||||
|     packet.payloadSize = payloadSize; | ||||
| } | ||||
| 
 | ||||
| #endif /* EE781A91_6D07_47AC_B3C4_F99E29F3731F */ | ||||
|  | ||||
| @ -8,8 +8,8 @@ | ||||
| /// @param cmd is the command
 | ||||
| /// @param handler is the handler(char*)-function
 | ||||
| /// @return Return-code form command
 | ||||
| int exec(const char* cmd, void (*handler)(char*) = nullptr){ | ||||
|     const int buf_size = 256; | ||||
| int exec(const char* cmd, void (*handler)(const char*) = nullptr){ | ||||
|     const int buf_size = 512; | ||||
|     char buf[buf_size]; | ||||
| 
 | ||||
|     // Open execution-pipe
 | ||||
|  | ||||
| @ -1,6 +1,10 @@ | ||||
| #ifndef F7CFE6A7_34BF_4E04_94CF_DB8374980631 | ||||
| #define F7CFE6A7_34BF_4E04_94CF_DB8374980631 | ||||
| 
 | ||||
| #include <vector> | ||||
| #include <string> | ||||
| #include <sstream> | ||||
| 
 | ||||
| std::vector<std::string> split(const std::string& s, char delimiter) | ||||
| { | ||||
|    std::vector<std::string> tokens; | ||||
| @ -13,4 +17,18 @@ std::vector<std::string> split(const std::string& s, char delimiter) | ||||
|    return tokens; | ||||
| } | ||||
| 
 | ||||
| char hex_char_to_int(const char &c) { | ||||
|     unsigned char result = 0; | ||||
|     if( ('0' <= c) && (c <= '9') ) { | ||||
|         result = c - '0'; | ||||
|     } | ||||
|     else if( ('A' <= c) && (c <= 'F') ) { | ||||
|         result = 10 + c - 'A'; | ||||
|     } | ||||
|     else if( ('a' <= c) && (c <= 'f') ) { | ||||
|         result = 10 + c - 'a'; | ||||
|     } | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| #endif /* F7CFE6A7_34BF_4E04_94CF_DB8374980631 */ | ||||
							
								
								
									
										4
									
								
								main.cpp
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.cpp
									
									
									
									
									
								
							| @ -1,7 +1,7 @@ | ||||
| #include <stdio.h> | ||||
| #include <string> | ||||
| #include "./helper/exec.hpp" | ||||
| #include "./handler/asyncHandler.hpp" | ||||
| #include "./handler/bufHandler.hpp" | ||||
| 
 | ||||
| const std::string tcpdump_baseCmd = "tcpdump -vvv -e -n -X -s0 -i "; | ||||
| 
 | ||||
| @ -15,7 +15,7 @@ int main(int argc, char *args[]){ | ||||
|         exit(1); | ||||
|     } | ||||
|      | ||||
|     int exitCode = exec(tcpdump_cmd.c_str(), &asyncHandler); | ||||
|     int exitCode = exec(tcpdump_cmd.c_str(), &bufHandler); | ||||
| 
 | ||||
|     if(exitCode){ | ||||
|         fprintf(stderr, "\ntcpdump exited with non-zero ExitCode: %d\n Something went wrong! Check tcpdump-output for more information.\n", exitCode); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user