Esempio n. 1
0
void SnifferConfiguration::configure_sniffer_pre_activation(FileSniffer& sniffer) const {
    if ((flags_ & PACKET_FILTER) != 0) {
        if (!sniffer.set_filter(filter_)) {
            throw invalid_pcap_filter(pcap_geterr(sniffer.get_pcap_handle()));
        }
    }
}
int main() 
{
	FileSniffer sniffer;
	std::cout<<"\nSniffing for new files on current directory path\n";
	sniffer.sniffFiles(".");
	std::cout<<"\nDisplaying only summary of analysis\n";
	sniffer.OnlySummary();
	sniffer.sniffFiles(".");
	std::cout<<"\nShowing previous analysis result\n";
	sniffer.PrintResult();
	std::cin.ignore();
	std::cin.get();
	return 0;
}
Esempio n. 3
0
void SnifferConfiguration::configure_sniffer_pre_activation(FileSniffer& sniffer) const
{
    if ((_flags & PACKET_FILTER) != 0) {
        if (!sniffer.set_filter(_filter)) {
            throw std::runtime_error("Could not set the filter!");
        }
    }
}
////////////////////////////////////////////////////////////////
///Function to send sniffed file list to the client
void Executive::listReply(struct mg_connection *conn, const struct mg_request_info *request_info)
{
	try{
	int is_jsonp;
	char text[100];
	const char * json;
	std::stringstream ss;
	std::string msg;
	mg_printf(conn, "%s\r\n", json_reply_start);	//prints the json message starting headers
	const char * clength;
	char h1[] = "Content-Length";
	clength = mg_get_header(conn,h1);	//get the length of post data
	int clen = atoi(clength);
	char *pdata = (char *)malloc(clen+clen/8+1);
	int datalen = mg_read(conn,pdata,clen);	//read post data
	pdata[clen] = '\0';
	mg_get_var(pdata, strlen(pdata == NULL ? "" : pdata), "text", text, sizeof(text));
	std::string path(text);
	is_jsonp = handle_jsonp(pdata,conn, request_info);	//find the callback function
	srand((size_t)time(NULL));
	ss<<"[";
	fsniffer2.Clear();
	fsniffer2.sniffFiles(path);
	std::set<std::string> filelist = fsniffer2.getFiles();	//get sniffed files
	for (std::set<std::string>::iterator it=filelist.begin(); it != filelist.end(); it++)
	{
		std::string tempstr = HTMLEncode(*it);	//html encode filepaths
		ss<<"{item: \""<<tempstr<<"\"},";
	}
	ss<<"]";
	msg = ss.str();
	json = msg.c_str();
	mg_printf(conn, "%s", json);	//print json array to the connection

	if (is_jsonp) 	{
		mg_printf(conn, "%s", ")");	//print closing bracket for the function
	}
//	fsniffer2.saveFiles();	//save sniffed files
	}
	catch(std::exception ex){std::cout << "\n  " << ex.what() << "\n\n";}
}
//function to save files
void Executive::savefiles(struct mg_connection *conn, const struct mg_request_info *request_info)
{
	fsniffer2.saveFiles();

}