我能够在perl中做到这一点,所以现在我试着用c ++来试一试。我的目标是向http://md5crack.com/crackmd5.php提交md5哈希并返回明文。如果我错了,请纠正我,但要做到这一点,你需要发送标题信息。我不确定如何解决这个问题,所以我将其分解为下面的单独字符串变量。我该如何将重建的标题发送到网站?
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;
}
答案 0 :(得分:3)
查看libcurl
答案 1 :(得分:2)
libcurl确实应该解决您的问题,请查看他们的C API here。这是一个附加HTTP标头的小代码示例:
CURL handle;
struct curl_slist *slist=NULL;
slist = curl_slist_append(slist, "Content-Type: text/html");
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);
顺便说一句,如果您想模拟与更复杂网站的交互(例如那些您无法将数据发布到其中的网站),您可以尝试使用实际的网络嵌入框架(例如WebKit或Awesomium)来模拟按键,鼠标输入和Javascript调用。