library/src/exploitation/WebExploitation/CommandExecution/BP-WebExploitationCommandExecution.cc
// Attempt to parse html anchors for new targets.
Attempt to parse html anchors for new targets.
Attempt to parse html anchors for new targets .
BP_ERROR_T BP_CommandInjectionParseHtmlAnchorsForNewTargets
(
		P_BP_WEB_COMMAND_INJECTION_TEST_SESSION cmd_injection_session,
		P_BP_HTML_ANCHOR_LIST                  anchors
)
{
	if(!cmd_injection_session)
		return ERR_FAILURE;
	if(!anchors)
		return ERR_FAILURE;
	P_BP_HTML_ANCHOR_LIST anchor_saved_first = anchors->first;
	P_BP_HTML_ANCHOR_VAR_LIST anchor_var_list = NULL;
	P_BP_HTML_ANCHOR_LIST anchor = anchors->first;
	size_t anchor_test_n = 0;
	for
	(
		;
		anchor;
		anchor = anchor->next
	)
	{
		if(!anchor->vars)
			continue;
		if(!anchor->base)
			continue;
		anchor_var_list = anchor->vars;
		for
		(
				;
				anchor_var_list;
				anchor_var_list = anchor_var_list->next
		)
		{
			if(!bpstrlen(anchor_var_list->name))
				continue;
			anchor_test_n++;
		}
	}
	size_t inital_index = 0;
	if(cmd_injection_session->cmd_injection_test_set_n)
		inital_index = cmd_injection_session->cmd_injection_test_set_n;
	cmd_injection_session->cmd_injection_test_set = (P_BP_WEB_COMMAND_INJECTION_TEST) tq_realloc
	(
		cmd_injection_session->tq,
		cmd_injection_session->cmd_injection_test_set,
		sizeof(BP_WEB_COMMAND_INJECTION_TEST) * (anchor_test_n + cmd_injection_session->cmd_injection_test_set_n+1),
		BPLN
	);
	memset
	(
		&cmd_injection_session->cmd_injection_test_set[inital_index],
		0x00,
		sizeof(BP_WEB_COMMAND_INJECTION_TEST) * anchor_test_n
	);
	P_BP_WEB_COMMAND_INJECTION_TEST test = NULL;
	for
	(
		anchor = anchor_saved_first;
		anchor;
		anchor = anchor->next
	)
	{
		if(!anchor->vars)
			continue;
		if(!anchor->base)
			continue;
		anchor_var_list = anchor->vars->first;
		for
		(
				;
				anchor_var_list;
				anchor_var_list = anchor_var_list->next
		)
		{
			if(!bpstrlen(anchor_var_list->name))
				continue;
			test = &cmd_injection_session->cmd_injection_test_set[inital_index];
			test->is_anchor_test = BP_TRUE;
			test->anchor        = anchor;
			 var list
			test->anchor_var     = anchor_var_list;
			inital_index++;
			cmd_injection_session->cmd_injection_test_set_n++;
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_CommandInjectionParseHtmlAnchorsForNewTargets ( P_BP_WEB_COMMAND_INJECTION_TEST_SESSION cmd_injection_session , P_BP_HTML_ANCHOR_LIST anchors ) { if ( ! cmd_injection_session ) return ERR_FAILURE ; if ( ! anchors ) return ERR_FAILURE ; P_BP_HTML_ANCHOR_LIST anchor_saved_first = anchors -> first ; P_BP_HTML_ANCHOR_VAR_LIST anchor_var_list = NULL ; P_BP_HTML_ANCHOR_LIST anchor = anchors -> first ; size_t anchor_test_n = 0 ; for ( ; anchor ; anchor = anchor -> next ) { if ( ! anchor -> vars ) continue ; if ( ! anchor -> base ) continue ; anchor_var_list = anchor -> vars ; for ( ; anchor_var_list ; anchor_var_list = anchor_var_list -> next ) { if ( ! bpstrlen ( anchor_var_list -> name ) ) continue ; anchor_test_n ++ ; } } size_t inital_index = 0 ; if ( cmd_injection_session -> cmd_injection_test_set_n ) inital_index = cmd_injection_session -> cmd_injection_test_set_n ; cmd_injection_session -> cmd_injection_test_set = ( P_BP_WEB_COMMAND_INJECTION_TEST ) tq_realloc ( cmd_injection_session -> tq , cmd_injection_session -> cmd_injection_test_set , sizeof ( BP_WEB_COMMAND_INJECTION_TEST ) * ( anchor_test_n + cmd_injection_session -> cmd_injection_test_set_n + 1 ) , BPLN ) ; memset ( & cmd_injection_session -> cmd_injection_test_set [ inital_index ] , 0x00 , sizeof ( BP_WEB_COMMAND_INJECTION_TEST ) * anchor_test_n ) ; P_BP_WEB_COMMAND_INJECTION_TEST test = NULL ; for ( anchor = anchor_saved_first ; anchor ; anchor = anchor -> next ) { if ( ! anchor -> vars ) continue ; if ( ! anchor -> base ) continue ; anchor_var_list = anchor -> vars -> first ; for ( ; anchor_var_list ; anchor_var_list = anchor_var_list -> next ) { if ( ! bpstrlen ( anchor_var_list -> name ) ) continue ; test = & cmd_injection_session -> cmd_injection_test_set [ inital_index ] ; test -> is_anchor_test = BP_TRUE ; test -> anchor = anchor ; test -> anchor_var = anchor_var_list ; inital_index ++ ; cmd_injection_session -> cmd_injection_test_set_n ++ ; } } return ERR_SUCCESS ; }
Attempt to parse html anchors for new targets.
Attempt to parse html anchors for new targets .
// ensure we have command injection sessions // ensure we have anchors // save first so we can iterate again // temporary anchor var list // create reference to increase readable while iterating // anchors // calculate the anchor count // must have a parsed base or we can't work // set the var list for iterating // count anchor variables // we have to have an anchor name, or we fail // increment the anchor count /*
		printf("\n base:     %s", anchor->base);
		printf("\n path:     %s", anchor->path);
		printf("\n script:   %s", anchor->script);
		printf("\n host:     %s", anchor->host);
		printf("\n full_url: %s", anchor->full_url);
		printf("\n");
		*/ // set inital index position // attempt to (re)allocate memory // zero new memory // command injection test reference, here for adding code readability // copy in new values // must have a parsed base or we can't work // set the var list for iterating // count anchor variables // we have to have an anchor name, or we fail // -- Set Values --------------------- // set test at index // mark test as an anchor test // set the anchor // set the anchor var list // -- Increment Counters -------------- // move up the initial index // increase the number of injection sets here // return indicating success