gdb破解&&密码分析CTF

时间:2018-03-11 14:45:06

标签: debugging gdb cracking gdb-python

你好我们正在玩CTF而且我必须破解一个程序来获取shell的源代码是:

/*
* gcc ch21.c -lcrypt -o ch21
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crypt.h>
#include <sys/types.h>
#include <unistd.h>

int main (int argc, char *argv[]) {
char pid[16];
char *args[] = { "/bin/bash", "-p", 0 };

snprintf(pid, sizeof(pid), "%i", getpid());
if (argc != 2)
    return 0;

printf("%s=%s",argv[1], crypt(pid, "$1$awesome"));

if (strcmp(argv[1], crypt(pid, "$1$awesome")) == 0) {
    printf("WIN!\n");
execve(args[0], &args[0], NULL);

} else {
    printf("Fail... :/\n");
}
return 0;
}

现在我用gdb调试它,因为我从源代码了解到我必须在运行时输入proccessid(PID)以获得成功的shell GDB-PEDA 我试过在断点期间getpid但是如何继续使用gdb的proccess id只运行命令传递给程序任何帮助!

任何 通知

1 个答案:

答案 0 :(得分:1)

不确定我是否正确理解了您的问题,但是当达到限制并且最大值通常在2 ^ 15左右时,PID的范围和周期受到限制。您可以简单地运行一个循环,该循环将运行潜在的PID以匹配将为该过程分配的循环。

这样的事情可以做到:

import os, crypt, subprocess

pid = os.getpid()+50 #safe buffer for things created after python script was started
print "Selected: ",pid
for i in range(32768):
    sp = subprocess.Popen(['./ch21', crypt.crypt(str(pid), "$1$awesome")], stdout=subprocess.PIPE)
    output = sp.stdout.readline()
    if "Fail" not in output:
            print output
            break