第一步 获取验证码图片地址
http://captcha.qq.com/getimage?a ... 0.13545262328517488
第二步 获取 sessionCookie 和machinecookie 以及地区
http://zc.qq.com/cgi-bin/chs/numreg/init?r=0.46001003
第三步 获取注册
http://zc.qq.com/cgi-bin/chs/numreg/get_acc?r=0.9412140433
正常情况将会返回我注册的QQ,但是现在的问题是 每次都返回
{"ec":26,"em":"need upsms verify"}
请大牛指点下问题到底出在哪里?
以下附上我的源代码
BOOL WINAPI DNFREG_POST_REG_ALL(CString verifyCode,CString NicName,CString Pass)
{
//ACCEPT类型
static LPCTSTR szAccept[2] = {_T(" */*"), NULL};
//HTTP版本
static LPCTSTR http11 = _T("HTTP/1.1");
//proxy
static LPCTSTR httpmsg =_T("http=");
//请求地址
static LPCTSTR HTTP_Host =_T("zc.qq.com");
HINTERNET hSession;
HINTERNET hConnect;
HINTERNET hRequest;
BOOL bReturn = FALSE;
CString tmpRndstr;
//访问地址
CString URL;
//发送的数据
CString szFormData;
//附加协议头
CStringA fujiaxieyitou;
//保存获取的HEAD头的指针
LPVOID lpOutBuffer=NULL;
DWORD dwSize = 0;
//返回数据用的变量指针
int nIndex;
TCHAR *ptvfsession= NULL;
//返回数据的内容
DWORD dwTmp;
WCHAR szContent[0x5000] = {0};
//表单转化数据
LPVOID pBuf = NULL;
char *pTempBuf = NULL;
CString mCity;
CString cityid;
CString countryid;
CString elevel;
CString provinceid;
//初始化随机
srand(GetTickCount());
//初始化
sessionCookie.Empty();
machineCookie.Empty();
//1.求取sessionCookie 获取所在地-----------------------------------
tmpRndstr.Format(_T("%d%d%d"),rand()%10000,rand()%99999,rand()%99999);
URL = _T("/cgi-bin/chs/numreg/init?r=0.46001003")+ tmpRndstr.Left(8) + _T("&cookieCode=undefined");
//建立请求
hRequest = HttpOpenRequest(hConnect,_T("GET"),URL.GetBuffer(0),NULL,NULL,szAccept,INTERNET_FLAG_DONT_CACHE,1);
URL.ReleaseBuffer();//释放URL数据
//发送请求
bReturn = HttpSendRequest(hRequest,NULL,0,0,0);
if(!bReturn)
{
DWORD dwError = GetLastError();
MessageBox(0,_T("获取登陆验证失败!"),_T("提示"),MB_ICONERROR | MB_OK);
return FALSE;
}
//使用HTTP_QUERY_SET_COOKIE只能获取第一个,但是有用的是第二个,这里直接获取整个Head
HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,(LPVOID)lpOutBuffer,&dwSize,NULL);
if (GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND)
{
AfxMessageBox(_T("获取登陆验证失败!"));
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
return FALSE;
}
else
{
if (GetLastError()==ERROR_INSUFFICIENT_BUFFER)
{
lpOutBuffer = new char[dwSize];
HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,(LPVOID)lpOutBuffer,&dwSize,NULL);
}
}
//查找sessionCookie
nIndex = UnicodeMemFind((const wchar_t *)lpOutBuffer,_T("sessionCookie"),dwSize,0);
if (nIndex != -1)
{
sessionCookie = MySubstr((TCHAR*)lpOutBuffer,nIndex+15,48);
TSS(_T("获取sessionCookie 成功"));
TSS(sessionCookie);
}
else
{
TSS(_T("获取sessionCookie 失败"));
TSS(sessionCookie);
delete []lpOutBuffer;
return FALSE;
}
delete []lpOutBuffer;
//读取内容,显示一下
InternetReadFile(hRequest,szContent,1000,&dwTmp);
TSS(_T("获取地区完成"));
mCity =UTF8ToGB((char*)szContent);
TSS(mCity);
WCHAR douhao[2] = {0x22,0x00};
mCity.Replace(douhao,_T(""));
mCity.Replace(_T("{"),_T(""));
mCity.Replace(_T("}"),_T(""));
mCity.MakeLower();
CString tmpstr;
split(mCity,_T(","));
int iPos = ArrRet.GetCount();
int tmpPos = 0;
for (int i=0;i<iPos;i++)
{
tmpstr = ArrRet[i];
tmpPos = tmpstr.Find(_T("cityid"));
if (tmpPos>=0)
{
cityid = tmpstr.Mid(7,tmpstr.GetLength() - tmpPos);
//AfxMessageBox(cityid);
}
tmpPos = tmpstr.Find(_T("countryid"));
if (tmpPos>=0)
{
countryid = tmpstr.Mid(10,tmpstr.GetLength() - tmpPos);
// AfxMessageBox(countryid);
}
tmpPos = tmpstr.Find(_T("elevel"));
if (tmpPos>=0)
{
elevel = tmpstr.Mid(7,tmpstr.GetLength() - tmpPos);
// AfxMessageBox(elevel);
}
tmpPos = tmpstr.Find(_T("provinceid"));
if (tmpPos>=0)
{
provinceid = tmpstr.Mid(11,tmpstr.GetLength() - tmpPos);
//AfxMessageBox(provinceid);
}
}
if (cityid==L"")
{
cityid = _T("1");
}
if (countryid==L"")
{
countryid = _T("1");
}
if (elevel==L"")
{
elevel = _T("1");
}
if (provinceid==L"")
{
provinceid = _T("23");
}
//关闭当前请求
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
hSession = InternetOpen(_T("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"),INTERNET_OPEN_TYPE_DIRECT,httpmsg,httpmsg,0);
hConnect = InternetConnect(hSession,_T("zc.qq.com"),INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,1);
//2.昵称检测-----------------------------------------------------
tmpRndstr.Format(_T("%d%d328957283"),rand()%10000,rand()%99999);
URL = _T("/cgi-bin/chs/common/dirty_check?nick=") + NicName+ _T("®Type=1&r=0.3475057586")+ tmpRndstr.Left(7);
//建立请求
hRequest = HttpOpenRequest(hConnect,_T("GET"),URL.GetBuffer(0),http11,NULL,NULL,INTERNET_FLAG_RELOAD,0);
URL.ReleaseBuffer();
//构造附加协议头
fujiaxieyitou = ("Accept: */*\r\n");
fujiaxieyitou += _T("Accept-Language: zh-cn\r\n");
fujiaxieyitou += _T("Referer: http://zc.qq.com/chs/index.html\r\n");
fujiaxieyitou += _T("Accept-Encoding: gzip, deflate\r\n");
fujiaxieyitou += _T("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)\r\n");
fujiaxieyitou += _T("Host: zc.qq.com\r\n");
fujiaxieyitou += _T("Connection: Keep-Alive\r\n");
fujiaxieyitou += _T("Cookie: sessionCookie=")+sessionCookie;
fujiaxieyitou += _T("\r\n\r\n");
//把内容转换成ANSI的结构的
pBuf = (LPVOID)szFormData.GetBuffer(szFormData.GetLength());
pTempBuf = MyWideCharToAnsi((wchar_t *)pBuf);
//发送请求 获取NIKEname的合法性
bReturn = HttpSendRequestA(hRequest,fujiaxieyitou.GetBuffer(0),fujiaxieyitou.GetLength(),NULL,0);
if(!bReturn)
{
DWORD dwError = GetLastError();
MessageBox(0,_T("获取登陆验证失败!"),_T("提示"),MB_ICONERROR | MB_OK);
return FALSE;
}
//读取返回内容
memset((void*)&szContent,0,sizeof(szContent));
InternetReadFile(hRequest,szContent,1000,&dwTmp);
TSS(_T("检查昵称完成"));
TSS(UTF8ToGB((char*)szContent));
//关闭当前请求
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
Sleep(15000);
hSession = InternetOpen(_T("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"),INTERNET_OPEN_TYPE_DIRECT,httpmsg,httpmsg,0);
hConnect = InternetConnect(hSession,_T("zc.qq.com"),INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,1);
//3.提交信息-----------------------------------------------------
//URL
srand(GetTickCount());
tmpRndstr.Format(_T("%d%d328957283"),rand()%10000,rand()%99999);
URL = _T("/cgi-bin/chs/numreg/get_acc?r=0.9412140433") + tmpRndstr.Left(5);
//加密密码
//CString password = _T("437b5525e2f94b732029c4b350d7649a4276ede74375e13dd5cedd3e91c2c9440048cdc307f93727ae2bf9b97c5162a498e2592852fe40c33ebbe9dc64008875d0fd4dd43b584bcfdc5a2cb900b99598e28395a363f60f6b56b9308e5ed1433edfccc2e801769a550ef437cb783b9a2da8a97fcaa215211e1c4743c1bf120d7c");
CString password = EmPass(Pass);
TSS(Pass);
TSS(password);
//构造数据包
szFormData =_T("&verifycode=");
szFormData+= verifyCode;
szFormData+=_T("&qzone_flag=1&country=");
szFormData+=countryid;
szFormData+=_T("&province=");
szFormData+=provinceid;
szFormData+=_T("&city=");
szFormData+=cityid;
szFormData+=_T("&isnongli=0&year=1993&month=3&day=3&isrunyue=0&password=");
szFormData+=password;
szFormData+=_T("&nick=");
szFormData+=NicName;
szFormData+=_T("&email=false&other_email=false&elevel=");
szFormData+=elevel;
szFormData+=_T("&sex=1&qzdate=&jumpfrom=58030&csloginstatus=0&p5p2q=w2u9");//
TSS(szFormData);
//获取数据包长度
CString szFormData_Len;
szFormData_Len.Format(_T("%d"),szFormData.GetLength());
//建立连接
hRequest = HttpOpenRequest(hConnect,_T("POST"),URL.GetBuffer(0),http11,NULL,NULL,INTERNET_FLAG_RELOAD,0);
URL.ReleaseBuffer();
//构造附加协议头
fujiaxieyitou = ("Accept: */*\r\n");
fujiaxieyitou += _T("Accept-Language: zh-cn\r\n");
fujiaxieyitou += _T("Referer: http://zc.qq.com/chs/index.html\r\n");
fujiaxieyitou += _T("Accept-Encoding: gzip, deflate\r\n");
fujiaxieyitou += _T("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)\r\n");
fujiaxieyitou += _T("Host: zc.qq.com\r\n");
fujiaxieyitou += _T("Content-Length: ")+szFormData_Len+_T("\r\n");
fujiaxieyitou += _T("Connection: Keep-Alive\r\n");
fujiaxieyitou += _T("Cache-Control: no-cache\r\n");
fujiaxieyitou += _T("Cookie: sessionCookie=");
fujiaxieyitou += sessionCookie;
fujiaxieyitou += _T("; verifysession=");
fujiaxieyitou += verifysession;
fujiaxieyitou += _T("; \r\n\r\n");
//MessageBoxA(0, fujiaxieyitou,"caption",0x40);
//转换表单数据为ansi
pBuf = (LPVOID)szFormData.GetBuffer(szFormData.GetLength());
pTempBuf = MyWideCharToAnsi((wchar_t *)pBuf);
//发送数据
bReturn = HttpSendRequestA(hRequest,fujiaxieyitou.GetBuffer(0),fujiaxieyitou.GetLength(),pTempBuf,szFormData.GetLength());
fujiaxieyitou.ReleaseBuffer();
szFormData.ReleaseBuffer();
if(!bReturn)
{
DWORD dwError = GetLastError();
MessageBox(0,_T("获取登陆验证失败!"),_T("提示"),MB_ICONERROR | MB_OK);
return FALSE;
}
//获取内容
memset((void*)&szContent,0,sizeof(szContent));
InternetReadFile(hRequest,szContent,1000,&dwTmp);
TSS(_T("注册完成"));
TSS(UTF8ToGB((char*)szContent));
//关闭当前请求
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
return TRUE;
}
RegQQ.7z
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)