Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <pthread.h>
- #include <string.h>
- #include <curl/curl.h>
- #include <stdlib.h>
- using namespace std;
- #define MAX 4
- struct info {
- int site_num;
- string website;
- string is_found;
- string post_data;
- };
- string word;
- bool cracked = false;
- struct info info_array[MAX];
- void *webCrack(void *thread_arg);
- int writer(char *data, size_t size, size_t nmemb, std::string *page);
- int main(int argc, char *argv[])
- {
- if(argc != 2 || strlen(argv[1]) != 32)
- {
- cout << "\nusage: ./webhash <md5Hash>\n";
- exit(-1);
- }
- pthread_t threads[MAX];
- pthread_attr_t attr;
- int r_val, x;
- void *status;
- /* Set it as joinable explicitly incase the users implementation doesn't by default */
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- for(x = 0; x < MAX; x++)
- {
- switch(x) /* Fill out structs to be passed to the main routine */
- {
- case 0:
- info_array[x].website = "http://hashcrack.com/index.php";
- info_array[x].is_found = "class=hervorheb2>"; //+17 </span></div></TD>
- info_array[x].post_data = "hash=" + (string)argv[1] + "&Submit=Submit";
- info_array[x].site_num = x;
- break;
- case 1:
- info_array[x].website = "http://md5crack.com/crackmd5.php";
- info_array[x].is_found = "md5(\"";
- info_array[x].post_data = "term=" + (string)argv[1] + "&crackbtn=Crack that hash baby!";
- info_array[x].site_num = x;
- break;
- case 2:
- info_array[x].website = "http://passcracking.com/index.php";
- info_array[x].is_found = "#FF0000>";
- info_array[x].post_data = "datafromuser=" + (string)argv[1];
- info_array[x].site_num = x;
- break;
- case 3:
- info_array[x].website = "http://md5decryption.com/index.php";
- info_array[x].is_found = "Text: </b>";
- info_array[x].post_data = "hash=" + (string)argv[1] + "&submit=Decrypt It!";
- info_array[x].site_num = x;
- break;
- }
- /* Let there be threads! */
- if((r_val = pthread_create(&threads[x], NULL, webCrack, (void *) &info_array[x])))
- {
- cout << "\n\nError creating threads\n\n";
- exit(-1);
- }
- }
- /* Clean up the attribute and then join */
- pthread_attr_destroy(&attr);
- for(x = 0; x < MAX; x++)
- {
- if((r_val = pthread_join(threads[x], &status)))
- {
- cout << "\n\nError joining threads\n\n";
- exit(-1);
- }
- }
- cracked == true ? cout << "\nFound!\n\n" << argv[1] << ":" << word << "\n\n" : cout << "\nNot Found!\n\n";
- pthread_exit(NULL);
- }
- void *webCrack(void *thread_arg)
- {
- if(cracked == true) pthread_exit(NULL);
- struct info *thread_data;
- thread_data = (struct info*)thread_arg;
- CURL *curl;
- CURLcode r_val;
- string page;
- size_t pos;
- curl = curl_easy_init();
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); /* for threading */
- curl_easy_setopt(curl, CURLOPT_URL, thread_data->website.c_str());
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, thread_data->post_data.c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
- r_val = curl_easy_perform(curl);
- pos = page.find(thread_data->is_found);
- if(pos != string::npos)
- {
- cracked = true;
- switch(thread_data->site_num) /* Extract cracked hash from webpage */
- {
- case 0: word = page.substr((pos + 17), (page.find("</span></div></TD>")) - (pos + 17)); break;
- case 1: word = page.substr((pos + 5), (page.find("\")")) - (pos + 5)); break;
- case 2: word = page.substr((pos + 8), (page.find_first_of("<", (pos + 8))) - (pos + 8)); break;
- case 3: word = page.substr((pos + 10), (page.find("</font><br/><center>")) - (pos + 10)); break;
- }
- }
- curl_easy_cleanup(curl);
- pthread_exit(NULL);
- }
- int writer(char *data, size_t size, size_t nmemb, std::string *page)
- {
- if(page != NULL) strncat(page, data, (size*nmemb));//page->append(data, (size * nmemb));
- return(size * nmemb);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement