library/src/exploitation/WebExploitation/BP-WebExploitation.cc
// Generates a magic-quotes string based on an instring (malloced and must be bpfreed)
Generates a magic-quotes string based on an instring (malloced and must be bpfreed)
Generates a magic - quotes string based on an instring ( malloced and must be bpfreed )
char * BP_WebAssessmentGenerateMagicQuoteStrFromStr(char *inStr)
{
	if(!inStr)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(inStr, bpstrlen(inStr), BP_TRUE, BP_TRUE))
		return NULL;
	size_t maxLen = bpstrlen(inStr);
	char *outStr = NULL;
	size_t x = 0; 
	size_t i = 0; 
	for (i = 0; i < maxLen; i++)
	{
		switch (inStr[i])
		{
			case '\'':
				x += 2;
				outStr = (char *) bprealloc(outStr, x);
				memcpy(&outStr[x - 2], "\\'", 2);
				break;
			case '"':
				x += 2;
				outStr = (char *) bprealloc(outStr, x);
				memcpy(&outStr[x - 2], "\\\"", 2);
				break;
			default:
				x++;
				outStr = (char *) bprealloc(outStr, x);
				outStr[x - 1] = inStr[i];
				break;
		}
	}
	x++;
	if (outStr) {
		outStr = (char *) bprealloc(outStr, x);
		outStr[x - 1] = '\0';
	}
	return outStr;
}
char * BP_WebAssessmentGenerateMagicQuoteStrFromStr ( char * inStr ) { if ( ! inStr ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( inStr , bpstrlen ( inStr ) , BP_TRUE , BP_TRUE ) ) return NULL ; size_t maxLen = bpstrlen ( inStr ) ; char * outStr = NULL ; size_t x = 0 ; size_t i = 0 ; for ( i = 0 ; i < maxLen ; i ++ ) { switch ( inStr [ i ] ) { case ' \' ' : x += 2 ; outStr = ( char * ) bprealloc ( outStr , x ) ; memcpy ( & outStr [ x - 2 ] , " \\ " , 2 ) ; break ; case ' ' : x += 2 ; outStr = ( char * ) bprealloc ( outStr , x ) ; memcpy ( & outStr [ x - 2 ] , " \\ \" " , 2 ) ; break ; default : x ++ ; outStr = ( char * ) bprealloc ( outStr , x ) ; outStr [ x - 1 ] = inStr [ i ] ; break ; } } x ++ ; if ( outStr ) { outStr = ( char * ) bprealloc ( outStr , x ) ; outStr [ x - 1 ] = ' \0 ' ; } return outStr ; }
Generates a magic-quotes string based on an instring (malloced and must be bpfreed)
Generates a magic - quotes string based on an instring ( malloced and must be bpfreed )
// ensure we have an in string // ensure the string to modify is reasonable printable string // get the string length // out string (returned pointer) // loop counters // modified length // orig length // walk original length // append null terminator to out str // return the output buffer