library/src/exploitation/WebExploitation/BlindSQLiDetection/BP-WebExploitationBlindSQLiDetection.cc
// Generates a list of test conditions for union select conditions.  The front_parts
// parameter must be null pointer terminated to use this function correctly.
Generates a list of test conditions for union select conditions.  The front_parts
parameter must be null pointer terminated to use this function correctly.
Generates a list of test conditions for union select conditions . The front_parts parameter must be null pointer terminated to use this function correctly .
P_BP_WEB_BLIND_SQLINJ_TEST BP_WebExploitatinGenUnionSelectTestConditions(char ** front_parts, size_t matrix_size, char *str_test, char *int_test, size_t gen_integer_tests, size_t gen_string_tests, size_t max_nesting)
{
	if(!front_parts)
		return NULL;
	size_t test_tail_ctr = 0;
	char ***merged      = NULL;
	char ***tmp_merging = NULL;
	size_t i = 1;
	for(; i <= matrix_size; i++)
	{
		tmp_merging = BP_GenerateBlindSQLiUnionMatrixFromStrIntText(str_test, int_test, i);
		merged      = BP_WebExploitationBlindSQLiMergeMatrixesAndFree(merged, tmp_merging);
	}
	BP_WebExploitationPrintUnionSelectMatrix(merged);
	char ** end_strs = (char **) bpcalloc( (max_nesting+1) * sizeof(char *), 1);
	size_t p = 0;
	for
	(
		i = 0;
		i < max_nesting;
		i++
	)
	{
		char *iter_str = (char *) bpcalloc(max_nesting+30, 1);
		for(p = 0; p < i; p++)
		{
			strcat(iter_str, ")");
		}
		strcat(iter_str, "--%20");
		end_strs[i] = iter_str;
	}
	size_t x =  0;
	char *iter_str = NULL;
	char **final_test_strings = NULL;
	size_t final_test_ctr = 0;
	for
	(
		;
		front_parts[x];
		x++
	)
	{
		for(i = 0; merged[i]; i++)
		{
			size_t j = 0;
			for(; end_strs[j]; j++)
			{
				iter_str = BP_WebExploitationBlindSQLiCreateExploitStr(front_parts[x], merged[i], end_strs[j]);
				if(iter_str)
				{
					final_test_ctr++;
					final_test_strings = (char **) bprealloc(final_test_strings, (final_test_ctr+1) * sizeof(char*));
					final_test_strings[final_test_ctr-1] = iter_str;
					final_test_strings[final_test_ctr]   = NULL;
				}
			}
		}
		)
	}
	P_BP_WEB_BLIND_SQLINJ_TEST bsqli_test_set = NULL;
	for(i = 0; final_test_strings[i]; i++)
	{
		bsqli_test_set = (P_BP_WEB_BLIND_SQLINJ_TEST) bprealloc(bsqli_test_set, sizeof(BP_WEB_BLIND_SQLINJ_TEST) * (i+2));
		bsqli_test_set[i].testFront = final_test_strings[i];
		bsqli_test_set[i].type = BP_WEB_BLINDSQLI_TYPE_UNION_SELECT;
		memset((void *) &bsqli_test_set[i+1], 0x00, sizeof(BP_WEB_BLIND_SQLINJ_TEST));
	}
	return bsqli_test_set;
}
P_BP_WEB_BLIND_SQLINJ_TEST BP_WebExploitatinGenUnionSelectTestConditions ( char * * front_parts , size_t matrix_size , char * str_test , char * int_test , size_t gen_integer_tests , size_t gen_string_tests , size_t max_nesting ) { if ( ! front_parts ) return NULL ; size_t test_tail_ctr = 0 ; char * * * merged = NULL ; char * * * tmp_merging = NULL ; size_t i = 1 ; for ( ; i <= matrix_size ; i ++ ) { tmp_merging = BP_GenerateBlindSQLiUnionMatrixFromStrIntText ( str_test , int_test , i ) ; merged = BP_WebExploitationBlindSQLiMergeMatrixesAndFree ( merged , tmp_merging ) ; } BP_WebExploitationPrintUnionSelectMatrix ( merged ) ; char * * end_strs = ( char * * ) bpcalloc ( ( max_nesting + 1 ) * sizeof ( char * ) , 1 ) ; size_t p = 0 ; for ( i = 0 ; i < max_nesting ; i ++ ) { char * iter_str = ( char * ) bpcalloc ( max_nesting + 30 , 1 ) ; for ( p = 0 ; p < i ; p ++ ) { strcat ( iter_str , " " ) ; } strcat ( iter_str , " " ) ; end_strs [ i ] = iter_str ; } size_t x = 0 ; char * iter_str = NULL ; char * * final_test_strings = NULL ; size_t final_test_ctr = 0 ; for ( ; front_parts [ x ] ; x ++ ) { for ( i = 0 ; merged [ i ] ; i ++ ) { size_t j = 0 ; for ( ; end_strs [ j ] ; j ++ ) { iter_str = BP_WebExploitationBlindSQLiCreateExploitStr ( front_parts [ x ] , merged [ i ] , end_strs [ j ] ) ; if ( iter_str ) { final_test_ctr ++ ; final_test_strings = ( char * * ) bprealloc ( final_test_strings , ( final_test_ctr + 1 ) * sizeof ( char * ) ) ; final_test_strings [ final_test_ctr - 1 ] = iter_str ; final_test_strings [ final_test_ctr ] = NULL ; } } } } P_BP_WEB_BLIND_SQLINJ_TEST bsqli_test_set = NULL ; for ( i = 0 ; final_test_strings [ i ] ; i ++ ) { bsqli_test_set = ( P_BP_WEB_BLIND_SQLINJ_TEST ) bprealloc ( bsqli_test_set , sizeof ( BP_WEB_BLIND_SQLINJ_TEST ) * ( i + 2 ) ) ; bsqli_test_set [ i ] . testFront = final_test_strings [ i ] ; bsqli_test_set [ i ] . type = BP_WEB_BLINDSQLI_TYPE_UNION_SELECT ; memset ( ( void * ) & bsqli_test_set [ i + 1 ] , 0x00 , sizeof ( BP_WEB_BLIND_SQLINJ_TEST ) ) ; } return bsqli_test_set ; }
Generates a list of test conditions for union select conditions.
Generates a list of test conditions for union select conditions .
// must have a set of at least 1 front part for union select. // used in the matrix generator to determine how many // test tails are currently being implemented. // generate all matrix stacks // display the merged matrix // generate nesting end strings // nested parenthesis iter // iterate through nesting // create an iterator string // add the end and loop it // walk frotparts and generate test matrix for each // this contains the final list of tests ready for processing // iterate through front parts and join // generating all string middle variations // allocate space on the stack for the iter string and drop in position // Test Tail Matrix Loop Theory: // pass 1: //     front_parts[x] = UNION SELECT //     test_tail =; // pass 2: // 		front_parts[x] = UNION SELECT //      test_tail = ) // pass 3: //      front_parts[x] = UNION SELECT //      test_tail = )) // generate bsqli test set // generate space for the test set // zero out last element to truncate on loop // return the populated array