Example #1
0
void problem17(void){
	 /*The CBC padding oracle*/
	string cipher;
	string plaintext;
	extern string paddingOracleKey;
	extern string paddingOracleIV;
	

	char * tenStringsRaw[10]={"MDAwMDAwTm93IHRoYXQgdGhlIHBhcnR5IGlzIGp1bXBpbmc=",
		"MDAwMDAxV2l0aCB0aGUgYmFzcyBraWNrZWQgaW4gYW5kIHRoZSBWZWdhJ3MgYXJlIHB1bXBpbic=",
		"MDAwMDAyUXVpY2sgdG8gdGhlIHBvaW50LCB0byB0aGUgcG9pbnQsIG5vIGZha2luZw==",
		"MDAwMDAzQ29va2luZyBNQydzIGxpa2UgYSBwb3VuZCBvZiBiYWNvbg==",
		"MDAwMDA0QnVybmluZyAnZW0sIGlmIHlvdSBhaW4ndCBxdWljayBhbmQgbmltYmxl",
		"MDAwMDA1SSBnbyBjcmF6eSB3aGVuIEkgaGVhciBhIGN5bWJhbA==",
		"MDAwMDA2QW5kIGEgaGlnaCBoYXQgd2l0aCBhIHNvdXBlZCB1cCB0ZW1wbw==",
		"MDAwMDA3SSdtIG9uIGEgcm9sbCwgaXQncyB0aW1lIHRvIGdvIHNvbG8=",
		"MDAwMDA4b2xsaW4nIGluIG15IGZpdmUgcG9pbnQgb2g=",
		"MDAwMDA5aXRoIG15IHJhZy10b3AgZG93biBzbyBteSBoYWlyIGNhbiBibG93"};
	string tenStrings[10];
	
	paddingOracleKey=randString(16);
	paddingOracleIV=randString(16);

	for(int i=0; i<10; i++) tenStrings[i]=newString(tenStringsRaw[i],0);

	printf("Demonstrating the CBC padding oracle. Ctrl+C to stop.\n\n");
	while(1){
	cipher=problem17func1(tenStrings);
	plaintext=stripPKCS7Padding(breakPaddingOracle(cipher, paddingOracle));
	if(!H4XX0R){prints(plaintext);printf("\n");}
	}
}
void printString(int probabilityLine) //the function print random strings
{

	time_t timer;
    char dateTime[26];
    struct tm* tm_info;
    time(&timer);
    tm_info = localtime(&timer);
    strftime(dateTime, 26, "%Y:%m:%d %H:%M:%S", tm_info);
	
	FILE *f = fopen("/home/vagrant/file.txt", "a");
	
	if (f == NULL)
	{
		printf("Error opening file!\n");
		exit(1);
	}
	
	if (probabilityLine <= 15 && probabilityLine <= 5)
		fprintf(f,"{ISO8601 %s}%{SPACE}%{%s}%{%s : 128 random characters}%{CR + LF + 5 TAB}%{%s: : 80 random characters}%\n", dateTime, logLevel(), randString(128), randString(80));
	else if (probabilityLine <= 15 && probabilityLine > 5)
		fprintf(f,"{ISO8601 %s}%{SPACE}%{%s}%{%s : 128 random characters}%{CR + LF + 5 TAB}\n", dateTime, logLevel(), randString(128));
	else if (probabilityLine > 15 && probabilityLine <= 5)
		fprintf(f,"{ISO8601 %s}%{SPACE}%{%s}%{CR + LF + 5 TAB}%{%s: : 80 random characters}%\n", dateTime, logLevel(),randString(80));
	else if (probabilityLine > 15 && probabilityLine > 5)
		fprintf(f,"{ISO8601 %s}%{SPACE}%{%s}%{CR + LF + 5 TAB}%\n", dateTime, logLevel(),randString(80));	
		
	fclose(f);	
}
char*
RandomFuncs::newRandString(int len)
{
   char* lp = new char[len+1];
   randString( lp, len );
   return lp;
}
Example #4
0
void GenExchangeTest::init(RsGroupMetaData& grpMetaData) const
{
    randString(SHORT_STR, grpMetaData.mGroupId);
    //randString(SHORT_STR, grpMetaData.mAuthorId);
    randString(SHORT_STR, grpMetaData.mGroupName);
    randString(SHORT_STR, grpMetaData.mServiceString);


    grpMetaData.mGroupFlags = randNum();
    grpMetaData.mLastPost = randNum();
    grpMetaData.mGroupStatus = randNum();
    grpMetaData.mMsgCount = randNum();
    grpMetaData.mPop = randNum();
    grpMetaData.mSignFlags = randNum();
    grpMetaData.mPublishTs = randNum();
    grpMetaData.mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN;
}
Example #5
0
File: io.c Project: CodeR57/DSA-lab
void writeToFile(int N)
{
    srand (time(NULL));
    FILE * f = getFileForInt(N);
    int i;
    for(i=0; i<N; i++)
    {
        fprintf(f,"%s\n",randString());
    }
    fclose(f);
}
Example #6
0
void GenExchangeTest::init(RsMsgMetaData& msgMetaData) const
{
    //randString(SHORT_STR, msgMeta.mAuthorId);
    randString(SHORT_STR, msgMetaData.mMsgName);
    randString(SHORT_STR, msgMetaData.mServiceString);
    randString(SHORT_STR, msgMetaData.mOrigMsgId);
    randString(SHORT_STR, msgMetaData.mParentId);
    randString(SHORT_STR, msgMetaData.mThreadId);
    randString(SHORT_STR, msgMetaData.mGroupId);

    msgMetaData.mChildTs = randNum();
    msgMetaData.mMsgStatus = randNum();
    msgMetaData.mMsgFlags = randNum();
    msgMetaData.mPublishTs = randNum();
}
Example #7
0
void objFinder::insert(QObject *obj, const char *key = 0){ /*FOLD00*/
  QString name;

  if(obj == 0x0){
    warning("objFinder: Passed Null Object");
    return;
  }
  
  if(key != 0){
    name = key;
  }
  else {
    name = obj->name();
    if(name == 0){
      name = randString();
    }
  }
  objList->insert(name.data(), obj);
  connect(obj, SIGNAL(destroyed()),
          objFind, SLOT(objDest()));
  
  emit objFind->inserted(obj);
}
Example #8
0
/**********Problem 25 ********/
string makeCipherText(void){
	char *inputChars=calloc(100, sizeof(char));
	string cipher;
	FILE *fp;
	int c, i;
	string out;

	fp=fopen(FILE7, "r");
	i=0;
	while((c=fgetc(fp))!=EOF){
		if(c=='\n') continue;
		inputChars[i++]=c;
		if(i%100==0){
			inputChars=realloc(inputChars, sizeof(char)*(i+100));
		}
	}
	inputChars=realloc(inputChars, sizeof(char)*(i+1));
	inputChars[i]='\0';
	cipher = PKCS7PadString(base64Decode(newString(inputChars,i)), 16);
	free(inputChars);
	out = AES128DecodeECB(cipher, newString("YELLOW SUBMARINE",0));
	savedKey=randString(16);
	return AES128CTR(out, savedKey, NULLSTRING);
}
Example #9
0
void GenExchangeTest::init(RsDummyMsg& msgItem) const
{
    randString(SHORT_STR, msgItem.msgData);
    init(msgItem.meta);
}
Example #10
0
void GenExchangeTest::init(RsDummyGrp& grpItem) const
{
    randString(SHORT_STR, grpItem.grpData);
    init(grpItem.meta);
}
Example #11
0
void problem19(void){
	/*Break fixed-nonce CTR mode using substitions
	 * 
	 *  I didn't want to do it using substitutions because it was a pain in the ass, so I did it using fixed-XOR
	 *  with a fixed keylength... which turned out to be how you're supposed to do the next problem? Oh well.
	 *  Spoiler: solutions are:
	 *      00: i have met them at close of day
	 * 		01: coming with vivid faces
	 *		02: from counter or desk among grey
	 *		03: eighteenth-century houses.
	 *		04: i have passed with a nod of the head
	 *		05: or polite meaningless words,
	 *		06: or have lingered awhile and said
	 *		07: polite meaningless words,
	 *		08: and thought before I had done
	 *		09: of a mocking tale or a gibe
	 *		10: to please a companion
	 *		11: around the fire at the club,
	 *		12: being certain that they and I
	 *		13: but lived where motley is worn:
	 *		14: all changed, changed utterly:
	 *		15: a terrible beauty is born.
	 *		16: that woman's days were spent
	 *		17: in ignorant good will,
	 *		18: her nights in argument
	 *		19: until her voice grew shrill.
	 *		20: what voice more sweet than hers
	 *		21: when young and beautiful,
	 *		22: she rode to harriers?
	 *		23: this man had kept a school
	 *		24: and rode our winged horse.
	 *		25: this other his helper and friend
	 *		26: was coming into his force;
	 *		27: he might have won fame in the end,
	 *		28: so sensitive his nature seemed,
	 *		29: so daring and sweet his thought.
	 *		30: this other man I had dreamed
	 *		31: a drunken, vain-glorious lout.
	 *		32: he had done most bitter wrong
	 *		33: to some who are near my heart,
	 *		34: yet I number him in the song;
	 *		35: he, too, has resigned his part
	 *		36: in the casual comedy;
	 *		37: he, too, has been changed in his turn
	 *		38: transformed utterly:
	 *		39: a terrible beauty is born.
	 */

	char * cipherListRaw[40]={
		"SSBoYXZlIG1ldCB0aGVtIGF0IGNsb3NlIG9mIGRheQ==",
		"Q29taW5nIHdpdGggdml2aWQgZmFjZXM=",
		"RnJvbSBjb3VudGVyIG9yIGRlc2sgYW1vbmcgZ3JleQ==",
		"RWlnaHRlZW50aC1jZW50dXJ5IGhvdXNlcy4=",
		"SSBoYXZlIHBhc3NlZCB3aXRoIGEgbm9kIG9mIHRoZSBoZWFk",
		"T3IgcG9saXRlI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cyBvdGhlciBtYW4gSSBoYWQgZHJlYW1lZA==",
		"QSBkcnVua2VuLCB2YWluLWdsb3Jpb3VzIGxvdXQu",
		"SGUgaGFkIGRvbmUgbW9zdCBiaXR0ZXIgd3Jvbmc=",
		"VG8gc29tZSB3aG8gYXJlIG5lYXIgbXkgaGVhcnQs",
		"WWV0IEkgbnVtYmVyIGhpbSBpbiB0aGUgc29uZzs=",
		"SGUsIHRvbywgaGFzIHJlc2lnbmVkIGhpcyBwYXJ0",
		"SW4gdGhlIGNhc3VhbCBjb21lZHk7",
		"SGUsIHRvbywgaGFzIGJlZW4gY2hhbmdlZCBpbiBoaXMgdHVybiw=",
		"VHJhbnNmb3JtZWQgdXR0ZXJseTo=",
		"QSB0ZXJyaWJsZSBiZWF1dHkgaXMgYm9ybi4="
	};

	string ciphers[40];
	int i;
	string p19Key=randString(16);
	string keystream;

	for(i=0; i<40; i++){
		ciphers[i]=AES128CTR(base64Decode(newString(cipherListRaw[i],0)), p19Key, newString(NULL,8));
	}

	keystream=breakFixedNonceCTRAsRepeatedXOR(ciphers, 40);
	keystream=modifyKey(keystream, ciphers, 40);
}
int main(int argc, char **argv) {
    //test addition, subtraction
    string a = charToS(0x0f);
    string b = charToS(0x01);
    for(int i=0; i<a.len; i++) a.c[i]=0xFF;
    string r = bigIntAdd(a,b);
    //printsint(a);printf(" + ");printsint(b);printf(" = ");printsint(r);PRINTNL;

    //a=newBigInt(r.c, r.len, -1);
    //printsint(a);printf(" + ");printsint(b);printf(" = ");printsint(bigIntAdd(a,b));PRINTNL;

    /*a = randString(3);
    a.sign = -1;
    b=charToS(0xa5);
    r = bigIntAdd(a,b);
    printsint(a);printf(" + ");printsint(b);printf(" = ");printsint(r);
    r = bigIntAdd(b,a);
    printf(" = ");printsint(r);PRINTNL;*/


    srand(time(NULL));
    a = randString(4);
    b = randString(2);
    //printsint(a);printf(" / \n");
    //printsint(b);printf(" = \n");
    string *qr = bigIntDivide(a, b);
    //printsint(qr[0]);printf(" R: "); printsint(qr[1]);PRINTNL;
    if(bigIntComp(a,bigIntAdd(bigIntMultiply(b,qr[0]),qr[1]))==0) {
        printf("Division checks out!\n");
    }

    string n;
    if(1) {
        string *gcd;
        do {
            a = randString(5);
            b = randString(5);
            n = randString(3);
            gcd = extendedEuclidean(a,b,n);
        } while(gcd==NULL);
        printsint(a);
        printf("*");
        printsint(gcd[0]);
        printf("+");
        printsint(b);
        printf("*");
        printsint(gcd[1]);
        printf("=");
        printsint(n);
        PRINTNL;
        if(bigIntComp(bigIntAdd(bigIntMultiply(a,gcd[0]),bigIntMultiply(b,gcd[1])),n)==0) {
            printf("EGCD working.\n");
        }

        else printf("EGCD failed!\n");
        fflush(stdout);
    }

    //testing Montgometry reduction product
    /*a = charToS(0x02);
    n = charToS(0x05);
    r = charToS(0x01);
    int rpow=0;
    while(bigIntComp(r,n)==-1){
    	r = stringLeftShift(r,1);
    	rpow++;
    }
    //printf("r = ");printsint(r);PRINTNL;
    string nprime = extendedEuclidean(r,n,charToS(0x01))[1];
    nprime.sign = 1;
    //printf("nprime = ");printsint(nprime);PRINTNL;fflush(stdout);
    string abar = bigIntDivide(bigIntMultiply(a,r),n)[1];
    //printf("abar = "); printsint(abar);PRINTNL;fflush(stdout);
    printsint(a);printf(" ** 2 mod ");printsint(n);printf(" = ...");PRINTNL;
    string rbar = __monPro(abar, abar, n, nprime, rpow);
    r = __monPro(rbar, charToS(0x01), n, nprime, rpow);
    printf("...");printsint(r);PRINTNL;*/

    //testing modexp;
    a = base16Decode(newString("0177",0));
    b = base16Decode(newString("f9",0));
    n = base16Decode(newString("0184",0));
    printsint(a);
    printf(" ** ");
    printsint(b);
    printf(" mod ");
    printsint(n);
    printf(" = \n");
    printsint(bigIntModExp(a,b,n));
    PRINTNL;


}