管,叉,dup2和麻烦

时间:2013-11-10 11:38:44

标签: c fork pipe dup2

我想通过两个管道执行metasploit与它进行通信,但我对这种通信有麻烦。当我运行我的程序时,我收到此错误:“stty:标准输入:不恰当的设备ioctl”,我没有收到metasploit promt。

只选择一个漏洞。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char** argv)
{
  int pipeIn[2];
    int pipeOut[2];
    pipe(pipeIn);
    pipe(pipeOut);
    pid_t hijo=fork();
    if (hijo==0) {
        dup2(pipeIn[0], STDIN_FILENO);
        dup2(pipeOut[1], STDOUT_FILENO);
        dup2(pipeOut[1], STDERR_FILENO);

        close(pipeIn[0]);
        close(pipeOut[1]);
         close(pipeIn[1]);
        close(pipeOut[0]);
        char* argv[]={"msfconsole", NULL};
        execvp("msfconsole", argv);
    }else if (hijo==-1) {
        perror("fork");
        exit(EXIT_FAILURE);
    } else{//padre
        close(pipeIn[0]);
        close(pipeOut[1]);
        char buf[1024];
        int count;

         bool b=true;
        int ccount=0;
         for (;b;){
            while (b && (count=read(pipeOut[0], buf, sizeof(char) * 1024))>0){
                buf[count]='\0';
                printf ("%s", buf);
                if (strstr(buf, "msf >")!= 0){ 
                    write(pipeIn[1], "use exploit/windows/fileformat/adobe_pdf_embedded_exe_nojs \n\0 ", sizeof(char)*1024);
                    if (ccount++>=1){ printf ("encontrado"); b=false; }
            } }

        }
              close(pipeIn[1]);
              close(pipeOut[0]);
          }}

它显示了这个:

 _                                                    _
/ \    /\         __                         _   __  /_/ __
| |\  / | _____   \ \           ___   _____ | | /  \ _   \ \
| | \/| | | ___\ |- -|   /\    / __\ | -__/ | || | || | |- -|
|_|   | | | _|__  | |_  / -\ __\ \   | |    | | \__/| |  | |_
      |/  |____/  \___\/ /\ \\___/   \/     \__|    |_\  \___\


       =[ metasploit v4.7.2-1 [core:4.7 api:1.0]
+ -- --=[ 1211 exploits - 733 auxiliary - 202 post
+ -- --=[ 317 payloads - 30 encoders - 8 nops

stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
^C

0 个答案:

没有答案