PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/hydra-7.3/hydra-cisco-enable.c

#
C | 193 lines | 173 code | 18 blank | 2 comment | 85 complexity | 0a455972acdb7eb06ab216c66dbecf67 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0
  1. #include "hydra-mod.h"
  2. extern char *HYDRA_EXIT;
  3. char *buf;
  4. int start_cisco_enable(int s, char *ip, int port, unsigned char options, char *miscptr, FILE * fp) {
  5. char *empty = "";
  6. char *pass, buffer[300];
  7. if (strlen(pass = hydra_get_next_password()) == 0)
  8. pass = empty;
  9. sprintf(buffer, "%.250s\r\n", pass);
  10. if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
  11. return 1;
  12. }
  13. buf = hydra_receive_line(s);
  14. if (buf != NULL && strstr(buf, "assw") != NULL) {
  15. hydra_completed_pair();
  16. free(buf);
  17. if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
  18. return 3;
  19. if (strlen(pass = hydra_get_next_password()) == 0)
  20. pass = empty;
  21. sprintf(buffer, "%.250s\r\n", pass);
  22. if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
  23. return 1;
  24. }
  25. buf = hydra_receive_line(s);
  26. if (strstr(buf, "assw") != NULL) {
  27. hydra_completed_pair();
  28. free(buf);
  29. if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
  30. return 3;
  31. if (strlen(pass = hydra_get_next_password()) == 0)
  32. pass = empty;
  33. sprintf(buffer, "%.250s\r\n", pass);
  34. if (hydra_send(s, buffer, strlen(buffer), 0) < 0) {
  35. return 1;
  36. }
  37. buf = hydra_receive_line(s);
  38. }
  39. }
  40. if (buf != NULL
  41. && (strstr(buf, "assw") != NULL || strstr(buf, "ad ") != NULL || strstr(buf, "attempt") != NULL || strstr(buf, "fail") != NULL || strstr(buf, "denied") != NULL)) {
  42. free(buf);
  43. hydra_completed_pair();
  44. if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
  45. return 3;
  46. return 2;
  47. }
  48. if (buf != NULL)
  49. free(buf);
  50. hydra_report_found_host(port, ip, "cisco-enable", fp);
  51. hydra_completed_pair_found();
  52. return 3;
  53. }
  54. void service_cisco_enable(char *ip, int sp, unsigned char options, char *miscptr, FILE * fp, int port) {
  55. int run = 1, failc = 0, retry = 1, next_run = 1, sock = -1;
  56. int myport = PORT_TELNET, mysslport = PORT_TELNET_SSL;
  57. char buffer[300];
  58. char *login;
  59. hydra_register_socket(sp);
  60. if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0)
  61. return;
  62. while (1) {
  63. next_run = 0;
  64. switch (run) {
  65. case 1: /* connect and service init function */
  66. {
  67. if (sock >= 0)
  68. sock = hydra_disconnect(sock);
  69. // usleep(275000);
  70. if ((options & OPTION_SSL) == 0) {
  71. if (port != 0)
  72. myport = port;
  73. sock = hydra_connect_tcp(ip, myport);
  74. port = myport;
  75. } else {
  76. if (port != 0)
  77. mysslport = port;
  78. sock = hydra_connect_ssl(ip, mysslport);
  79. port = mysslport;
  80. }
  81. if (sock < 0) {
  82. fprintf(stderr, "[ERROR] Child with pid %d terminating, can not connect\n", (int) getpid());
  83. hydra_child_exit(1);
  84. }
  85. /* Cisco AAA Support */
  86. if (strlen(login = hydra_get_next_login()) != 0) {
  87. while ((buf = hydra_receive_line(sock)) != NULL && strstr(buf, "name:") == NULL && strstr(buf, "ogin:") == NULL) {
  88. if (hydra_strcasestr(buf, "ress ENTER") != NULL)
  89. hydra_send(sock, "\r\n", 2, 0);
  90. free(buf);
  91. }
  92. sprintf(buffer, "%.250s\r\n", login);
  93. if (hydra_send(sock, buffer, strlen(buffer), 0) < 0) {
  94. fprintf(stderr, "[ERROR] Child with pid %d terminating, can not send login\n", (int) getpid());
  95. hydra_child_exit(2);
  96. }
  97. }
  98. if (miscptr != NULL) {
  99. while ((buf = hydra_receive_line(sock)) != NULL && strstr(buf, "assw") == NULL) {
  100. if (hydra_strcasestr(buf, "ress ENTER") != NULL)
  101. hydra_send(sock, "\r\n", 2, 0);
  102. free(buf);
  103. }
  104. sprintf(buffer, "%.250s\r\n", miscptr);
  105. if (hydra_send(sock, buffer, strlen(buffer), 0) < 0) {
  106. fprintf(stderr, "[ERROR] Child with pid %d terminating, can not send login\n", (int) getpid());
  107. hydra_child_exit(2);
  108. }
  109. }
  110. buf = hydra_receive_line(sock);
  111. if (hydra_strcasestr(buf, "ress ENTER") != NULL) {
  112. hydra_send(sock, "\r\n", 2, 0);
  113. free(buf);
  114. buf = hydra_receive_line(sock);
  115. }
  116. if (strstr(buf, "assw") != NULL) {
  117. fprintf(stderr, "[ERROR] Child with pid %d terminating - can not login, can not login\n", (int) getpid());
  118. hydra_child_exit(2);
  119. }
  120. free(buf);
  121. next_run = 2;
  122. break;
  123. }
  124. case 2: /* run the cracking function */
  125. {
  126. unsigned char *buf2;
  127. int f = 0;
  128. sprintf(buffer, "%.250s\r\n", "ena");
  129. if (hydra_send(sock, buffer, strlen(buffer), 0) < 0) {
  130. fprintf(stderr, "[ERROR] Child with pid %d terminating, can not send 'ena'\n", (int) getpid());
  131. hydra_child_exit(2);
  132. }
  133. do {
  134. if (f != 0)
  135. free(buf2);
  136. else
  137. f = 1;
  138. if ((buf2 = (unsigned char *) hydra_receive_line(sock)) == NULL) {
  139. if (failc < retry) {
  140. next_run = 1;
  141. failc++;
  142. fprintf(stderr, "[ERROR] Child with pid %d was disconnected - retrying (%d of %d retries)\n", (int) getpid(), failc, retry);
  143. sleep(3);
  144. break;
  145. } else {
  146. fprintf(stderr, "[ERROR] Child with pid %d was disconnected - exiting\n", (int) getpid());
  147. hydra_child_exit(0);
  148. }
  149. }
  150. } while (strstr((char *) buf2, "assw") == NULL);
  151. free(buf2);
  152. if (next_run != 0)
  153. break;
  154. failc = 0;
  155. next_run = start_cisco_enable(sock, ip, port, options, miscptr, fp);
  156. break;
  157. }
  158. case 3: /* clean exit */
  159. sprintf(buffer, "%.250s\r\n", "exit");
  160. if (hydra_send(sock, buffer, strlen(buffer), 0) < 0) {
  161. fprintf(stderr, "[ERROR] Child with pid %d terminating, can not send 'exit'\n", (int) getpid());
  162. hydra_child_exit(0);
  163. }
  164. if (sock >= 0)
  165. sock = hydra_disconnect(sock);
  166. hydra_child_exit(0);
  167. return;
  168. default:
  169. fprintf(stderr, "[ERROR] Caught unknown return code, exiting!\n");
  170. hydra_child_exit(0);
  171. hydra_child_exit(2);
  172. }
  173. run = next_run;
  174. }
  175. }