diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f65c72..8045ba9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ add_subdirectory(libraries) set(LIBRARIES_DIR libraries) -set(RIDDLE_SRCS ${LIBRARIES_DIR}/libRiddle.cpp ${LIBRARIES_DIR}/libRiddle.h Riddle.cpp) +set(RIDDLE_SRCS Riddle.cpp) set(CIGARETTE_SRCS ${LIBRARIES_DIR}/libCigarette.cpp ${LIBRARIES_DIR}/libCigarette.h Cigarette.cpp) set(RANGING_SRCS ${LIBRARIES_DIR}/libRanging.h ${LIBRARIES_DIR}/libRanging.cpp Ranging.cpp) set(PURSUER_SRCS ${LIBRARIES_DIR}/libPursuer.h ${LIBRARIES_DIR}/libPursuer.cpp Pursuer.cpp) diff --git a/Cigarette.cpp b/Cigarette.cpp index 92bd026..ab2054d 100644 --- a/Cigarette.cpp +++ b/Cigarette.cpp @@ -82,7 +82,7 @@ int main ( int argc, char **argv ) { packet* pkg = packet::factory ( r_packet ); - cout << "[" << std::dec << pkg->getEpoch() << " " << setfill ( '0' ) << std::setw ( 6 ) << pkg->getMillis() << "] Size: " << pkg->getPacketLength() << " byte" << endl; + cout << "[" << std::dec << pkg->getEpoch() << " " << setfill ( '0' ) << setw ( 6 ) << pkg->getMillis() << "] Size: " << pkg->getPacketLength() << " byte" << endl; cout << " From " << pkg->getSenderMac().to_string() << " to "<< pkg->getTargetMac().to_string() << endl; cout << " EtherType: 0x" << std::hex << pkg->getEtherType() << " ("<< ether_type_decode ( pkg->getEtherType() ) << ")" << endl; cout << endl; diff --git a/Project-Riddle.kdev4 b/Project-Riddle.kdev4 new file mode 100644 index 0000000..15ca0d5 --- /dev/null +++ b/Project-Riddle.kdev4 @@ -0,0 +1,3 @@ +[Project] +Manager=KDevCMakeManager +Name=Project-Riddle diff --git a/Riddle.cpp b/Riddle.cpp index d699126..3d5ddad 100644 --- a/Riddle.cpp +++ b/Riddle.cpp @@ -33,7 +33,7 @@ #include #include #include -#include "./libraries/libRiddle.h" +#include "./commons/libDump.h" #ifdef __linux__ #include @@ -109,16 +109,16 @@ int main ( int argc, char **argv ) { pcap_t *pcap_handle; if ( vm.count ( "input" ) ) { - + pcap_handle = pcap_open_offline ( vm["input"].as().c_str(), error_buffer ); - + if ( pcap_handle == NULL ) { cerr << "ERROR >> pcap_open_offline: " << error_buffer << endl; return EXIT_FAILURE; } - + cerr << ">> Reading packets from " << vm["input"].as() << endl; - + } else { string pcap_device; @@ -126,7 +126,7 @@ int main ( int argc, char **argv ) { if ( vm.count ( "iface" ) ) { pcap_device=vm["iface"].as(); } else { - + // Cerca e restituisce interfaccia char *dev=pcap_lookupdev ( error_buffer ); if ( dev!=NULL ) { @@ -135,17 +135,17 @@ int main ( int argc, char **argv ) { cerr << "ERROR >> pcap_lookupdev: " << error_buffer << endl; return EXIT_FAILURE; } - + } // Apre il device in mod promiscua pcap_handle = pcap_open_live ( pcap_device.c_str(), 4096, 1, 0, error_buffer ); - + if ( pcap_handle == NULL ) { cerr << "ERROR >> pcap_open_live: " << error_buffer << endl; return EXIT_FAILURE; } - + cerr << ">> Sniffing on device " << pcap_device << endl; } @@ -189,9 +189,12 @@ int main ( int argc, char **argv ) { maxpacket=vm["limit"].as(); } - void ( *dumper ) ( const unsigned char*,struct pcap_pkthdr ); - if ( vm.count ( "dump" ) ) dumper=hexDump; - else dumper=rawDump; + string ( *dumper ) ( string, uint64_t, uint32_t ); + if ( vm.count ( "dump" ) ) { + dumper=libDump::classicDump; + } else { + dumper=libDump::riddleDump; + } const u_char *packet; pcap_pkthdr header; @@ -202,7 +205,8 @@ int main ( int argc, char **argv ) { cerr << ">> Flow terminated" << endl; break; } - dumper ( packet, header ); + + cout << dumper ( libDump::encodeHexText( packet, header.len ), header.ts.tv_sec, header.ts.tv_usec ); if ( maxpacket!=numeric_limits::max() ) maxpacket--; } diff --git a/commons/libDump.cpp b/commons/libDump.cpp index 5138269..d221af3 100644 --- a/commons/libDump.cpp +++ b/commons/libDump.cpp @@ -33,9 +33,21 @@ #include #include #include +#include #include "libDump.h" +std::string libDump::classicDump ( std::string input, uint64_t timeEpoch, uint32_t timeMillis ) { + + std::stringstream out; + + out << "[ epoch: " << timeEpoch << " ] -> " << timeMillis << "ms" << std::endl; + out << classicDump( input ); + + return out.str(); + +} + std::string libDump::classicDump ( std::string input ) { std::stringstream out; @@ -105,6 +117,18 @@ std::string libDump::classicDump ( std::string input ) { return out.str(); } +std::string libDump::riddleDump( std::string input, uint64_t timeEpoch, uint32_t timeMillis ) { + + std::stringstream out; + + out << timeEpoch << "!"; + out << timeMillis << "!"; + out << input << std::endl; + + return out.str(); + +} + std::string libDump::decodeHexText ( std::string raw ) { std::string text; @@ -122,3 +146,17 @@ std::string libDump::decodeHexText ( std::string raw ) { return text; } + +std::string libDump::encodeHexText ( const unsigned char* text, uint32_t size ) { + + std::stringstream out; + + for ( int i = 0; i < size; i++ ) { + + out << std::setfill ( '0' ) << std::setw ( 2 ) << std::hex << (int) text[i]; + + } + + return out.str(); + +} diff --git a/commons/libDump.h b/commons/libDump.h index a5de1c0..6212cc6 100644 --- a/commons/libDump.h +++ b/commons/libDump.h @@ -32,15 +32,25 @@ #include #include #include +#include namespace libDump { /** print hex string in a format style "memory dump". */ +std::string classicDump ( std::string input, uint64_t timeEpoch, uint32_t timeMillis ); + +/** print hex string in a format style "memory dump". overload */ std::string classicDump ( std::string input ); +/** print data in riddle protocol */ +std::string riddleDump ( std::string input, uint64_t timeEpoch, uint32_t timeMillis ); + /** decode hex string using the ASCII table. */ std::string decodeHexText ( std::string raw ); +/** enccoding to hex format */ +std::string encodeHexText ( const unsigned char *text, uint32_t size); + } #endif //LIBDUMP_H diff --git a/libraries/libRiddle.cpp b/libraries/libRiddle.cpp deleted file mode 100644 index 8ae256c..0000000 --- a/libraries/libRiddle.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/** - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - - * - * Name : Project Riddle - * Author : Andrea Bontempi - * Version : 0.1 aplha - * Description : Modular Network Sniffer - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - - * - * This file is part of the project Riddle. - * - * The project Riddle 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. - * - * The project Riddle 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 project. If not, see . - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - - */ - -#include -#include -#include -#include -#include -#include "libRiddle.h" -#include "../commons/libDump.h" - -static void memPrint ( const unsigned char *start, char len, int index ) { - printf ( "0x%08x | ",index ); - int i; - for ( i=0; i32 ) && ( start[i]<128 ) ) printf ( "%c",start[i] ); - else printf ( "." ); - } - printf ( "\n" ); -} - -void hexDump ( const unsigned char *start, struct pcap_pkthdr header ) { - std::cout<16 ) { - memPrint ( start,16,index ); - header.len-=16; - start+=16; - index+=16; - } - if ( header.len>0 ) memPrint ( start,header.len,index ); - -} - -void rawDump ( const unsigned char *start, struct pcap_pkthdr header ) { - std::cout<. - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - - */ - -#ifndef LIBRIDDLE_H -#define LIBRIDDLE_H - -#include - -/* struct pcap_pkthdr { - * struct timeval ts; time stamp - * bpf_u_int32 caplen; length of portion present - * bpf_u_int32; lebgth this packet (off wire) - } * - */ - -/* Funzioni per la stampa su schermo dei dati in formato esadecimale */ -void hexDump ( const unsigned char *start, struct pcap_pkthdr header ); -void rawDump ( const unsigned char *start, struct pcap_pkthdr header ); - -#endif //LIBRIDDLE_H