国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

C++ LibCurl實現(xiàn)Web隱藏目錄掃描

這篇具有很好參考價值的文章主要介紹了C++ LibCurl實現(xiàn)Web隱藏目錄掃描。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

LibCurl是一個開源的免費的多協(xié)議數(shù)據(jù)傳輸開源庫,該框架具備跨平臺性,開源免費,并提供了包括HTTP、FTP、SMTP、POP3等協(xié)議的功能,使用libcurl可以方便地進行網(wǎng)絡(luò)數(shù)據(jù)傳輸操作,如發(fā)送HTTP請求、下載文件、發(fā)送電子郵件等。它被廣泛應(yīng)用于各種網(wǎng)絡(luò)應(yīng)用開發(fā)中,特別是涉及到數(shù)據(jù)傳輸?shù)膱鼍?。本章將?code>《C++ LibCurl 庫的使用方法》的擴展篇,在前一篇文章中我們簡單實現(xiàn)了LibCurl對特定頁面的訪問功能,本文將繼續(xù)擴展該功能,并以此實現(xiàn)Web隱藏目錄掃描功能。

讀入文件到內(nèi)存

首先通過讀取字典文件,將每行內(nèi)容與指定的根網(wǎng)址進行拼接,生成新的URL列表,此處GetCombinationURL 函數(shù)的目標是根據(jù)傳入的根網(wǎng)址和字典文件,生成一個包含拼接后的URL列表的std::vector<std::string>

函數(shù)的實現(xiàn)主要包括以下步驟:

  • 打開指定的字典文件,逐行讀取其中的內(nèi)容。
  • 對于每一行內(nèi)容,去除行末的換行符,并使用sprintf將根網(wǎng)址與當前行內(nèi)容拼接,形成完整的URL。
  • 將生成的URL加入std::vector`中。
  • 返回包含所有URL的std::vector。

main函數(shù)中,調(diào)用GetCombinationURL并將生成的URL列表輸出到控制臺。代碼使用了C++中的文件操作和字符串處理,利用std::vector存儲生成的 URL,以及通過std::cout在控制臺輸出結(jié)果。

#include <iostream>
#include <string>
#include <vector>

using namespace std;

// 傳入網(wǎng)址和字典名
std::vector<std::string> GetCombinationURL(char root[64],char dict_file[128])
{
  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");                 // 去掉行末的 \n
      buffer[strcspn(buffer, "\n")] = 0;    // 替換所有 \n

      sprintf(this_url, "%s%s", root, buffer);
      ref.push_back(this_url);
    }
  }
  return ref;
}

int main(int argc, char *argv[])
{
  std::vector<std::string> ref = GetCombinationURL("https://www.xxx.com", "./save.log");

  for (int x = 0; x < ref.size(); x++)
  {
    std::cout << "拼接URL: " << ref[x] << std::endl;
  }

  std::system("pause");
  return 0;
}

我們需要新建一個save.log文件,每行放入一個子目錄地址,例如放入;

/index.php
/phpinfo.php

運行后輸出效果如下圖所示;

C++ LibCurl實現(xiàn)Web隱藏目錄掃描,《Visual C++ 編程技術(shù)實踐》,c語言,c++,LibCurl,Web目錄掃描,信息安全,安全工具開發(fā),Boost

增加默認多線程

首先,我們引入了libcurl庫,代碼中使用libcurl提供的函數(shù)來執(zhí)行HTTP請求,獲取返回狀態(tài)碼,并通過多線程處理多個URL。

  • GetPageStatus 函數(shù):用于獲取指定URL的HTTP狀態(tài)碼。使用libcurl進行初始化、設(shè)置請求頭、執(zhí)行請求,并最終獲取返回的狀態(tài)碼。
  • ThreadProc 函數(shù):線程執(zhí)行函數(shù),通過調(diào)用GetPageStatus函數(shù)獲取URL的狀態(tài)碼,并在控制臺輸出。如果狀態(tài)碼為200,則將URL記錄到日志文件中。
  • main 函數(shù):主函數(shù)讀取輸入的URL列表文件,逐行讀取并構(gòu)造完整的URL。通過CreateThread創(chuàng)建線程,每個線程處理一個URL。同時使用互斥鎖確保線程安全。

用戶可以通過在命令行傳遞兩個參數(shù),第一個參數(shù)為根網(wǎng)址,第二個參數(shù)為包含URL列表的文件路徑。程序?qū)⒆x取文件中的每個URL,通過libcurl發(fā)送HTTP 請求,獲取狀態(tài)碼,并輸出到控制臺。狀態(tài)碼為200的URL將被記錄到save.log文件中。

#define CURL_STATICLIB
#define BUILDING_LIBCURL
#include <iostream>
#include <string>
#include "curl/curl.h"

#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;

// 設(shè)置鎖
HANDLE hmutex;

// 屏蔽無用的輸出
static size_t write_data(char *d, size_t n, size_t l, void *p){ return 0; }

int GetPageStatus(char *HostUrl)
{
  CURLcode return_code;
  return_code = curl_global_init(CURL_GLOBAL_WIN32);
  if (CURLE_OK != return_code)
    return 0;

  struct curl_slist *headers = NULL;
  headers = curl_slist_append(headers, "User-Agent: Mozilla/5.0 (LyShark NT 10.0; Win64; x64; rv:76.0)");
  CURL *easy_handle = curl_easy_init();
  int retcode = 0;

  if (NULL != easy_handle)
  {
    curl_easy_setopt(easy_handle, CURLOPT_HTTPHEADER, headers);         // 改協(xié)議頭
    curl_easy_setopt(easy_handle, CURLOPT_URL, HostUrl);                // 請求的網(wǎng)站
    curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data);   // 設(shè)置回調(diào)函數(shù),屏蔽輸出
    return_code = curl_easy_perform(easy_handle);                       // 執(zhí)行CURL
    return_code = curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &retcode);
  }
  curl_easy_cleanup(easy_handle);
  curl_global_cleanup();
  return retcode;
}

// 線程執(zhí)行函數(shù)
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
  char *urls = (char *)(LPVOID)lpParam;

  WaitForSingleObject(hmutex, INFINITE);
  int ret = GetPageStatus(urls);
  if (ret == 200)
  {
    FILE *fp = fopen("./save.log", "a+");
    fwrite(urls, strlen(urls), 1, fp);
    fwrite("\n", 2, 1, fp);
    fclose(fp);
  }
  std::cout << "狀態(tài)碼: " << ret << " 地址: " << urls << std::endl;
  ReleaseMutex(hmutex);
  return 0;
}

int main(int argc, char *argv[])
{
  if (argc == 3)
  {
    FILE *fp = fopen(argv[2], "r");
    char buffer[1024] = { 0 };
    char url[1024] = { 0 };

    hmutex = CreateMutex(NULL, TRUE, NULL);
    ReleaseMutex(hmutex);

    while (feof(fp) == 0)
    {
      fgets(buffer, 1024, fp);
      strtok(buffer, "\n");
      buffer[strcspn(buffer, "\n")] = 0;
      sprintf(url, "%s%s", argv[1], buffer);
      CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)url, 0, 0);
      Sleep(80);
    }
  }
  return 0;
}

使用Boost多線程

如上Web目錄掃描器,雖實現(xiàn)了目錄的掃描,但是有個很大的缺陷,第一是無法跨平臺,第二是無法實現(xiàn)優(yōu)雅的命令行解析效果,所以我們需要使用boost讓其支持跨平臺并增加一個輸出界面。

#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"
    );
}

// 傳入網(wǎng)址和字典名
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");                 // 去掉行末的 \n
      buffer[strcspn(buffer, "\n")] = 0;    // 替換所有 \n

      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);                // 請求的網(wǎng)站
    curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, write_data);   // 設(shè)置回調(diào)函數(shù),屏蔽輸出
    return_code = curl_easy_perform(easy_handle);                       // 執(zhí)行CURL
    return_code = curl_easy_getinfo(easy_handle, CURLINFO_RESPONSE_CODE, &retcode);
  }
  curl_easy_cleanup(easy_handle);
  curl_global_cleanup();
  return retcode;
}

// 線程執(zhí)行函數(shù)
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 << "狀態(tài)碼: " << ret << " 地址: " << url << std::endl;
}

int main(int argc, char * argv[])
{
  opt::options_description des_cmd("\n Usage: 掃描工具 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);

  // 無參數(shù)直接返回
  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>();

    // 由于string與char* 需要轉(zhuǎn)換,所以拷貝后轉(zhuǎn)換
    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 << "參數(shù)錯誤" << std::endl;
  }
  return 0;
}

傳入?yún)?shù)運行,當訪問出現(xiàn)200提示,則自動保存到save.log中,運行效果如下。

  • main.exe --url https://xxxxx --dict c://dict.log

C++ LibCurl實現(xiàn)Web隱藏目錄掃描,《Visual C++ 編程技術(shù)實踐》,c語言,c++,LibCurl,Web目錄掃描,信息安全,安全工具開發(fā),Boost文章來源地址http://www.zghlxwxcb.cn/news/detail-758527.html

到了這里,關(guān)于C++ LibCurl實現(xiàn)Web隱藏目錄掃描的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【小沐學(xué)C++】libcurl實現(xiàn)HTTP/HTTPS請求

    【小沐學(xué)C++】libcurl實現(xiàn)HTTP/HTTPS請求

    https://github.com/curl/curl https://curl.se/libcurl/ https://curl.se/download.html libcurl 是一個免費且易于使用的客戶端 URL 傳輸 庫,支持DICT,F(xiàn)ILE,F(xiàn)TP,F(xiàn)TPS,GOPHER,GOPHERS,HTTP,HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POPP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB、SMBS、SMTP、SMTPS、TELNET 和 T

    2024年02月15日
    瀏覽(21)
  • visual stdio c++調(diào)用python混合編程

    visual stdio c++調(diào)用python混合編程

    關(guān)于環(huán)境創(chuàng)建可以參考https://blog.csdn.net/qq_36559788/article/details/123174309 這里python我用的是anaconda里的python38 ,并且沒有debug庫,所以我只用了release庫 在vs中設(shè)置項目屬性,添加 包含目錄 以及 附加庫目錄 ,注意都是在release模式下添加的 在main.cpp中添加頭文件 添加代碼 編譯運行

    2024年02月01日
    瀏覽(16)
  • C++中的網(wǎng)絡(luò)編程和安全性:實現(xiàn)安全的Web應(yīng)用程序和網(wǎng)絡(luò)應(yīng)用程序

    作者:禪與計算機程序設(shè)計藝術(shù) 《67. C++中的網(wǎng)絡(luò)編程和安全性:實現(xiàn)安全的Web應(yīng)用程序和網(wǎng)絡(luò)應(yīng)用程序》 1.1. 背景介紹 隨著互聯(lián)網(wǎng)的快速發(fā)展,網(wǎng)絡(luò)應(yīng)用程序在人們的生活和工作中扮演著越來越重要的角色,網(wǎng)絡(luò)編程和安全性也成為了現(xiàn)代應(yīng)用程序的重要組成部分。在網(wǎng)絡(luò)

    2024年02月16日
    瀏覽(25)
  • C++編程:Visual Studio啟動之后如何創(chuàng)建項目

    C++編程:Visual Studio啟動之后如何創(chuàng)建項目

    Visual Studio啟動之后,我們首先應(yīng)該創(chuàng)建一個項目。所謂“項目”,就是一個工作任務(wù),需要實現(xiàn)相應(yīng)的需求。點擊“創(chuàng)建新項目”。 ? 直接選擇一個空項目。 ? 指定項目名稱和保存位置。 ? 這里還有一個“解決方案”(Solution)的概念,其實就是一組有關(guān)聯(lián)的項目,共同合

    2024年02月07日
    瀏覽(24)
  • C++ 混合Python編程 及 Visual Studio配置

    C++ 混合Python編程 及 Visual Studio配置

    接手了一個C++應(yīng)用程序,解析csv和生成csv文件,但是如果要把多個csv文件合并成一個Excel,分布在不同的Sheet中,又想在一次運行中完成,不想說運行完C++ 的App后,再調(diào)用一個Python腳本或程序,這需要兩步操作 根據(jù)安裝的Visual Studio 的版本,我安裝的是64-bit的。 如何查看當前

    2024年02月13日
    瀏覽(62)
  • 【Visual Studio 2022創(chuàng)建ASP.NET Web應(yīng)用程序(.NET Framework)發(fā)布并部署到局域網(wǎng) 及“常見權(quán)限問題和不列出目錄問題解決”】

    【Visual Studio 2022創(chuàng)建ASP.NET Web應(yīng)用程序(.NET Framework)發(fā)布并部署到局域網(wǎng) 及“常見權(quán)限問題和不列出目錄問題解決”】

    然后給項目命名并選擇文件保存位置 用一個空項目進行舉例 創(chuàng)建完成如下 點擊更多模板選擇Web窗體 創(chuàng)建成功如下 .aspx頁面編寫前端代碼,.aspx.cs頁面編寫后端代碼 通過插入表格和拉取控件快速完成 然后給Button按鈕設(shè)置一個點擊事件,雙擊按鈕后會跳到.aspx.cs頁面,完善下面

    2024年02月07日
    瀏覽(85)
  • C++ LibCurl 庫的使用方法

    C++ LibCurl 庫的使用方法

    LibCurl是一個開源的免費的多協(xié)議數(shù)據(jù)傳輸開源庫,該框架具備跨平臺性,開源免費,并提供了包括 HTTP 、 FTP 、 SMTP 、 POP3 等協(xié)議的功能,使用 libcurl 可以方便地進行網(wǎng)絡(luò)數(shù)據(jù)傳輸操作,如發(fā)送 HTTP 請求、下載文件、發(fā)送電子郵件等。它被廣泛應(yīng)用于各種網(wǎng)絡(luò)應(yīng)用開發(fā)中,特

    2024年02月11日
    瀏覽(18)
  • 【Python安全編程】Python實現(xiàn)網(wǎng)絡(luò)主機和端口掃描

    【Python安全編程】Python實現(xiàn)網(wǎng)絡(luò)主機和端口掃描

    本文主要講幾個利用Python實現(xiàn)網(wǎng)絡(luò)掃描的小例子,可以 結(jié)合多線程或多進程 編程改進實例 我曾經(jīng)走過多遙遠的路 跨越過多少海洋去看你 Python3環(huán)境 scapy庫 socket庫 能與物理機正常通信的虛擬機 由于本文實驗?zāi)康臑閷崿F(xiàn)網(wǎng)絡(luò)掃描,即探測網(wǎng)絡(luò)中存活的主機,為了避免影響真實

    2024年02月11日
    瀏覽(26)
  • 詳解C++開源網(wǎng)絡(luò)傳輸庫libcurl的編譯過程

    目錄 1、引言 2、直接編譯libcurl工程,提示找不到ssh.h 3、下載并編譯libssh2開源代碼,部署到libcurl目錄中

    2024年02月12日
    瀏覽(14)
  • asp.net歸宿管理系統(tǒng)VS開發(fā)sqlserver數(shù)據(jù)庫web結(jié)構(gòu)c#編程Microsoft Visual Studio

    asp.net歸宿管理系統(tǒng)VS開發(fā)sqlserver數(shù)據(jù)庫web結(jié)構(gòu)c#編程Microsoft Visual Studio

    一、源碼特點 ? ? ? ? asp.net歸宿管理系統(tǒng) 是一套完善的web設(shè)計管理系統(tǒng),系統(tǒng)具有完整的源代碼和數(shù)據(jù)庫,系統(tǒng)主要采用B/S模式開發(fā)。開發(fā)環(huán)境為vs2010,數(shù)據(jù)庫為sqlserver2008,使用c#語言開發(fā) asp.net歸宿管理系統(tǒng)VS開發(fā)sqlserver數(shù)據(jù)庫w 二、功能介紹 一、定時打卡(采用RFID卡)

    2024年02月09日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包