#define CURL_STATICLIB #define BUILDING_LIBCURL #include <iostream> #include <string> #include "curl/curl.h"
#include <boost/bind.hpp> #include <boost/thread.hpp> #include <boost/function.hpp> #include <boost/thread/thread_guard.hpp>
#include <boost/program_options.hpp>
#pragma comment (lib,"libcurl_a.lib") #pragma comment (lib,"wldap32.lib") #pragma comment (lib,"ws2_32.lib") #pragma comment (lib,"Crypt32.lib")
using namespace std; using namespace boost; namespace opt = boost::program_options;
boost::mutex io_mutex;
void ShowOpt() { fprintf(stderr, "# # # \n" "# # # \n" "# # # ##### ###### ###### # ### # ## \n" "# # # # # # # # ## # # \n" "# # # #### # # # # # ### \n" "# ##### # # # # ## # # # \n" "##### # ##### # # #### # # # ## \n\n" ); }
std::vector<std::string> GetCombinationURL(char *root, char *dict_file) { char buffer[512] = { 0 }; char this_url[1024] = { 0 };
std::vector<std::string> ref;
FILE *fp = fopen(dict_file, "r"); if (fp != NULL) { while (feof(fp) == 0) { fgets(buffer, 1024, fp); strtok(buffer, "\n"); buffer[strcspn(buffer, "\n")] = 0;
sprintf(this_url, "%s%s", root, buffer); ref.push_back(this_url); } } return ref; }
static size_t write_data(char *d, size_t n, size_t l, void *p){ return 0; }
int GetPageStatus(std::string HostUrl) { CURLcode return_code; return_code = curl_global_init(CURL_GLOBAL_WIN32); if (CURLE_OK != return_code) return 0;
CURL *easy_handle = curl_easy_init(); int retcode = 0;
if (NULL != easy_handle) { curl_easy_setopt(easy_handle, CURLOPT_URL, HostUrl); curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data); return_code = curl_easy_perform(easy_handle); return_code = curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &retcode); } curl_easy_cleanup(easy_handle); curl_global_cleanup(); return retcode; }
void ThreadProc(std::string url) { boost::lock_guard<boost::mutex> global_mutex(io_mutex);
int ret = GetPageStatus(url); if (ret == 200) { FILE *fp = fopen("./save.log", "a+"); fwrite(url.c_str(), strlen(url.c_str()), 1, fp); fwrite("\n", 2, 1, fp); fclose(fp); } std::cout << "状态码: " << ret << " 地址: " << url << std::endl; }
int main(int argc, char * argv[]) { opt::options_description des_cmd("\n Usage: LyShark URL扫描工具 Ver:1.1 \n\n Options"); des_cmd.add_options() ("url,u", opt::value<std::string>(), "指定需要的URL地址") ("dict,d", opt::value<std::string>(), "指定字典") ("help,h", "帮助菜单");
opt::variables_map virtual_map; try { opt::store(opt::parse_command_line(argc, argv, des_cmd), virtual_map); } catch (...){ return 0; }
opt::notify(virtual_map);
if (virtual_map.empty()) { ShowOpt(); std::cout << des_cmd << std::endl; return 0; } else if (virtual_map.count("help") || virtual_map.count("h")) { ShowOpt(); std::cout << des_cmd << std::endl; return 0; } else if (virtual_map.count("url") && virtual_map.count("dict")) {
std::string scan_url = virtual_map["url"].as<std::string>(); std::string scan_path = virtual_map["dict"].as<std::string>();
char src[1024] = { 0 }; char path[1024] = { 0 };
strcpy(src, scan_url.c_str()); strcpy(path, scan_path.c_str());
std::vector<std::string> get_url = GetCombinationURL(src, path);
boost::thread_group group;
for (int x = 0; x < get_url.size(); x++) { group.create_thread(boost::bind(ThreadProc, get_url[x])); _sleep(50); } group.join_all(); } else { std::cout << "参数错误" << std::endl; } return 0; }
|