From 1b0669bdccaf232db416d8c31110672ce86ff66e Mon Sep 17 00:00:00 2001 From: Juan Pablo Contreras Franco Date: Sun, 8 Oct 2023 19:29:19 +0200 Subject: [PATCH] Adds the scaffold for the HTTP 1.x reassembly example application --- Examples/CMakeLists.txt | 1 + Examples/HttpReassembler/CMakeLists.txt | 17 +++++ Examples/HttpReassembler/README.md | 14 ++++ Examples/HttpReassembler/main.cpp | 86 +++++++++++++++++++++++++ Packet++/src/HttpReassembly.cpp | 2 +- 5 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 Examples/HttpReassembler/CMakeLists.txt create mode 100644 Examples/HttpReassembler/README.md create mode 100644 Examples/HttpReassembler/main.cpp diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index d101bdd6e1..17946a2dd7 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory(ArpSpoofing) add_subdirectory(DNSResolver) add_subdirectory(DnsSpoofing) add_subdirectory(HttpAnalyzer) +add_subdirectory(HttpReassembler) add_subdirectory(IcmpFileTransfer) add_subdirectory(IPDefragUtil) add_subdirectory(IPFragUtil) diff --git a/Examples/HttpReassembler/CMakeLists.txt b/Examples/HttpReassembler/CMakeLists.txt new file mode 100644 index 0000000000..3e8802a044 --- /dev/null +++ b/Examples/HttpReassembler/CMakeLists.txt @@ -0,0 +1,17 @@ +add_executable(HttpReassembler main.cpp) + +target_link_libraries(HttpReassembler PUBLIC PcapPlusPlus::Pcap++) + +if(MSVC) + # This executable requires getopt.h not available on VStudio + target_link_libraries(HttpReassembler PRIVATE Getopt-for-Visual-Studio) +endif() + +set_target_properties(HttpReassembler PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PCAPPP_BINARY_EXAMPLES_DIR}") + +if(PCAPPP_INSTALL) + install( + TARGETS HttpReassembler + EXPORT PcapPlusPlusTargets + RUNTIME DESTINATION ${PCAPPP_INSTALL_BINDIR}) +endif() diff --git a/Examples/HttpReassembler/README.md b/Examples/HttpReassembler/README.md new file mode 100644 index 0000000000..5e1ad3d5b3 --- /dev/null +++ b/Examples/HttpReassembler/README.md @@ -0,0 +1,14 @@ +HTTP Traffic Analyzer +===================== + +This application reassembless HTTP 1.x packets and generate a file from the payload. It read packets from a pcap/pcap-ng file. + +Using the utility (Work In Progress) +----------------- +When extracting HTTP traffic payload a pcap/pcap-ng file: + + Basic usage: + HttpAnalyzer [-h] -f input_file + Options: + -f : The input pcap file to analyze. Required argument for this mode + -h : Displays this help message and exits diff --git a/Examples/HttpReassembler/main.cpp b/Examples/HttpReassembler/main.cpp new file mode 100644 index 0000000000..918f10f249 --- /dev/null +++ b/Examples/HttpReassembler/main.cpp @@ -0,0 +1,86 @@ +/** + * HttpReassembler application + * ======================== + * This application reassembles HTTP payloads from captured packets as a text file. + */ + +#include +#include +#include "PcapPlusPlusVersion.h" +#include "SystemUtils.h" + +#define EXIT_WITH_ERROR(reason) do { \ + printUsage(); \ + std::cout << std::endl << "ERROR: " << reason << std::endl << std::endl; \ + exit(1); \ + } while(0) + +static struct option HttpReassemblerOptions[] = +{ + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, nullptr, 'v'} +}; + +/** + * Print application usage + */ +void printUsage() +{ + std::cout << std::endl + << "Usage:" << std::endl + << "----------------------" << std::endl + << pcpp::AppName::get() << " [-vh]" << std::endl + << std::endl + << "Options:" << std::endl + << std::endl + << " -v : Displays the current version and exists" << std::endl + << " -h : Displays this help message and exits" << std::endl + << std::endl; +} + +/** + * Print application version + */ +void printAppVersion() +{ + std::cout + << pcpp::AppName::get() << " " << pcpp::getPcapPlusPlusVersionFull() << std::endl + << "Built: " << pcpp::getBuildDateTime() << std::endl + << "Built from: " << pcpp::getGitInfo() << std::endl; + exit(0); +} + +/** + * Utility's main method + */ +int main(int argc, char* argv[]) +{ + pcpp::AppName::init(argc, argv); + + int optionIndex = 0; + int opt = 0; + + if (argc == 1) { + printUsage(); + exit(0); + } + + while((opt = getopt_long(argc, argv, "hv", HttpReassemblerOptions, &optionIndex)) != -1) + { + switch (opt) + { + case 0: + break; + case 'h': + printUsage(); + exit(0); + break; + case 'v': + printAppVersion(); + break; + default: + printUsage(); + exit(-1); + } + } +} diff --git a/Packet++/src/HttpReassembly.cpp b/Packet++/src/HttpReassembly.cpp index 0b21fe9323..c5e38254dd 100644 --- a/Packet++/src/HttpReassembly.cpp +++ b/Packet++/src/HttpReassembly.cpp @@ -3,4 +3,4 @@ namespace pcpp { -} \ No newline at end of file +}