Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. #define PORT 50105
  2.  
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <sys/types.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <arpa/inet.h>
  9. #include <pwd.h>
  10. #include <unistd.h>
  11. #include <syslog.h>
  12. #include <stdarg.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15.  
  16. static void usage(char *);
  17.  
  18. int main(int argc, char **argv)
  19. {
  20. char buf[1024];
  21. char cmd[512];
  22. char *pass;
  23.  
  24. int soc_des;
  25. int soc_cli;
  26. int soc_rc;
  27. int i;
  28.  
  29. socklen_t lenght;
  30.  
  31. struct sockaddr_in serv_addr;
  32. struct sockaddr_in client_addr;
  33.  
  34. (argc > 1) ? pass=argv[1] : usage(argv[0]);
  35.  
  36. soc_des = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  37.  
  38. if (soc_des == -1)
  39. {
  40. perror("socket");
  41. exit(-1);
  42. }
  43.  
  44. bzero((char *)&serv_addr, sizeof(serv_addr));
  45.  
  46. serv_addr.sin_family = AF_INET;
  47. serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  48. serv_addr.sin_port = htons(PORT);
  49.  
  50. soc_rc = bind(soc_des, (struct sockaddr *) & serv_addr, sizeof(serv_addr));
  51.  
  52. if (soc_rc != 0)
  53. {
  54. perror("bind");
  55. exit(-1);
  56. }
  57.  
  58. if (fork() != 0)
  59. exit(0);
  60.  
  61. soc_rc = listen(soc_des, 5);
  62.  
  63. if (soc_rc != 0)
  64. {
  65. perror("listen");
  66. exit(0);
  67. }
  68.  
  69. while (1)
  70. {
  71. lenght = sizeof(client_addr);
  72. soc_cli = accept(soc_des, (struct sockaddr *) & client_addr,&lenght);
  73.  
  74. if (soc_cli < 0)
  75. exit(0);
  76.  
  77. if (fork() != 0)
  78. {
  79. for(i=0;i<3;i++)
  80. {
  81. dup2(soc_cli, 0);
  82. dup2(soc_cli, 1);
  83. dup2(soc_cli, 2);
  84. snprintf(cmd,sizeof(cmd),"What drugs do you abuse? :");
  85. write(soc_cli, cmd,strlen(cmd));
  86. fgets(buf, sizeof(buf), stdin);
  87. strtok(buf, "\n");
  88. strtok(buf,"\r");
  89.  
  90. if (!strcmp(buf,argv[1]))
  91. {
  92. snprintf(cmd,sizeof(cmd),"/sbin/ipfw add 10 allow ip from %s to any in via igb0",inet_ntoa(client_addr.sin_addr));
  93. system(cmd);
  94. syslog(LOG_NOTICE,"SOLknocker: Allow ip from \"%s\" \n",inet_ntoa(client_addr.sin_addr));
  95. printf("All your drugs are belong to us!\n");
  96. close(soc_cli);
  97. exit(0);
  98. }
  99. else
  100. {
  101. syslog(LOG_WARNING, "SOLkocker: Failed to authenticate from \"%s\"\n", inet_ntoa(client_addr.sin_addr));
  102. printf("Go to hell!\n");
  103. }
  104. }
  105. snprintf(cmd,sizeof(cmd),"/sbin/ipfw add 11 deny ip from %s to any in via igb0",inet_ntoa(client_addr.sin_addr));
  106. system(cmd);
  107. close(soc_cli);
  108. exit(0);
  109. }
  110. close(soc_cli);
  111. }
  112. }
  113.  
  114. static void usage(char *s)
  115. {
  116. printf("usage: %s password\n",s);
  117. exit(-1);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement