Skip to content

Commit

Permalink
Adds the scaffold for the HTTP 1.x reassembler
Browse files Browse the repository at this point in the history
example application.
  • Loading branch information
jpcofr committed Oct 8, 2023
1 parent 1447f7c commit 22a85a0
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions Examples/HttpReassembler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
14 changes: 14 additions & 0 deletions Examples/HttpReassembler/README.md
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions Examples/HttpReassembler/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* HttpReassembler application
* ========================
* This application reassembles HTTP payloads from captured packets as a text file.
*/

#include <iostream>
#include <getopt.h>
#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) { // No options provided
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);
}
}
}

0 comments on commit 22a85a0

Please sign in to comment.