大家好,我正在玩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)才能成功地使用-PEDA,我在断点期间尝试过getpid,但是如何继续使用进程id,gdb只运行命令,将输入传递给程序--任何帮助!
任何通知!
发布于 2018-03-12 21:28:35
不确定我是否正确地理解了您的问题,但是PID在达到极限时在范围和周期上是有限的,最大值通常在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
breakhttps://stackoverflow.com/questions/49221254
复制相似问题