pwn

题目代码如下,要求是碰撞出一个20字节长度的字符串转换为4个int类型相加之后的值等于题目给定的hashcode

#include <stdio.h>
#include <string.h>
unsigned long hashcode = 0x21DD09EC;
unsigned long check_password(const char* p){
        int* ip = (int*)p;
        int i;
        int res=0;
        for(i=0; i<5; i++){
                res += ip[i];
        }
        return res;
}

int main(int argc, char* argv[]){
        if(argc<2){
                printf("usage : %s [passcode]\n", argv[0]);
                return 0;
        }
        if(strlen(argv[1]) != 20){
                printf("passcode length should be 20 bytes\n");
                return 0;
        }

        if(hashcode == check_password( argv[1] )){
                system("/bin/cat flag");
                return 0;
        }
        else
                printf("wrong passcode.\n");
        return 0;
}


就直接来碰撞吧。。

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


#define LEN 4
unsigned char buf[LEN] = "\x00\x00\x00\x00";

int main(void)
{
    div_t div_val;
    unsigned long hashcode = 0x21DD09EC;
    div_val = div(hashcode,5);
    //printf("%d,%d\n",x.quot,x.rem);
    int *tmp;
    int j;
    for(j=LEN-1;j>=0;j--){
        unsigned char i = 0x01;
        for(;i<=0xff;i++){
            buf[j] = i;
            tmp = (int *)&buf;
            if(*tmp == div_val.quot){
                printf("playload is:\t");
                printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
                printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
                printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
                printf("\\x%x\\x%x\\x%x\\x%x",buf[0],buf[1],buf[2],buf[3]);
                printf("\\x%x\\x%x\\x%x\\x%x\n",buf[0]+div_val.rem,buf[1],buf[2],buf[3]);
            }
            if(*tmp < div_val.quot) {
                continue;
            }else{
                buf[j] = i-0x01;
                break;
            }
        }
    }
    exit(0);
}


转载于:https://my.oschina.net/firebroo/blog/548613

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值