Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- extern char** environ;
- int main() {
- int input_pipes[2];
- if (pipe(input_pipes) < 0){
- printf("can't open pipe");
- exit(1);
- }
- char* bufToWrite = (char*)malloc(1024*1024);
- strcpy(bufToWrite, "http://yandex.ru");
- if (write(input_pipes[1], &bufToWrite, sizeof(bufToWrite)) != sizeof(bufToWrite)){
- printf("can't write into pipe");
- exit(1);
- }
- char* bufToRead = (char*)malloc(1024*1024);
- read(input_pipes[0], &bufToRead, sizeof(bufToRead));
- char* fifoName = (char*)malloc(255);
- strcpy(fifoName, "bashFifo");
- unlink(fifoName);
- if (mkfifo(fifoName, O_RDWR | O_CREAT | S_IRWXU | O_NONBLOCK) < 0){
- printf("can't create bash fifo");
- exit(1);
- }
- char* query = (char*)malloc(1024*1024);
- strcpy(query, "curl ");
- strcat(query, bufToRead);
- strcat(query, " >");
- strcat(query, fifoName);
- char* args[] = {"/bin/bash", "-c", query, NULL};
- pid_t pid = fork();
- if (pid == 0){
- execv(args[0], args);
- printf("error in exec process"); // successful exec shouldn't be here
- }
- char* readFromBash = (char*)malloc(256);
- int bashFD;
- if ((bashFD = open(fifoName, O_RDONLY)) < 0){
- printf("error opening bash fifo");
- exit(1);
- }
- read(bashFD, &readFromBash, 256);
- printf("\n--------\n%s", readFromBash);
- close(bashFD);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement