views:

57

answers:

2

I was able to do this in perl, so now I'm trying to give it a shot in c++. My goal is to submit a md5 hash to http://md5crack.com/crackmd5.php and receive the plaintext back. Correct me if I'm wrong, but to do this you need to send the header information. I'm not exactly sure how to go about this so I broke it up into separate string variables below. How should I send the reconstructed header to the site?

string head1= "POST /crackmd5.php HTTP/1.1";
string head2= "Host: md5crack.com";
string Useragent= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 PBSTB/1.2";
string type= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
string content= "Content-Type: application/x-www-form-urlencoded";
string term= "=term=aaaaaaaaa&crackbtn=Crack+that+hash+baby%21";


int hConnect()
{
 int iResult;
 int recvbuflen = 999999;
 char *sendbuf = "098f6bcd4621d373cade4e832627b4f6";
 char recvbuf[9999999]="";
 WSADATA wsaData;
 Socket ConnectSocket;
 struct sockaddr_in client Service

 iResult=WSAStartup(MAKEWORD(2,2), &wsaData)
 if(iResult != NO_ERROR)
 {
      cout<<"WSA Startup Failed."<<endl;
      return 1;
 }

 ConnectSocket=socket(AF_INET, SOCK_STREAM, IPPPROTO_TCP);
 if (ConnectSocket ==  INVALID_SOCKET)
 {
      cout<<"Socket Failed"<<endl;
      WSACLEANUP();
      return 1;
 }

 clientService.sin_family=AF_INET;
 clientService.sin_addr.s_addr=inet_addr("http://md5crack.com/");
 clientService.sin_port=htons(80);

 iResult=connect( ConnectSocket, (SOCKADDR*, &clientService, sizeof(clientService));

 if(iresult == SOCKET_ERROR)
 {
    cout<<"Failed to connect"<<endl;
    closesocket(connectsocket);
    WSACleanup();
    return 1;
 }

 iResult= send(ConnectSocket, sendbuf,  (int)strlen(sendbuf), 0 );
 recv(ConnectSocket, recvbuf, recvbuflen, 0);
 cout<<recvbuf;


}
+2  A: 

have a look at libcurl

TokenMacGuy
A: 

libcurl should indeed solve your problem, check out their C API here. Here's a little code example to append an HTTP header:

CURL handle;
struct curl_slist *slist=NULL;

slist = curl_slist_append(slist, "Content-Type: text/html");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);

As an aside, if you would like to simulate interaction with more complex websites (e.g., those that you can't feasibly POST data to), you could try using an actual web embedding framework (such as WebKit or Awesomium) to simulate key-presses, mouse input, and Javascript calls.

Adam