VC socket 实现post提交

DWORD WINAPI Start(LPVOID lParam)
{
CPostDlg *p = (CPostDlg *)lParam;
SOCKET sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sock == SOCKET_ERROR)
{
p->MessageBox(“创建套接字失败~”);
return 0;
}
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
char url[20] = “192.168.10.104″;

addr.sin_addr.S_un.S_addr = inet_addr(“192.168.10.104″);
int ret =connect(sock, (SOCKADDR *)&addr, sizeof(SOCKADDR_IN));
if(ret == SOCKET_ERROR)
{
p->MessageBox(“连接失败~”);
return 0;
}
char buffer[4096];
char pwd[] = “fuckhacker”;
int len = strlen(pwd) + 21;
sprintf(buffer, “POST /webshell1.php HTTP/1.1\r\n”
“Content-Type: application/x-www-form-urlencoded\r\n”
“Host: 192.168.10.104\r\n”
“Content-Length: %d\r\n”
“\r\n”
“password=%s&doing=login”,
len,
pwd);
ret = send(sock, buffer, sizeof(buffer), 0);
if(ret == SOCKET_ERROR)
{
p->MessageBox(“发送失败~”);
return 0;
}
memset(buffer, 0, sizeof(buffer));
ret = recv(sock, buffer, sizeof(buffer), 0);
if(ret == SOCKET_ERROR)
{
p->MessageBox(“接受失败~”);
return 0;
}
CString buf(buffer);
if(buf.Find(“Success”, 0) != -1)
p->MessageBox(“密码正确~”);
else
p->MessageBox(“密码错误~”);
return 0;
}

上一篇: 通过CHtmlView::GetHtmlDocument函数得到HTML源文件
下一篇: 用PHP通过HTTP POST到一个远程WEB SITE上

点击获得Trackback地址

发表评论

内 容: