library/src/exploitation/WebExploitation/BP-WebExploitationRunWebAssessmentFormChecks.cc
// Generates a test target based off an form.
Generates a test target based off an form.
Generates a test target based off an form .
char *BP_WebExploitationGetFormRelativeTestTarget(P_BP_WEB_ASSESSMENT assessment, P_BP_HTML_FORM_LIST form, size_t form_buff_len)
{
	if(!form)
		return NULL;
	char * baseTestURL = NULL;
	P_BP_HTML_FORM_PROPERTY_LIST formActionInput = HTMLGetFormPropertyByNameI(form->properties, "action");
	size_t formProto = HTMLGetAnchorProtocol(formActionInput->content, formActionInput->cLen);
	P_BP_HTML_FORM_PROPERTY_LIST formMethodInput = (P_BP_HTML_FORM_PROPERTY_LIST) HTMLGetFormPropertyByNameI(form->properties, "method");
	char * formTest = (char *) bpcalloc(form_buff_len, 1);
	memset(formTest, 0x00, form_buff_len);
	if
	(
			formProto == BP_ANCHOR_PROTO_HTTP ||
			formProto == BP_ANCHOR_PROTO_HTTPS
	)
	{
		baseTestURL      = bpstrdup(form->path);
		char *tmp_script = BP_ParseURLToScript(form->full_url, 1, 1);
		if(bpstrlen(tmp_script) == 2)
		if(memcmp(tmp_script, "./", 2) == 0)
		{
			bpfree(tmp_script);
			tmp_script = NULL;
		}
		if(bpstrlen(tmp_script) == 1)
		if(tmp_script[1] == '/')
		{
			bpfree(tmp_script);
			tmp_script = NULL;
		}
		if(tmp_script)
		{
			if(tmp_script[0] == '/')
			if(bpstrlen(tmp_script) > 1)
				snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) &tmp_script[0]);
			if(tmp_script[0] != '/')
				snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) tmp_script);
		}
		else
		{
			snprintf(formTest, form_buff_len, "%s", baseTestURL);
		}
		if(tmp_script)
			bpfree(tmp_script);
	}
	else
	{
		baseTestURL = bpstrdup(form->path); 
		char *tmp_script = BP_ParseRelativeLinkToScript(form->full_url, 1);
		if(bpstrlen(tmp_script) == 2)
		if(memcmp(tmp_script, "./", 2) == 0)
		{
			bpfree(tmp_script);
			tmp_script = NULL;
		}
		if(bpstrlen(tmp_script) == 1)
		if(tmp_script[1] == '/')
		{
			bpfree(tmp_script);
			tmp_script = NULL;
		}
		if(tmp_script)
		{
			if(tmp_script[0] == '/')
			if(bpstrlen(tmp_script) > 1)
				snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) &tmp_script[0]);
			if(tmp_script[0] != '/')
				snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) tmp_script);
			else
				snprintf(formTest, form_buff_len, "%s", baseTestURL);
		}
		else if(formActionInput->content)
		{
			if(formActionInput->content[0] == '/')
			if(bpstrlen(formActionInput->content) > 1)
				snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) &formActionInput->content[0]);
			if(bpstrlen(formActionInput->content) == 2)
			{
				if(memcmp(formActionInput->content, "./", 2) == 0)
				{
					snprintf(formTest, form_buff_len, "%s", baseTestURL);
				}
			}
			else
			{
				if(formActionInput->content[0] != '/')
					snprintf(formTest, form_buff_len, "%s%s", baseTestURL, (char *) formActionInput->content);
			}
		}
		else
		{
			snprintf(formTest, form_buff_len, "%s", baseTestURL);
		}
		if(tmp_script)
			bpfree(tmp_script);
	}
	if (baseTestURL)
	{
		bpfree(baseTestURL);
		baseTestURL = NULL;
	}
	return formTest;
}
char * BP_WebExploitationGetFormRelativeTestTarget ( P_BP_WEB_ASSESSMENT assessment , P_BP_HTML_FORM_LIST form , size_t form_buff_len ) { if ( ! form ) return NULL ; char * baseTestURL = NULL ; P_BP_HTML_FORM_PROPERTY_LIST formActionInput = HTMLGetFormPropertyByNameI ( form -> properties , " " ) ; size_t formProto = HTMLGetAnchorProtocol ( formActionInput -> content , formActionInput -> cLen ) ; P_BP_HTML_FORM_PROPERTY_LIST formMethodInput = ( P_BP_HTML_FORM_PROPERTY_LIST ) HTMLGetFormPropertyByNameI ( form -> properties , " " ) ; char * formTest = ( char * ) bpcalloc ( form_buff_len , 1 ) ; memset ( formTest , 0x00 , form_buff_len ) ; if ( formProto == BP_ANCHOR_PROTO_HTTP || formProto == BP_ANCHOR_PROTO_HTTPS ) { baseTestURL = bpstrdup ( form -> path ) ; char * tmp_script = BP_ParseURLToScript ( form -> full_url , 1 , 1 ) ; if ( bpstrlen ( tmp_script ) == 2 ) if ( memcmp ( tmp_script , " " , 2 ) == 0 ) { bpfree ( tmp_script ) ; tmp_script = NULL ; } if ( bpstrlen ( tmp_script ) == 1 ) if ( tmp_script [ 1 ] == ' ' ) { bpfree ( tmp_script ) ; tmp_script = NULL ; } if ( tmp_script ) { if ( tmp_script [ 0 ] == ' ' ) if ( bpstrlen ( tmp_script ) > 1 ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) & tmp_script [ 0 ] ) ; if ( tmp_script [ 0 ] != ' ' ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) tmp_script ) ; } else { snprintf ( formTest , form_buff_len , " " , baseTestURL ) ; } if ( tmp_script ) bpfree ( tmp_script ) ; } else { baseTestURL = bpstrdup ( form -> path ) ; char * tmp_script = BP_ParseRelativeLinkToScript ( form -> full_url , 1 ) ; if ( bpstrlen ( tmp_script ) == 2 ) if ( memcmp ( tmp_script , " " , 2 ) == 0 ) { bpfree ( tmp_script ) ; tmp_script = NULL ; } if ( bpstrlen ( tmp_script ) == 1 ) if ( tmp_script [ 1 ] == ' ' ) { bpfree ( tmp_script ) ; tmp_script = NULL ; } if ( tmp_script ) { if ( tmp_script [ 0 ] == ' ' ) if ( bpstrlen ( tmp_script ) > 1 ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) & tmp_script [ 0 ] ) ; if ( tmp_script [ 0 ] != ' ' ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) tmp_script ) ; else snprintf ( formTest , form_buff_len , " " , baseTestURL ) ; } else if ( formActionInput -> content ) { if ( formActionInput -> content [ 0 ] == ' ' ) if ( bpstrlen ( formActionInput -> content ) > 1 ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) & formActionInput -> content [ 0 ] ) ; if ( bpstrlen ( formActionInput -> content ) == 2 ) { if ( memcmp ( formActionInput -> content , " " , 2 ) == 0 ) { snprintf ( formTest , form_buff_len , " " , baseTestURL ) ; } } else { if ( formActionInput -> content [ 0 ] != ' ' ) snprintf ( formTest , form_buff_len , " " , baseTestURL , ( char * ) formActionInput -> content ) ; } } else { snprintf ( formTest , form_buff_len , " " , baseTestURL ) ; } if ( tmp_script ) bpfree ( tmp_script ) ; } if ( baseTestURL ) { bpfree ( baseTestURL ) ; baseTestURL = NULL ; } return formTest ; }
Generates a test target based off an form.
Generates a test target based off an form .
// If the protocol is not 0, then its offsite (change later) // retrieve form method // substitute variable at position // Check to see if we have a http:// or https:// or relative link. // printf("\n Form is http or https!"); // create base test url (duplicated) // BP_ParseURLToPathPCRE(formActionInput->content); // parse script (duplicated) // fix the appending bug // printf("\n Got http/https direct form test: %s", formTest); // printf("\n Form is relative!"); // baseTestURL = HTTPStripScript(assessment->baseAssessmentURL, bpstrlen(assessment->baseAssessmentURL)); // BP_ParseURLToPathPCRE(assessment->baseAssessmentURL); // fix the appending bug // fix the appending bug // destroy test url if set then nullify for loop // return the form test