I want to execute metasploit by two pipes to communicate with it, but I have troubles with that communication. When I run my program, I get this error: "stty: standard input: Inappropriate ioctl for device" and I don't receive the metasploit promt.
just select an exploit.
This is my code:
Code:
#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]);
}}
It shows this:
Code:
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMM MMMMMMMMMM
MMMN$ vMMMM
MMMNl MMMMM MMMMM JMMMM
MMMNl MMMMMMMN NMMMMMMM JMMMM
MMMNl MMMMMMMMMNmmmNMMMMMMMMM JMMMM
MMMNI MMMMMMMMMMMMMMMMMMMMMMM jMMMM
MMMNI MMMMMMMMMMMMMMMMMMMMMMM jMMMM
MMMNI MMMMM MMMMMMM MMMMM jMMMM
MMMNI MMMMM MMMMMMM MMMMM jMMMM
MMMNI MMMNM MMMMMMM MMMMM jMMMM
MMMNI WMMMM MMMMMMM MMMM# JMMMM
MMMMR ?MMNM MMMMM .dMMMM
MMMMNm `?MMM MMMM` dMMMMM
MMMMMMN ?MM MM? NMMMMMN
MMMMMMMMNe JMMMMMNMMM
MMMMMMMMMMNm, eMMMMMNMMNMM
MMMMNNMNMMMMMNx MMMMMMNMMNMMNM
MMMMMMMMNMMNMMMMm+..+MMNMMNMNMMNMMNMM
http://metasploit.pro
=[ 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
I'm very worried. I have an assignment that is due in 3 weeks, and also tute exercises which I can't seem to understand and work out.
Okay, the question:
The parent process will convert the command arguments into integer values using atoi() and store them into an integer array which you will... (2 Replies)
I'm having difficulty understanding the purposes of using dup/dup2 when involving forks.
for example, if we call fork() once, that is, we are creating a child process. In what cases would we need to use dup or dup2 to duplicate the file descriptors for standard output and standard error? What... (1 Reply)
Hi,
i have in one program such a pice of code
................
static int old_stderr_handle = -1;
static int old_stdout_handle = -1;
log_handle = open(log_file_name,O_CREAT|O_RDWR,932);
old_stderr_handle = dup(STDERR_FILENO);
if (dup2(log_handle,STDERR_FILENO) < 0)
{
//... (1 Reply)
int redirect()
{
int fd,rc;
fd = open("sample.DAT",O_CREAT | O_RDWR , 00777 );
rc = dup2(fd , 1 ) ;
close (fd );
return 0;
}
I used the above to redirect all the cout statements to sample.DAT. process is redirecting the output and I had two questions
1. All stdout/cout statements... (2 Replies)
Hi all,I'm reading <Advanced programming in the UNIX environment>,that book asked the reader to implement a function which has same functions with dup2 without calling fcntl.Could anyone give me a tip?Any help will be appreciated.:) (8 Replies)
Hello, I'm stuck and this is a matter which I need to resolve quite fast (but I couldn't post in the "Emergency" section); the problem is this :
I have created a chat program in which the client sends the sentence to the server and then the server should send it to all the clients connected,... (2 Replies)
Hi, I will try to keep my post as compressed as my title was.
I am writing on pseudo code on a recursive function that I want to read from the one-above function-run and then give the result to the function-run down below until a stop is triggered. Example:
$ ls -la | grep x | sort
In my... (2 Replies)
is it possible to duplicate file descriptors(opened by a different process) with the help of dup or dup2. the two process do not share parent child relationship as well. (2 Replies)
What this code should do is: there are parent.cpp and child.cpp. Parent will send whatever is in the buffer to child and child will send back whatever received to parent. I do not know what I am doing wrong. I am confused what is missing in the parent and what else I should include into the child.... (1 Reply)
Discussion started by: ramono
1 Replies
LEARN ABOUT REDHAT
ioctl
IOCTL(2) Linux Programmer's Manual IOCTL(2)NAME
ioctl - control device
SYNOPSIS
#include <sys/ioctl.h>
int ioctl(int d, int request, ...);
DESCRIPTION
The ioctl function manipulates the underlying device parameters of special files. In particular, many operating characteristics of charac-
ter special files (e.g. terminals) may be controlled with ioctl requests. The argument d must be an open file descriptor.
The second argument is a device-dependent request code. The third argument is an untyped pointer to memory. It's traditionally char *argp
(from the days before void * was valid C), and will be so named for this discussion.
An ioctl request has encoded in it whether the argument is an in parameter or out parameter, and the size of the argument argp in bytes.
Macros and defines used in specifying an ioctl request are located in the file <sys/ioctl.h>.
RETURN VALUE
Usually, on success zero is returned. A few ioctls use the return value as an output parameter and return a nonnegative value on success.
On error, -1 is returned, and errno is set appropriately.
ERRORS
EBADF d is not a valid descriptor.
EFAULT argp references an inaccessible memory area.
ENOTTY d is not associated with a character special device.
ENOTTY The specified request does not apply to the kind of object that the descriptor d references.
EINVAL Request or argp is not valid.
CONFORMING TO
No single standard. Arguments, returns, and semantics of ioctl(2) vary according to the device driver in question (the call is used as a
catch-all for operations that don't cleanly fit the Unix stream I/O model). See ioctl_list(2) for a list of many of the known ioctl calls.
The ioctl function call appeared in Version 7 AT&T Unix.
SEE ALSO execve(2), fcntl(2), ioctl_list(2), mt(4), sd(4), tty(4)BSD Man Page 2000-09-21 IOCTL(2)