Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // changed parts in common.h:
- ...
- int mystdin[2]; // pipes to child process
- int mystdout[2];
- void print_unencrypted_data(char *buf, size_t len) {
- printf("from SSL to bash: %d bytes", (int)len);
- write(mystdin[1],buf,(int)len); // write to child's stdin instead of stdout
- }
- ...
- void do_stdin_read()
- {
- char buf[DEFAULT_BUF_SIZE];
- //ssize_t n = read(STDIN_FILENO, buf, sizeof(buf));
- ssize_t n = read(mystdout[0], buf, sizeof(buf)); // read from child's stdout instead of stdin
- //printf("from shell: %.*s", (int)n, buf);
- if (n>0)
- send_unencrypted_bytes(buf, (size_t)n);
- }
- ...
- // changed part in main:
- int main(int argc, char **argv)
- {
- ...
- if (connect(sockfd, (struct sockaddr*) &addr, sizeof(addr)) < 0)
- die("connect()");
- // added code:
- pipe(mystdin);
- pipe(mystdout);
- int pid = fork();
- if (pid==(pid_t)0) // child: simple echo
- {
- close(mystdin[1]);
- close(mystdout[0]);
- char buf;
- int i;
- while(1)
- {
- read(mystdin[0],&buf,1);
- write(mystdout[1],&buf,1);
- // replace "a" by a very large output:
- if (buf=='a')
- for (i=0; i<160000; i++) // 160000 might have to be increased depending on system
- write(mystdout[1],&buf,1);
- }
- return 0;
- }
- // parent
- close(mystdin[0]);
- close(mystdout[1]);
- if (pid>(pid_t)0)
- {
- struct pollfd fdset[2];
- memset(&fdset, 0, sizeof(fdset));
- fdset[0].fd = mystdout[0]; //STDIN_FILENO; // stdout[0];
- fdset[0].events = POLLIN;
- // original code from here
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement