Advertisement
Guest User

Untitled

a guest
Jun 21st, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <pthread.h>
  3. #include <string.h>
  4. #include <curl/curl.h>
  5. #include <stdlib.h>
  6. using namespace std;
  7.  
  8. #define MAX 4
  9.  
  10. struct info {
  11.     int site_num;
  12.     string website;
  13.     string is_found;
  14.     string post_data;
  15. };
  16.  
  17. string word;
  18. bool cracked = false;
  19. struct info info_array[MAX];
  20.  
  21. void *webCrack(void *thread_arg);
  22. int writer(char *data, size_t size, size_t nmemb, std::string *page);
  23.  
  24. int main(int argc, char *argv[])
  25. {
  26.     if(argc != 2 || strlen(argv[1]) != 32)
  27.     {
  28.          cout << "\nusage: ./webhash <md5Hash>\n";
  29.          exit(-1);
  30.     }
  31.  
  32.     pthread_t threads[MAX];
  33.     pthread_attr_t attr;
  34.     int r_val, x;
  35.     void *status;
  36.  
  37.     /* Set it as joinable explicitly incase the users implementation doesn't by default */
  38.     pthread_attr_init(&attr);
  39.     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
  40.  
  41.     for(x = 0; x < MAX; x++)
  42.     {
  43.          switch(x) /* Fill out structs to be passed to the main routine */
  44.          {
  45.               case 0:
  46.                    info_array[x].website = "http://hashcrack.com/index.php";
  47.                    info_array[x].is_found = "class=hervorheb2>";  //+17 </span></div></TD>
  48.                    info_array[x].post_data = "hash=" + (string)argv[1] + "&Submit=Submit";
  49.                    info_array[x].site_num = x;
  50.                    break;
  51.               case 1:
  52.                    info_array[x].website = "http://md5crack.com/crackmd5.php";
  53.                    info_array[x].is_found = "md5(\"";
  54.                    info_array[x].post_data = "term=" + (string)argv[1] + "&crackbtn=Crack that hash baby!";
  55.                    info_array[x].site_num = x;
  56.                    break;
  57.               case 2:
  58.                    info_array[x].website = "http://passcracking.com/index.php";
  59.                    info_array[x].is_found = "#FF0000>";
  60.                    info_array[x].post_data = "datafromuser=" + (string)argv[1];
  61.                    info_array[x].site_num = x;
  62.                    break;
  63.               case 3:
  64.                    info_array[x].website = "http://md5decryption.com/index.php";
  65.                    info_array[x].is_found = "Text: </b>";
  66.                    info_array[x].post_data = "hash=" + (string)argv[1] + "&submit=Decrypt It!";
  67.                    info_array[x].site_num = x;
  68.                    break;
  69.          }
  70.  
  71.          /* Let there be threads! */
  72.          if((r_val = pthread_create(&threads[x], NULL, webCrack, (void *) &info_array[x])))
  73.          {
  74.               cout << "\n\nError creating threads\n\n";
  75.               exit(-1);
  76.          }
  77.     }
  78.  
  79.     /* Clean up the attribute and then join */
  80.     pthread_attr_destroy(&attr);
  81.     for(x = 0; x < MAX; x++)
  82.     {
  83.          if((r_val = pthread_join(threads[x], &status)))
  84.          {
  85.               cout << "\n\nError joining threads\n\n";
  86.               exit(-1);
  87.          }
  88.     }
  89.  
  90.     cracked == true ? cout << "\nFound!\n\n" << argv[1] << ":" << word << "\n\n" : cout << "\nNot Found!\n\n";
  91.     pthread_exit(NULL);
  92. }
  93.  
  94. void *webCrack(void *thread_arg)
  95. {
  96.     if(cracked == true) pthread_exit(NULL);
  97.    
  98.     struct info *thread_data;
  99.     thread_data = (struct info*)thread_arg;
  100.     CURL *curl;
  101.     CURLcode r_val;
  102.     string page;
  103.     size_t pos;
  104.  
  105.     curl = curl_easy_init();
  106.     curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); /* for threading */
  107.     curl_easy_setopt(curl, CURLOPT_URL, thread_data->website.c_str());
  108.     curl_easy_setopt(curl, CURLOPT_POSTFIELDS, thread_data->post_data.c_str());
  109.     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
  110.     curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
  111.     r_val = curl_easy_perform(curl);
  112.  
  113.     pos = page.find(thread_data->is_found);
  114.     if(pos != string::npos)
  115.     {
  116.          cracked = true;
  117.          switch(thread_data->site_num) /* Extract cracked hash from webpage */
  118.          {
  119.               case 0: word = page.substr((pos + 17), (page.find("</span></div></TD>")) - (pos + 17)); break;
  120.               case 1: word = page.substr((pos + 5), (page.find("\")")) - (pos + 5)); break;
  121.               case 2: word = page.substr((pos + 8), (page.find_first_of("<", (pos + 8))) - (pos + 8)); break;
  122.               case 3: word = page.substr((pos + 10), (page.find("</font><br/><center>")) - (pos + 10)); break;
  123.          }
  124.     }
  125.  
  126.     curl_easy_cleanup(curl);
  127.     pthread_exit(NULL);
  128. }
  129.  
  130. int writer(char *data, size_t size, size_t nmemb, std::string *page)
  131. {
  132.     if(page != NULL) strncat(page, data, (size*nmemb));//page->append(data, (size * nmemb));
  133.     return(size * nmemb);
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement