library/src/network/nmap/BP-NMAP.cc
// thread entry point for our application handler.  This must be
// added to whichever event handler you want to hook it into at runtime
// in order for it to work. (BP_EventMgrAddProcessor)
thread entry point for our application handler.  This must be
added to whichever event handler you want to hook it into at runtime
in order for it to work.
thread entry point for our application handler . This must be added to whichever event handler you want to hook it into at runtime in order for it to work .
BP_EVENT_PROCESSOR_FUNC( BP_NmapThreadCallbackEntryPoint )
{
	BP_EVENT_PROCESSOR_ENTRY;
	P_BP_NMAP_EVENT_DATA nmap_event_data = (P_BP_NMAP_EVENT_DATA) event->event_data;
	if(!nmap_event_data)
	{
		BP_EVENT_PROCESSOR_EXIT;
	}
	P_BP_NMAP nmap = nmap_event_data->nmap;
	if(!nmap)
	{
		printf("\n [!!] Critical: nmap session has not been passed into the nmap event processor function.");
		BP_EVENT_PROCESSOR_EXIT;
	}
	if(nmap_event_data->event_type == BP_NMAP_EVENT_START_NMAP)
	{
		nmap_event_data->status = BP_NMAP_EVENT_STATUS_STARTING_UP;
		BP_NMAP_EVENT_RETURN_CODE return_code;
		BP_NMAP_EVENT_STATUS status;
		%%%%%%%%%%%%
		%%%%%%%%%%%%
		printf("\n NMAP bin path", nmap->nmap_bin_path);
		char *nmap_params[] =
		{
				nmap->nmap_bin_path,
				"-sS",
				"localhost",
				NULL
		};
		nmap->nmap_app = BP_FExec
		(
				nmap->nmap_bin_path,
				(char **) &nmap_params,
				nmap->nmap_bin_envp,
				BP_TRUE
		);
		%%%%%%%%%%%%%%%
		%%%%%%%%%%%%%%%
		P_BP_CC_SESSION nmap_cc_session = BP_CCNewSession
		(
				nmap->nmap_app,
			   "nmap_cc_session",
			   BP_CC_SHELL_LINUX_EXECVE
		);
		nmap_cc_session->display_reads_from_app_stdout = BP_TRUE;
		nmap_cc_session->display_reads_from_app_stderr = BP_TRUE;
		nmap_cc_session->display_writes_to_app_stdin   = BP_FALSE;
		nmap_cc_session->select_child_stdout_timeout_sec  = 30;
		nmap_cc_session->select_child_stdout_timeout_usec = 500;
		BP_ERROR_T ret_val = ERR_FAILURE;
		%%%%%%%%%%%%%%
		%%%%%%%%%%%%%%
		char *cc_command_name = "start_and_monitor_nmap";
		BP_CCAddCommand(nmap_cc_session, cc_command_name);
		ret_val = BP_CCAddTryExpectToCommand
		(
				nmap_cc_session,
				"start_and_monitor_nmap",
				NULL,
				0,
				"Nmap done",
				bpstrlen("Nmap done"),
				BP_CC_MATCH_BUFF_POLICY_MEM_SEARCH
		);
		if(!BP_CCDispatcher(nmap_cc_session, "start_and_monitor_nmap", NULL))
		{
				printf("\n [!!] Dispatcher failed for start_and_monitor_nmap.");
				exit(0);
		}
		%%%%%%%%%%%%%%%%%%%%%
		%%%%%%%%%%%%%%%%%%%%%
		gettimeofday(&nmap->service_start_time, NULL);
		BP_CCVisualizeSession(nmap_cc_session, BP_TRUE, BP_TRUE);
		printf("\n [+] NMAP dispatcher has completed.");
		nmap_event_data->status = BP_NMAP_EVENT_STATUS_RUNNING;
	}
	if(nmap_event_data->event_type == BP_NMAP_EVENT_STOP_NMAP)
	{
		nmap_event_data->status = BP_NMAP_EVENT_STATUS_STOPPING;
	    BP_BOOL still_running = BP_TRUE;
	    do
	    {
	    	still_running = BP_FExecApplicationStillRunning(nmap->nmap_app) ? BP_TRUE : BP_FALSE;
	    	if(still_running)
	    	{
	    		BP_FExecKillApplication(nmap->nmap_app);
	    		sleep(1);
	    	}
	    } while(still_running);
	    nmap_event_data->status = BP_NMAP_EVENT_STATUS_FINISHED;
	    printf("\n [+] Nmap process has stopped completely.");
	}
	BP_EVENT_PROCESSOR_EXIT;
}
BP_EVENT_PROCESSOR_FUNC ( BP_NmapThreadCallbackEntryPoint ) { BP_EVENT_PROCESSOR_ENTRY ; P_BP_NMAP_EVENT_DATA nmap_event_data = ( P_BP_NMAP_EVENT_DATA ) event -> event_data ; if ( ! nmap_event_data ) { BP_EVENT_PROCESSOR_EXIT ; } P_BP_NMAP nmap = nmap_event_data -> nmap ; if ( ! nmap ) { printf ( " \n " ) ; BP_EVENT_PROCESSOR_EXIT ; } if ( nmap_event_data -> event_type == BP_NMAP_EVENT_START_NMAP ) { nmap_event_data -> status = BP_NMAP_EVENT_STATUS_STARTING_UP ; BP_NMAP_EVENT_RETURN_CODE return_code ; BP_NMAP_EVENT_STATUS status ; printf ( " \n " , nmap -> nmap_bin_path ) ; char * nmap_params [ ] = { nmap -> nmap_bin_path , " " , " " , NULL } ; nmap -> nmap_app = BP_FExec ( nmap -> nmap_bin_path , ( char * * ) & nmap_params , nmap -> nmap_bin_envp , BP_TRUE ) ; P_BP_CC_SESSION nmap_cc_session = BP_CCNewSession ( nmap -> nmap_app , " " , BP_CC_SHELL_LINUX_EXECVE ) ; nmap_cc_session -> display_reads_from_app_stdout = BP_TRUE ; nmap_cc_session -> display_reads_from_app_stderr = BP_TRUE ; nmap_cc_session -> display_writes_to_app_stdin = BP_FALSE ; nmap_cc_session -> select_child_stdout_timeout_sec = 30 ; nmap_cc_session -> select_child_stdout_timeout_usec = 500 ; BP_ERROR_T ret_val = ERR_FAILURE ; char * cc_command_name = " " ; BP_CCAddCommand ( nmap_cc_session , cc_command_name ) ; ret_val = BP_CCAddTryExpectToCommand ( nmap_cc_session , " " , NULL , 0 , " " , bpstrlen ( " " ) , BP_CC_MATCH_BUFF_POLICY_MEM_SEARCH ) ; if ( ! BP_CCDispatcher ( nmap_cc_session , " " , NULL ) ) { printf ( " \n " ) ; exit ( 0 ) ; } gettimeofday ( & nmap -> service_start_time , NULL ) ; BP_CCVisualizeSession ( nmap_cc_session , BP_TRUE , BP_TRUE ) ; printf ( " \n " ) ; nmap_event_data -> status = BP_NMAP_EVENT_STATUS_RUNNING ; } if ( nmap_event_data -> event_type == BP_NMAP_EVENT_STOP_NMAP ) { nmap_event_data -> status = BP_NMAP_EVENT_STATUS_STOPPING ; BP_BOOL still_running = BP_TRUE ; do { still_running = BP_FExecApplicationStillRunning ( nmap -> nmap_app ) ? BP_TRUE : BP_FALSE ; if ( still_running ) { BP_FExecKillApplication ( nmap -> nmap_app ) ; sleep ( 1 ) ; } } while ( still_running ) ; nmap_event_data -> status = BP_NMAP_EVENT_STATUS_FINISHED ; printf ( " \n " ) ; } BP_EVENT_PROCESSOR_EXIT ; }
thread entry point for our application handler.
thread entry point for our application handler .
// processor entry macro // set nmap event data // printf("\n HERE HERE THIS IS THE EVENT DATA POINTER: %p (event) - %p (tor event)", event, tor_event_data); // set nmap handle // ensure we have nmap // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Process Start Event %%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // process start event if set // set the tor running status to starting up // return code for the specified event data // tor event status // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Exec Parameters and Execute Binary %%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set nmap binary path // set argv for application. // exec the file nvp) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Basic CC Session To Start TOR Service %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set cc session // display reads and writes (values can be changed inbetween // command runs to disable output for certain commands, or // enable output for others) // Set stdout polling timeout (values are additive and can be reset // between dispatched commands to change the select() responsiveness // of the app being controlled.) // declare return value // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% 2) Add Auth Try/Expect Logic %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set the cc command name here // Add some arbitrary commands to the command orchard. // Add some try/expect branches to some commands // start dispatcher // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Display CC Information After %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set service start time now that it's officially started // dbg: attempt to visualize sessions // display completion message // set indicator to running now that the process is up // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Process Stop Event %%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // process stop event if set // set event status // check if the app is still running // check if application is still running // if the application is running, attempt to kill it and sleep one sec // set event status // display message when stopped // processor entry macro