Examples/TLSFingerprinting/main.cpp
/**
 * Extract TLS fingerprints from a live interface
 */
Extract TLS fingerprints from a live interface
Extract TLS fingerprints from a live interface
void doTlsFingerprintingOnLiveTraffic(const std::string& interfaceNameOrIP, std::string& outputFileName, const std::string& separator, bool chFP, bool shFP, const std::string& bpfFilter)
{
	pcpp::PcapLiveDevice* dev = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIpOrName(interfaceNameOrIP);
	if (dev == NULL)
		EXIT_WITH_ERROR("Couldn't find interface by given IP address or name");
	if (!dev->open())
		EXIT_WITH_ERROR("Couldn't open interface");
	if (outputFileName.empty())
	{
		outputFileName = std::string(dev->getName());
		outputFileName.erase(remove_if(
			outputFileName.begin(),
			outputFileName.end(),
			isNotAlphanumeric), outputFileName.end());
		outputFileName += ".txt";
	}
	std::ofstream outputFile(outputFileName.c_str());
	if (!outputFile)
	{
		EXIT_WITH_ERROR("Cannot open output file '" << outputFileName << "'");
	}
	writeHeaderToOutputFile(outputFile, separator);
	if (!bpfFilter.empty())
	{
		if (!dev->setFilter(bpfFilter))
			EXIT_WITH_ERROR("Error in setting BPF filter to interface");
	}
	std::cout << "Start capturing packets from '" << interfaceNameOrIP << "'..." << std::endl;
	TLSFingerprintingStats stats;
	HandlePacketData data;
	data.chFP = chFP;
	data.shFP = shFP;
	data.outputFile = &outputFile;
	data.separator = separator;
	data.stats = &stats;
	dev->startCapture(onPacketArrives, &data);
	bool shouldStop = false;
	pcpp::ApplicationEventHandler::getInstance().onApplicationInterrupted(onApplicationInterrupted, &shouldStop);
	while(!shouldStop)
		pcpp::multiPlatformSleep(1);
	dev->stopCapture();
	dev->close();
	printStats(stats, chFP, shFP);
	std::cout << "Output file was written to: '" << outputFileName << "'" << std::endl;
}
void doTlsFingerprintingOnLiveTraffic ( const std :: string & interfaceNameOrIP , std :: string & outputFileName , const std :: string & separator , bool chFP , bool shFP , const std :: string & bpfFilter ) { pcpp :: PcapLiveDevice * dev = pcpp :: PcapLiveDeviceList :: getInstance ( ) . getPcapLiveDeviceByIpOrName ( interfaceNameOrIP ) ; if ( dev == NULL ) EXIT_WITH_ERROR ( " " ) ; if ( ! dev -> open ( ) ) EXIT_WITH_ERROR ( " " ) ; if ( outputFileName . empty ( ) ) { outputFileName = std :: string ( dev -> getName ( ) ) ; outputFileName . erase ( remove_if ( outputFileName . begin ( ) , outputFileName . end ( ) , isNotAlphanumeric ) , outputFileName . end ( ) ) ; outputFileName += " " ; } std :: ofstream outputFile ( outputFileName . c_str ( ) ) ; if ( ! outputFile ) { EXIT_WITH_ERROR ( " " << outputFileName << " " ) ; } writeHeaderToOutputFile ( outputFile , separator ) ; if ( ! bpfFilter . empty ( ) ) { if ( ! dev -> setFilter ( bpfFilter ) ) EXIT_WITH_ERROR ( " " ) ; } std :: cout << " " << interfaceNameOrIP << " " << std :: endl ; TLSFingerprintingStats stats ; HandlePacketData data ; data . chFP = chFP ; data . shFP = shFP ; data . outputFile = & outputFile ; data . separator = separator ; data . stats = & stats ; dev -> startCapture ( onPacketArrives , & data ) ; bool shouldStop = false ; pcpp :: ApplicationEventHandler :: getInstance ( ) . onApplicationInterrupted ( onApplicationInterrupted , & shouldStop ) ; while ( ! shouldStop ) pcpp :: multiPlatformSleep ( 1 ) ; dev -> stopCapture ( ) ; dev -> close ( ) ; printStats ( stats , chFP , shFP ) ; std :: cout << " " << outputFileName << " " << std :: endl ; }
Extract TLS fingerprints from a live interface
Extract TLS fingerprints from a live interface
// extract pcap live device by interface name or IP address // set output file name to interface name if not provided by the user // take the device name and remove all chars which are not alphanumeric // open output file // write the column headers to the output file // set BPF filter if provided by the user // start capturing packets. Each packet arrived will be handled by the onPacketArrives method // register the on app close event to print summary stats on app termination // run in an endless loop until the user press ctrl+c // stop capturing and close the live device