本文记录了 pwnable.kr 中 Collision (col) 题目的解题过程。核心考点是 C 语言的指针类型转换机制与内存的字节序排布。程序将输入的 20 字节字符数组强制转换为 5 个 32 位 int 型整数并求和 。为了使求和结果等于目标哈希值 0x21DD09EC,解题思路巧妙地利用了简单的数学拆分,将目标值分为 4 个 113626825 与 1 个 113626824。最后,将其转换为小端序(Little Endian)十六进制机器码拼接作为参数传入,成功绕过哈希校验并获取 flag。 本文记录了 pwnable.kr 中 Collision (col) 题目的解题过程。核心考点是 C 语言的指针类型转换机制与内存的字节序排布。程序将输入的 20 字节字符数组强制转换为 5 个 32 位 int 型整数并求和 。为了使求和结果等于目标哈希值 0x21DD09EC,解题思路巧妙地利用了简单的数学拆分,将目标值分为 4 个 113626825 与 1 个 113626824。最后,将其转换为小端序(Little Endian)十六进制机器码拼接作为参数传入,成功绕过哈希校验并获取 flag。

Collision

#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] )){
                setregid(getegid(), getegid());
                system("/bin/cat flag");
                return 0;
        }
        else
                printf("wrong passcode.\n");
        return 0;
}

这是源代码,这题简单,难点在于如何计算。只需结果等于hashcode即可

hashcode转换为十进制是:568134124

所以可以构造:113626825*4+113626824=568134124

再转换为16进制

printf '\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC8\xCE\xC5\x06' | ./col $(cat)
This post has not been translated to English yet.

Collision

#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] )){
                setregid(getegid(), getegid());
                system("/bin/cat flag");
                return 0;
        }
        else
                printf("wrong passcode.\n");
        return 0;
}

这是源代码,这题简单,难点在于如何计算。只需结果等于hashcode即可

hashcode转换为十进制是:568134124

所以可以构造:113626825*4+113626824=568134124

再转换为16进制

printf '\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC9\xCE\xC5\x06\xC8\xCE\xC5\x06' | ./col $(cat)