部落格已經轉移
https://noone-hub.github.io/
由上一節教會的動作,我就不提了,直接貼上代碼
#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;
}
由代碼可知關鍵點在hashcode==check_password(argv[1]) 也就是說我們輸入的,經過check_password這個函數變換過後的結果要等于hashcode=0x21DD09EC,從那個函數裡面看,他是把我們輸入的字元串,比如12345678每4個一相加然後易得到這題目是輸入20個字元,然後相加結果要等于那個,是以利用python代碼
collision.py+ buffers
1 #!/usr/bin/env python
2 # coding=utf-8
3 from pwn import *
4 pwn_ssh=ssh(host='pwnable.kr',user='col',password='guest',port=2222)
5 print(pwn_ssh.connected())
6 sh=pwn_ssh.process(argv=['collision','\xc9\xce\xc5\x06' * 4 + '\xcc\xce\xc5\x06'],executable='./col')#那些數字是0x21DD09EC/5計算得到,然後用0x21DD09EC-得到的結果*4
7 print(sh.recvall())
~
~
這題還要懂那個相加是怎麼計算的,在計算機中,32位的,從00000000到FFFFFFFF為一個頭尾,FFFFFFFF+1變成0,而我要做的隻是将0x21DD09EC 拆分成5個字元串,每個字元串有4個位元組