PWN:Bad Seed

感觉没什么太特殊的地方,都是把原本的代码拿过来用而已,所以就觉得这些东西,没什么意思。

上面的代码是我从文章中自己摘出来的,然后自己看了看文章的解决方案写出的代码。


第一题:
破解下面的程序:

random.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h> 

int main()
{
    srand((unsigned int)time(NULL));
    int targetnum=rand();
    int destnum;
    printf("Please enter:\n");
    scanf("%d",&destnum);
    if(destnum==targetnum)
    {
        printf("OK\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
} 

solve.c

#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<stdint.h>
#include<string.h>

int main()
{
    uint32_t rand_num;
    srand((unsigned int)time(NULL)); //seed with current time
    rand_num = rand();
    //uint32_t ans;
    printf("%d\n", rand_num);	
}

执行结果:

$ ./solve | ./random 
Please enter:
OK

第二题:
破解下面的程序:

random.c

#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main()
{
	srand((unsigned int)time(NULL));
	int array[6]; 
	array[0] = 0x79;
  	array[1] = 0x12c97f;
  	array[2] = 0x135f0f8;
  	array[3] = 0x74acbc6;
  	array[4]=0x56c614e;
  	array[5]=0xffffffe2;
  	int j = 0;
  	while (j < 6) 
	{
    	int randVal = rand();
    	array[(long)j] = array[(long)j] - ((randVal%10) + -1);
    	j = j + 1;
  	}
  	int targetNumber = 0;
  	int i = 0;
  	while (i < 6) 
	{
    	targetNumber = targetNumber + array[(long)i];
    	i = i + 1;
  	}
  	int destnum;
  	scanf("%d",&destnum);

  	if(targetNumber==destnum)
  	{
  		printf("OK\n");	
	}
	else
	{
		printf("NO\n");
	}
	//printf("targetNumber=%d\n",targetNumber);
  	//printf("destnum=%d\n",destnum);
  	return 0;	
 } 

solve.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
	srand((unsigned int)time(NULL));
	int array[6]; 
	array[0] = 0x79;
  	array[1] = 0x12c97f;
  	array[2] = 0x135f0f8;
  	array[3] = 0x74acbc6;
  	array[4]=0x56c614e;
  	array[5]=0xffffffe2;
  	int j = 0;
  	while (j < 6) 
	{
    	int randVal = rand();
    	array[(long)j] = array[(long)j] - ((randVal % 10) + -1);
    	j = j + 1;
  	}
  	int targetNumber = 0;
  	int i = 0;
  	while (i < 6) 
	{
    	targetNumber = targetNumber + array[(long)i];
    	i = i + 1;
  	}
  	printf("%d\n",targetNumber);
}

第三题:
破解下面的程序:

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>
int main()
{
	char target [504];
	char input [512];
  	srand((unsigned int)time(NULL));
  	int i = 0;
  	while (i < 50) 
	{
    		int randVal = rand();
    		printf("%d days without an incident.\n",i);
    		sprintf(target,"%d",(randVal % 100));
    		scanf(" %10s",input);
   			strtok(input,"\n");
    		int check = strcmp(target,input);
    		if (check != 0) 
		{
      			puts("Well that didn\'t take long.");
      			printf("You should have used %s.\n",target);
      			exit(0);
    		}
    		i = i + 1;
  	}
  	puts("Success");
  	return 0; 
 } 

solve.c

#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>

int main()
{
	char target [504];
	char input [512];
  	srand((unsigned int)time(NULL));
  	int i = 0;
  	while (i < 50) 
	{
    	int randVal = rand();
    	sprintf(target,"%d",(randVal % 100));
   		strtok(input,"\n");
   		printf("%s\n",target);
   		i++;
   	}
  	
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值