#define CURL_STATICLIB #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include "yajl/yajl_parse.h" #include "yajl/yajl_tree.h" #pragma comment(lib,"ws2_32.lib") #pragma comment(lib,"D:\\win32dev\\curl-7.19.0\\lib\\Debug\\curllib.lib") #pragma comment(lib,"D:\\win32dev\\yajl\\build\\yajl-2.0.1\\lib\\debug\\yajl_s.lib") unsigned short chrsz = 8; char *b64pad = ""; char *validate_code; unsigned short mode = 32; unsigned short hexcase = 1; int hex[16]={0}; typedef struct tagSESSION{ unsigned short retcode,birthday_year,birthday_month,birthday_day,allow,constel,blood,stat,vip_info,shengxiao; unsigned reg_time; char* occupation; char* phone; char* college; char* homepage; char* country; char* city; char* personal; char* nick; char* email; char* province; char* gender; char* mobile; char* uin; char* vfwebqq; char* psessionid; }session; session sess; char *hash2str (unsigned char digest[16]) { unsigned int i; char temp[3]={0}; char *hex_str=malloc(16); memset(hex_str,0,16); for (i = 0; i < 16; i++) { sprintf(temp,"%02X", digest[i]); strcat(hex_str,temp); } return hex_str; } unsigned int *str2binl(char *str,size_t str_len) { unsigned short b; unsigned short a = (1<>5; bin[i] |= h; } return bin; } char *binl2str(unsigned int *arr) { size_t i=0; char char_temp[2]=""; unsigned short b,a = (1<<8)-1; char *str=malloc(200); memset(str,0,200); while(arr[i] !=0) { i++; } for(b=0;b>5])>>(b%32)&a ); //char_temp[0] = (char) ; char_temp[1] = 0; strcat(str,char_temp); } return str; } char *binl2hex(unsigned int *arr) { size_t j,i=0; char *str = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; char str_temp[4]=""; char str_temp2[2]=""; char *str_hex=(char*)malloc(100); strcpy(str_hex,""); while(arr[i] !=0) { i++; } for(j=0;j>2]>>((j%4)*8+4)&15]; str_temp[1]=0; str_temp2[0] = str[arr[j>>2]>>((j%4)*8)&15]; str_temp2[1]=0; strcat(str_temp,str_temp2); strcat(str_hex,str_temp); } return str_hex; } unsigned int bit_rol(unsigned int A,unsigned int B) { return (A<>(32-B)); } unsigned int safe_add(unsigned int A,unsigned int D) { unsigned int C = (A & 0xFFFF) + (D &0xFFFF); unsigned int B = (A >> 16) + (D >> 16) + (C >> 16); return (B<<16) | (C & 0xFFFF); } unsigned int md5_cmn(unsigned int F,unsigned int C, unsigned int B, unsigned int A, unsigned int E, unsigned int D) { return safe_add(bit_rol(safe_add(safe_add(C, F), safe_add(A, D)), E), B); } unsigned int md5_ff(unsigned int C, unsigned int B, unsigned int G, unsigned int F, unsigned int A, unsigned int E, unsigned int D) { return md5_cmn((B & G) | ((~B) & F), C, B, A, E, D); } unsigned int md5_gg(unsigned int C, unsigned int B, unsigned int G, unsigned int F, unsigned int A, unsigned int E, unsigned int D) { return md5_cmn((B & F) | (G & (~F)), C, B, A, E, D); } unsigned int md5_hh(unsigned int C, unsigned int B, unsigned int G, unsigned int F, unsigned int A, unsigned int E, unsigned int D) { return md5_cmn(B ^ G ^ F, C, B, A, E, D); } unsigned int md5_ii(unsigned int C, unsigned int B, unsigned int G, unsigned int F, unsigned int A, unsigned int E, unsigned int D) { return md5_cmn(G ^ (B | (~F)), C, B, A, E, D); } unsigned int *core_md5(unsigned int *K, unsigned int F) { unsigned int len,i; unsigned int C; unsigned int E,D,B,A; unsigned int J = 1732584193; unsigned int I = -271733879; unsigned int H = -1732584194; unsigned int G = 271733878; /* unsigned int *ret=malloc(16); memset(ret,0,16); */ K[F >> 5] |= 128 << ((F) % 32); len =(((F + 64) >> 9) << 4) + 14; K[len] = F; for (C = 0; C < len+1; C += 16) { E = J; D = I; B = H; A = G; J = md5_ff(J, I, H, G, K[C + 0], 7, -680876936); G = md5_ff(G, J, I, H, K[C + 1], 12, -389564586); H = md5_ff(H, G, J, I, K[C + 2], 17, 606105819); I = md5_ff(I, H, G, J, K[C + 3], 22, -1044525330); J = md5_ff(J, I, H, G, K[C + 4], 7, -176418897); G = md5_ff(G, J, I, H, K[C + 5], 12, 1200080426); H = md5_ff(H, G, J, I, K[C + 6], 17, -1473231341); I = md5_ff(I, H, G, J, K[C + 7], 22, -45705983); J = md5_ff(J, I, H, G, K[C + 8], 7, 1770035416); G = md5_ff(G, J, I, H, K[C + 9], 12, -1958414417); H = md5_ff(H, G, J, I, K[C + 10], 17, -42063); I = md5_ff(I, H, G, J, K[C + 11], 22, -1990404162); J = md5_ff(J, I, H, G, K[C + 12], 7, 1804603682); G = md5_ff(G, J, I, H, K[C + 13], 12, -40341101); H = md5_ff(H, G, J, I, K[C + 14], 17, -1502002290); I = md5_ff(I, H, G, J, K[C + 15], 22, 1236535329); J = md5_gg(J, I, H, G, K[C + 1], 5, -165796510); G = md5_gg(G, J, I, H, K[C + 6], 9, -1069501632); H = md5_gg(H, G, J, I, K[C + 11], 14, 643717713); I = md5_gg(I, H, G, J, K[C + 0], 20, -373897302); J = md5_gg(J, I, H, G, K[C + 5], 5, -701558691); G = md5_gg(G, J, I, H, K[C + 10], 9, 38016083); H = md5_gg(H, G, J, I, K[C + 15], 14, -660478335); I = md5_gg(I, H, G, J, K[C + 4], 20, -405537848); J = md5_gg(J, I, H, G, K[C + 9], 5, 568446438); G = md5_gg(G, J, I, H, K[C + 14], 9, -1019803690); H = md5_gg(H, G, J, I, K[C + 3], 14, -187363961); I = md5_gg(I, H, G, J, K[C + 8], 20, 1163531501); J = md5_gg(J, I, H, G, K[C + 13], 5, -1444681467); G = md5_gg(G, J, I, H, K[C + 2], 9, -51403784); H = md5_gg(H, G, J, I, K[C + 7], 14, 1735328473); I = md5_gg(I, H, G, J, K[C + 12], 20, -1926607734); J = md5_hh(J, I, H, G, K[C + 5], 4, -378558); G = md5_hh(G, J, I, H, K[C + 8], 11, -2022574463); H = md5_hh(H, G, J, I, K[C + 11], 16, 1839030562); I = md5_hh(I, H, G, J, K[C + 14], 23, -35309556); J = md5_hh(J, I, H, G, K[C + 1], 4, -1530992060); G = md5_hh(G, J, I, H, K[C + 4], 11, 1272893353); H = md5_hh(H, G, J, I, K[C + 7], 16, -155497632); I = md5_hh(I, H, G, J, K[C + 10], 23, -1094730640); J = md5_hh(J, I, H, G, K[C + 13], 4, 681279174); G = md5_hh(G, J, I, H, K[C + 0], 11, -358537222); H = md5_hh(H, G, J, I, K[C + 3], 16, -722521979); I = md5_hh(I, H, G, J, K[C + 6], 23, 76029189); J = md5_hh(J, I, H, G, K[C + 9], 4, -640364487); G = md5_hh(G, J, I, H, K[C + 12], 11, -421815835); H = md5_hh(H, G, J, I, K[C + 15], 16, 530742520); I = md5_hh(I, H, G, J, K[C + 2], 23, -995338651); J = md5_ii(J, I, H, G, K[C + 0], 6, -198630844); G = md5_ii(G, J, I, H, K[C + 7], 10, 1126891415); H = md5_ii(H, G, J, I, K[C + 14], 15, -1416354905); I = md5_ii(I, H, G, J, K[C + 5], 21, -57434055); J = md5_ii(J, I, H, G, K[C + 12], 6, 1700485571); G = md5_ii(G, J, I, H, K[C + 3], 10, -1894986606); H = md5_ii(H, G, J, I, K[C + 10], 15, -1051523); I = md5_ii(I, H, G, J, K[C + 1], 21, -2054922799); J = md5_ii(J, I, H, G, K[C + 8], 6, 1873313359); G = md5_ii(G, J, I, H, K[C + 15], 10, -30611744); H = md5_ii(H, G, J, I, K[C + 6], 15, -1560198380); I = md5_ii(I, H, G, J, K[C + 13], 21, 1309151649); J = md5_ii(J, I, H, G, K[C + 4], 6, -145523070); G = md5_ii(G, J, I, H, K[C + 11], 10, -1120210379); H = md5_ii(H, G, J, I, K[C + 2], 15, 718787259); I = md5_ii(I, H, G, J, K[C + 9], 21, -343485551); J = safe_add(J, E); I = safe_add(I, D); H = safe_add(H, B); G = safe_add(G, A); } for(i=0;i<16;i++) { hex[i]=0; } if (mode == 16) { hex[0]=I; hex[1]=H; } else { hex[0]=J; hex[1]=I; hex[2]=H; hex[3]=G; } return hex; } char *hex_md5(char *A) { return binl2hex(core_md5(str2binl(A,strlen(A)),(unsigned int)strlen(A)*8)); } char *md5(char *A) { return hex_md5(A); } char *md5_3(char *b) { unsigned int *a = (unsigned int *)malloc(16); size_t len = strlen(b); memset(a,0,16); a = core_md5(str2binl(b,strlen(b)),(unsigned int)len * chrsz); a = core_md5(a,16*chrsz); a = core_md5(a,16*chrsz); return binl2hex(a); } size_t vacode_check( void *ptr, size_t size, size_t nmemb, void *stream) { if(strchr(ptr,'!') == NULL) { //printf("not what we want:%s\n",ptr); validate_code=ptr; return 0; } else { validate_code=strchr(ptr,'!'); validate_code[4]=0; return 1; } } size_t fake_write( char *ptr, size_t size, size_t nmemb, char *stream) { strcat(stream,ptr); return(nmemb*size); } static void print_cookies(CURL *curl) { CURLcode res; struct curl_slist *cookies; struct curl_slist *nc; int i; printf("Cookies, curl knows:\n"); res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); if (res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res)); exit(1); } nc = cookies, i = 1; while (nc) { printf("[%d]: %s\n", i, nc->data); nc = nc->next; i++; } if (i == 1) { printf("(none)\n"); } curl_slist_free_all(cookies); } char* WebQQ_check(char* QQno) { char* buffer=(char*)malloc(100); char* get_url=(char*)malloc(100); CURL *easy_handle; easy_handle = curl_easy_init(); if (NULL == easy_handle) { curl_global_cleanup(); return NULL; } memset(buffer,0,100); memset(get_url,0,100); sprintf(get_url,"http://ptlogin2.qq.com/check?uin=%s&appid=1003903",QQno); curl_easy_setopt(easy_handle, CURLOPT_URL, get_url); curl_easy_setopt(easy_handle, CURLOPT_REFERER, "http://web.qq.com/"); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,0); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, fake_write); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA,buffer); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\cookie_login.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR, "D:\\cookie_login.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); //返还QQ验证码 if(strchr(buffer,'!') == NULL) { return (char*)-1; } else { buffer=strchr(buffer,'!'); buffer[4]=0; return buffer; } } char* WebQQ_login(char* QQno,char* PassCode,char* VeriCode) { char* buffer=(char*)malloc(100); char* get_url=(char*)malloc(500); CURL *easy_handle = curl_easy_init(); memset(buffer,0,100); memset(get_url,0,500); sprintf(get_url,"http://ptlogin2.qq.com/login?u=%s&p=%s&verifycode=%s&remember_uin=1&aid=1003903&u1=http%%3A%%2F%%2Fweb.qq.com%%2Floginproxy.html&h=1&ptlang=2052&from_ui=1&pttype=1&dumy=&fp=loginerroralert&ptredirect=0",QQno,PassCode,VeriCode); curl_easy_setopt(easy_handle, CURLOPT_URL, get_url); curl_easy_setopt(easy_handle, CURLOPT_REFERER, "http://web.qq.com"); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,0); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, fake_write); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\cookie_login.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR,"D:\\cookie_login.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); return buffer; } char* get_json_string(char* buffer,char* errbuf,char** path, int data_type) { yajl_val v; yajl_val node; node = yajl_tree_parse(buffer, errbuf, sizeof(errbuf)); if( data_type == 1) { v = yajl_tree_get(node, path, yajl_t_string); return YAJL_GET_STRING(v); } if( data_type == 2) { v = yajl_tree_get(node, path, yajl_t_number); return YAJL_GET_NUMBER(v); } else return (char*)-1; } void WebQQ_login2() { char* path[20] = { "result", "vfwebqq", (char *) 0 }; char* ptwebqq=(char*)malloc(1000); char* buffer=(char*)malloc(1000); char* errbuf=(char*)malloc(1000); char* szClient=(char*)malloc(20); char* post_data=(char*)malloc(500); CURL *easy_handle; FILE* fp = fopen("D:\\cookie_login.txt","r"); int iClient= rand()%100000000; memset(ptwebqq,0,1000); memset(buffer,0,1000); memset(errbuf,0,1000); memset(post_data,0,500); memset(szClient,0,20); szClient = "92719761"; fread(ptwebqq,1000,1,fp); ptwebqq = strstr(ptwebqq,"ptwebqq\t"); ptwebqq = strchr(ptwebqq,'\t'); ptwebqq = ptwebqq+1; ptwebqq[64]=0; easy_handle = curl_easy_init(); sprintf(post_data,"r={\"status\":\"online\",\"ptwebqq\":\"%s\",\"passwd_sig\":\"\",\"clientid\":\"%s\",\"psessionid\":null}&clientid=%s&psessionid=null",ptwebqq,szClient,szClient); curl_easy_setopt(easy_handle, CURLOPT_URL, "http://d.web2.qq.com/channel/login2"); curl_easy_setopt(easy_handle, CURLOPT_REFERER, "http://d.web2.qq.com/proxy.html"); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,0); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, fake_write); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS,post_data); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\cookie_login.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR,"D:\\cookie_login.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); sess.vfwebqq = get_json_string(buffer,errbuf,path,1); path[1] = "psessionid"; sess.psessionid = get_json_string(buffer,errbuf,path,1); printf("登录成功\n"); } void WebQQ_get_friend_info2(char* qq_id) { CURL *easy_handle; char* url = (char*)malloc(300); char* buffer=(char*)malloc(2000); WCHAR* wbuffer=(WCHAR*)malloc(2000); char* errbuf=(char*)malloc(1000); char* path[20] = { "result", "uin", (char *) 0 }; int len; memset(url,0,300); memset(buffer,0,2000); memset(wbuffer,0,2000); memset(errbuf,0,1000); sprintf(url,"http://s.web2.qq.com/api/get_friend_info2?tuin=%s&verifysession=&code=&vfwebqq=%s&t=1322670147670",qq_id,sess.vfwebqq); easy_handle = curl_easy_init(); curl_easy_setopt(easy_handle, CURLOPT_URL, url); curl_easy_setopt(easy_handle, CURLOPT_REFERER, "http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=2"); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,0); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, fake_write); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\cookie_login.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR,"D:\\cookie_login.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); len=MultiByteToWideChar(CP_UTF8,0,buffer,-1,NULL,0); MultiByteToWideChar(CP_UTF8,0,buffer,-1,wbuffer,len); len = WideCharToMultiByte(CP_OEMCP,0,wbuffer,-1,NULL,0,NULL,FALSE); WideCharToMultiByte (CP_OEMCP,0,wbuffer,-1,buffer,len,NULL,FALSE); sess.uin = get_json_string(buffer,errbuf,path,2); path[1] = "country"; sess.country = get_json_string(buffer,errbuf,path,1); path[1] = "homepage"; sess.homepage = get_json_string(buffer,errbuf,path,1); path[1] = "nick"; sess.nick = get_json_string(buffer,errbuf,path,1); path[1] = "gender"; sess.gender = get_json_string(buffer,errbuf,path,1); printf("QQ号:%s|昵称:%s|国家:%s|主页:%s|性别:%s\n",sess.uin,sess.nick,sess.country,sess.homepage,sess.gender); } void WebQQ_get_user_friends2() { int len; CURL *easy_handle; char* post_fields=(char*)malloc(200); char* buffer=(char*)malloc(10000); char* errbuf=(char*)malloc(1000); WCHAR* wbuffer=(WCHAR*)malloc(20000); char* path[20] = { "result", "info", (char *) 0 }; struct qq_friend{ char* nick; char* uin; }; struct qq_friend qf; memset(buffer,0,10000); memset(wbuffer,0,20000); memset(errbuf,0,1000); memset(post_fields,0,200); easy_handle = curl_easy_init(); curl_easy_setopt(easy_handle, CURLOPT_URL, "http://s.web2.qq.com/api/get_user_friends2"); curl_easy_setopt(easy_handle, CURLOPT_REFERER, "http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=2"); curl_easy_setopt(easy_handle, CURLOPT_VERBOSE,0); curl_easy_setopt(easy_handle, CURLOPT_POST,1); sprintf(post_fields,"{\"h\":\"hello\",\"vfwebqq\":\"%s\"}",sess.vfwebqq); curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS,post_fields); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, fake_write); curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, buffer); curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\cookie_login.txt"); curl_easy_setopt(easy_handle, CURLOPT_COOKIEJAR,"D:\\cookie_login.txt"); curl_easy_perform(easy_handle); curl_easy_cleanup(easy_handle); len=MultiByteToWideChar(CP_UTF8,0,buffer,-1,NULL,0); MultiByteToWideChar(CP_UTF8,0,buffer,-1,wbuffer,len); len = WideCharToMultiByte(CP_OEMCP,0,wbuffer,-1,NULL,0,NULL,FALSE); WideCharToMultiByte (CP_OEMCP,0,wbuffer,-1,buffer,len,NULL,FALSE); printf("在线好友:???\n"); } void main() { char *qq_id = "2508491710",*qq_pass="whatthefuck"; char *vacode; char *passcode; char *login_result; //check vacode=WebQQ_check(qq_id); //encrypt passcode = md5_3(qq_pass); strcat(passcode,vacode); passcode = md5(passcode); //login login_result=WebQQ_login(qq_id,passcode,vacode); //login2 WebQQ_login2(); WebQQ_get_friend_info2(qq_id); WebQQ_get_user_friends2(); getchar(); }