简体   繁体   English

我怎么知道子进程是否正在等待 C 中的键盘输入

[英]How can I know if child process is waiting for keyboard input in C

I'm working on a buffer overflow exploitation in C (Linux).我正在研究 C (Linux) 中的缓冲区溢出漏洞利用。 Goal of exploitation is to run shell as root .利用的目标是以 root 运行 shell

So my strategy is like this.所以我的策略是这样的。

  1. Guess target address.猜测目标地址。
  2. Run vulnerable program with #1's target address.使用#1 的目标地址运行易受攻击的程序。 (Run by fork-exec) (由 fork-exec 运行)
  3. Check if the program is exploited.检查程序是否被利用。 (whether shell is executed) (是否执行shell)
  4. LOOP until #3 is satisfied.循环直到满足#3。

My problem occurs from #3.我的问题发生在#3。 How can I check if child process executes shell successfully?如何检查子进程是否成功执行 shell?
Or, How can I know if child process is waiting for keyboard input?或者,我如何知道子进程是否正在等待键盘输入?

Here is my code.这是我的代码。

/*
GUESS TARGET_ADDRESS
*/
if(fork()==0){
    execl("./vulnerableProgram", "./vulnerableProgram", "exploitInput.txt", NULL);
}
int check = CHECK_IF_CHILD_PROCESS_RUNS_SHELL()          // <- here is my question
if(check) {
    printf("%s\n", TARGET_ADDRESS);
    break;
}

When child process fails to exploit, the status of child process is like below.当子进程无法利用时,子进程的状态如下所示。

  • Segmentation Fault分段故障
  • Illegal Instructions非法指令
  • exit normally (overflow doesn't occurs due to NULL character among the exploit code)正常退出(由于漏洞利用代码中的NULL字符不会发生溢出)

When a child terminates the program you enter to run it will return or exit normal with value or abnormal.I dont know what are you doing with exploitation and stuff but i can answer your to your question in how you know when the child executes shell successfully.You can tell the parent to wait for child until it's work is done and after you can handle normal or ubnormal execute by WIFEXITED(), if this return true means that execution of child was normal else abnormal.当孩子终止您输入运行的程序时,它将返回或退出正常值或异常。我不知道您在做什么利用和东西,但我可以回答您的问题,您如何知道孩子何时成功执行 shell .你可以告诉父母等待孩子,直到它的工作完成,然后你可以通过WIFEXITED()处理正常或异常执行,如果这个返回true意味着孩子的执行是正常的,否则异常。

waitpid(pid,&status,0);
if(WIFEXITED(status){
    printf("normal with %d", WEXITSTATUS(status));
}else{
  //abnormal
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM