Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This is a basic RAW TCP server. You can use this to make a chat room type thing.
- Made by DaddyL33T
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #define MAXFDS 1000000
- #define BUFFER_SIZE 1024
- #define on_error(...) { fprintf(stderr, __VA_ARGS__); fflush(stderr); exit(1); }
- static volatile int OperatorsConnected = 0;
- struct login_info {
- char username[20];
- char password[20];
- };
- static struct login_info accounts[22];
- struct telnetdata_t {
- int connected;
- } managements[MAXFDS];
- struct args {
- int sock;
- struct sockaddr_in cli_addr;
- };
- int fdgets(unsigned char *buffer, int bufferSize, int fd) {
- int total = 0, got = 1;
- while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
- return got;
- }
- void trim(char *str) {
- int i;
- int begin = 0;
- int end = strlen(str) - 1;
- while (isspace(str[begin])) begin++;
- while ((end >= begin) && isspace(str[end])) end--;
- for (i = begin; i <= end; i++) str[i - begin] = str[i];
- str[i - begin] = '\0';
- }
- int Search_in_File(char *str)
- {
- FILE *fp;
- int line_num = 0;
- int find_result = 0, find_line=0;
- char temp[512];
- if((fp = fopen("logins.txt", "r")) == NULL){
- return(-1);
- }
- while(fgets(temp, 512, fp) != NULL){
- if((strstr(temp, str)) != NULL){
- find_result++;
- find_line = line_num;
- }
- line_num++;
- }
- if(fp)
- fclose(fp);
- if(find_result == 0)return 0;
- return find_line;
- }
- void *titleWriter(void *sock)
- {
- int thefd = (int)sock;
- char string[2048];
- while(1)
- {
- memset(string, 0, 2048);
- sprintf(string, "%c]0; [+] Simple Telnet Base [+]%c", '\033', '\007');
- if(send(thefd, string, strlen(string), MSG_NOSIGNAL) == -1) return;
- sleep(3);
- }
- }
- void broadcast(char *msg, int us, char *sender)
- {
- int sendMGM = 1;
- if(strcmp(msg, "PING") == 0) sendMGM = 0;
- char *wot = malloc(strlen(msg) + 10);
- memset(wot, 0, strlen(msg) + 10);
- strcpy(wot, msg);
- trim(wot);
- time_t rawtime;
- struct tm * timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- char *timestamp = asctime(timeinfo);
- trim(timestamp);
- int i;
- for(i = 0; i < MAXFDS; i++)
- {
- if(i == us || (sendMGM == 0 || !managements[i].connected)) continue;
- if(sendMGM && managements[i].connected)
- {
- send(i, "\x1b[1;35m", 9, MSG_NOSIGNAL);
- send(i, sender, strlen(sender), MSG_NOSIGNAL);
- send(i, ": ", 2, MSG_NOSIGNAL);
- }
- send(i, msg, strlen(msg), MSG_NOSIGNAL);
- if(sendMGM && managements[i].connected) send(i, "\r\n\x1b[1;31m~>\x1b[36m ", 19, MSG_NOSIGNAL);
- else send(i, "\n", 1, MSG_NOSIGNAL);
- }
- free(wot);
- }
- void *mainShit(void *sock)
- {
- char usernamez[80];
- int thefd = (int)sock;
- int find_line;
- OperatorsConnected++;
- char counter[2048];
- memset(counter, 0, 2048);
- char buf[2048];
- char* nickstring;
- char* username;
- char* password;
- memset(buf, 0, sizeof buf);
- char botnet[2048];
- memset(botnet, 0, 2048);
- FILE *fp;
- int i=0;
- int c;
- fp=fopen("logins.txt", "r");
- while(!feof(fp))
- {
- c=fgetc(fp);
- ++i;
- }
- int j=0;
- rewind(fp);
- while(j!=i-1)
- {
- fscanf(fp, "%s %s", accounts[j].username, accounts[j].password);
- ++j;
- }
- if(send(thefd, "\x1b[35mName:\x1b[33m ", 16, MSG_NOSIGNAL) == -1) goto end;
- if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
- trim(buf);
- sprintf(usernamez, buf);
- nickstring = ("%s", buf);
- find_line = Search_in_File(nickstring);
- if(strcmp(nickstring, accounts[find_line].username) == 0){
- if(send(thefd, "\x1b[35mPasscode:\x1b[30m ", 20, MSG_NOSIGNAL) == -1) goto end;
- if(fdgets(buf, sizeof buf, thefd) < 1) goto end;
- trim(buf);
- if(strcmp(buf, accounts[find_line].password) != 0) goto failed;
- memset(buf, 0, 2048);
- if(send(thefd, "\x1b[0;37m---> Credentials Are Correct <---\r\n--->Please Wait While We Prepare Stuff<---\r\n", 100, MSG_NOSIGNAL) == -1) goto end;
- sleep(3);
- goto dope;
- }
- failed:
- if(send(thefd, "\033[1A", 6, MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, "\x1b[0;37m***********************************\r\n", 50, MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, "\x1b[0;37m* Incorrect Credentials! *\r\n", 50, MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, "\x1b[0;37m***********************************\r\n", 50, MSG_NOSIGNAL) == -1) goto end;
- sleep(5);
- goto end;
- dope:
- titleWriter(sock);
- char banner1 [80];
- char banner2 [80];
- char banner3 [80];
- sprintf(banner1, "\x1b[0;37mThis is a blank TCP server coded in C\r\n");
- sprintf(banner2, "\x1b[0;37mThere Are Currently %s People Connected\r\n", OperatorsConnected);
- sprintf(banner3, "\x1b[0;37mType [1;35mHELP [0;37mfor commands\r\n");
- char clearscreen [2048];
- memset(clearscreen, 0, 2048);
- if(send(thefd, "\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner1, strlen(banner1), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner2, strlen(banner2), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner3, strlen(banner3), MSG_NOSIGNAL) == -1) goto end;
- while(1) {
- if(send(thefd, "\x1b[1;31m~>\x1b[36m ", 19, MSG_NOSIGNAL) == -1) goto end;
- break;
- }
- managements[thefd].connected = 1;
- while(fdgets(buf, sizeof buf, thefd) > 0)
- {
- if(strstr(buf, "HELP")) {
- char helpline1 [80];
- char helpline2 [80];
- char helpline3 [80];
- char helpline4 [80];
- sprintf(helpline1, " \x1b[0;31m[+] [1;35mCommands [0;31m[+]\r\n");
- sprintf(helpline2, " CLEAR---| Clears The Screen?\r\n");
- sprintf(helpline3, " HELP----| Shows This Ya Retard\r\n");
- sprintf(helpline4, " EXIT----| Disconnects From This\r\n");;
- if(send(thefd, helpline1, strlen(helpline1), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, helpline2, strlen(helpline2), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, helpline3, strlen(helpline3), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, helpline4, strlen(helpline4), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, "\x1b[1;31m~>\x1b[36m ", 19, MSG_NOSIGNAL) == -1) goto end;
- continue;
- }
- if(strstr(buf, "CLEAR")){
- if(send(thefd, "\033[2J\033[1;1H", 14, MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner1, strlen(banner1), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner2, strlen(banner2), MSG_NOSIGNAL) == -1) goto end;
- if(send(thefd, banner3, strlen(banner3), MSG_NOSIGNAL) == -1) goto end;
- }
- if(strstr(buf, "LOGOUT")) {
- sprintf(botnet, "Goodbye -> %s\r\n", accounts[find_line].username, buf);
- goto end;
- }
- trim(buf);
- if(send(thefd, "\x1b[1;31m~>\x1b[36m ", 19, MSG_NOSIGNAL) == -1) goto end;
- if(strlen(buf) == 0) continue;
- printf("%s: \"%s\"\n",accounts[find_line].username, buf);
- FILE *logFile;
- logFile = fopen("Activity.log", "a");
- fprintf(logFile, "%s: \"%s\"\n",accounts[find_line].username, buf);
- fclose(logFile);
- broadcast(buf, thefd, usernamez);
- memset(buf, 0, 2048);
- }
- end:
- managements[thefd].connected = 0;
- close(thefd);
- OperatorsConnected--;
- }
- int main (int argc, char *argv[]) {
- if (argc < 2) on_error("Usage: %s [port]\n", argv[0]);
- int port = atoi(argv[1]);
- int server_fd, client_fd, err;
- struct sockaddr_in server, client;
- char buf[BUFFER_SIZE];
- server_fd = socket(AF_INET, SOCK_STREAM, 0);
- if (server_fd < 0) on_error("Could not create socket\n");
- server.sin_family = AF_INET;
- server.sin_port = htons(port);
- server.sin_addr.s_addr = htonl(INADDR_ANY);
- int opt_val = 1;
- setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt_val, sizeof opt_val);
- err = bind(server_fd, (struct sockaddr *) &server, sizeof(server));
- if (err < 0) on_error("Could not bind socket\n");
- err = listen(server_fd, 128);
- if (err < 0) on_error("Could not listen on socket\n");
- printf("Server is listening on %d\n", port);
- while (1) {
- socklen_t client_len = sizeof(client);
- client_fd = accept(server_fd, (struct sockaddr *) &client, &client_len);
- if (client_fd < 0) on_error("Could not establish new connection\n");
- mainShit(client_fd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement