模拟发包winhttp和libcurl+openssl C/C++

admin 6月前 121

今天在一个群里看到了模拟发包谈到了wininet,于是记起前段时间搞的winhttp和libcurl+openssl。然后又想起php和py等模拟发包十行八行。

而c/c++的确那么多行,心里感觉不公平。
就想到之前,为了一个http代理到处找winhttp,貌似也没发现现成的可用的,或者都多少有点小毛病,不能拿来就用。而且也注意到了winhttp不支持s5代理
于是就又找libcurl和openssl,网上教编译openssl的教程很多,但是貌似也没有可以拿来就用的,记得当时还编译了一晚上。
来吧,虽然是小东西,但是总比烂在硬盘里好,虽然意义不大,但是f12的所有的基本全能满足,也免的需要的人再去重新寻找了。
winhttp 支持https  支持http代理 (可带用户密码) 。
#include "read_winhttp.h"
 
#define DEMO 3
 
int main()
{
#if DEMO == 1
    //multipart/form-data
    char* proxy = NULL;
    char* user = NULL;
    char* pass = NULL;
    char* url = "https://ip.cn/";
    int mode = 3;    //1/2/3 GET/POST/multipart/form-data
    BOOL refirect = TRUE; //自动重定向
    char* cookie = NULL;
    char* data = "aa=11&bb=22";
    int data_len = strlen(data);
    char* upload_source = "filename";
    char* upload_filename = "1.jpg";
    char* upload_type = "image/jpeg";
    char* upload_buffer = "aa";
    int len_upload_buffer = strlen(upload_buffer);
    WCHAR* w_add_request_headers[] = { L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                                                                                                                                    L"Referer: https://bbs.pediy.com/",
                                                                                                                                                                NULL};
#elif DEMO == 2
    //POST
    char* proxy = NULL;
    char* user = NULL;
    char* pass = NULL;
    char* url = "https://ip.cn/";
    int mode = 2;    //1/2/3 GET/POST/multipart/form-data
    BOOL refirect = TRUE; //自动重定向
    char* cookie = NULL;
    char* data = "aa=11&bb=22";
    int data_len = strlen(data);
    char* upload_source = NULL;
    char* upload_filename = NULL;
    char* upload_type = NULL;
    char* upload_buffer = NULL;
    int len_upload_buffer = 0;
    WCHAR* w_add_request_headers[] = { L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                                                                                                                                    L"Referer: https://bbs.pediy.com/",
                                                                                                                                                                NULL};
#elif DEMO == 3
    //GET
    char* proxy = NULL;
    char* user = NULL;
    char* pass = NULL;
    char* url = "https://ip.cn/";
    int mode = 1;    //1/2/3 GET/POST/multipart/form-data
    BOOL refirect = TRUE; //自动重定向
    char* cookie = NULL;
    char* data = NULL;
    int data_len = 0;
    char* upload_source = NULL;
    char* upload_filename = NULL;
    char* upload_type = NULL;
    char* upload_buffer = NULL;
    int len_upload_buffer = 0;
    WCHAR* w_add_request_headers[] = { L"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
                                                                                                                                L"Referer: https://bbs.pediy.com/",
                                                                                                                                                                NULL};
#endif
 
    string strHeader = "";
    string strBody = "";
 
    if (read_winhttp(proxy, user, pass, url, mode, refirect, cookie,
                                                data, data_len, 
                                                upload_source, upload_filename, upload_type, upload_buffer, len_upload_buffer, 
                                                w_add_request_headers,strHeader, strBody))
    {
        puts(strHeader.c_str());
        puts(strBody.c_str());
    }
    return 1;
}

libcurl+openssl 支持https 支持http代理(可带用户密码) 支持s5代理(可带用户密码)

#include <windows.h>
#include <stdio.h>
#include "http/readhttp.h"
 
int main(int argc, CHAR* argv[])
{
    BOOL bSuccess = FALSE;
    int retCode = 0;
    char* header = NULL;
    char* body = NULL;
 
    //普通get
    bSuccess = read_http(NULL,NULL, NULL, NULL,
                                            0, 
                                            "https://ip.cn/",
                                            NULL,0,
                                            NULL,NULL,NULL,
                                            NULL, 0,
                                            NULL, NULL,NULL,
                                            retCode, header, body);
 
    //普通post
    bSuccess = read_http(NULL, NULL, NULL, NULL,
                                            1,
                                            "https://ip.cn/",
                                            "aaa=1&bb=2", strlen("aaa=1&bb=2"),
                                            NULL, NULL, NULL,
                                            NULL, 0,
                                            NULL, NULL, NULL,
                                            retCode, header, body);
    //普通put
    bSuccess = read_http(NULL, NULL, NULL, NULL,
                                            4,
                                            "https://ip.cn/",
                                            "aaa=1&bb=2", strlen("aaa=1&bb=2"),
                                            NULL, NULL, NULL,
                                            NULL, 0,
                                            NULL, NULL, NULL,
                                            retCode, header, body);
 
    //上传文件不带其他参数
    bSuccess = read_http(NULL, NULL, NULL, NULL,
                                            2,
                                            "https://ip.cn/",
                                            NULL, 0,
                                            "userfile", "C:\\Users\\DELL\\Desktop\\666.jpg", NULL,
                                            NULL, 0,
                                            NULL, NULL, NULL,
                                            retCode, header, body);
 
 
    //上传文件并带其他参数
    bSuccess = read_http(NULL, NULL, NULL, NULL,
                                            2,
                                            "https://ip.cn/",
                                            "aaa=1&bb=2", strlen("aaa=1&bb=2"),
                                            "userfile", "C:\\Users\\DELL\\Desktop\\666.jpg", NULL,
                                            NULL, 0,
                                            NULL, NULL, NULL,
                                            retCode, header, body);
 
    //上传文件的内存并带其他参数
    bSuccess = read_http(NULL, NULL, NULL, NULL,
                                            2,
                                            "https://ip.cn/",
                                            "aaa=1&bb=2", strlen("aaa=1&bb=2"),
                                            "userfile", NULL, "1.jpg",
                                            "jpg文件内存", strlen("jpg文件内存"),
                                            NULL, NULL, NULL,
                                            retCode, header, body);
 
    if (bSuccess)
    {
        printf("retCode = %d\n", retCode);
        puts(header);
        puts(body);
 
        free(header);
        free(body);
    }
 
    system("pause");
    return 0;
}

注意:里面的静态lib文件绝对没有掺假,原样编译的源码,可放心使用!!!(由于体积过大debug的lib都删除了)


少客联盟- 版权声明 1、本主题所有言论和图片纯属会员个人意见,与少客联盟立场无关。
2、本站所有主题由该帖子作者发表,该帖子作者admin少客联盟享有帖子相关版权。
3、少客联盟管理员和版主有权不事先通知发贴者而删除本文。
4、其他单位或个人使用、转载或引用本文时必须同时征得该帖子作者admin少客联盟的同意。
5、帖子作者须承担一切因本文发表而直接或间接导致的民事或刑事法律责任。
6、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责。
7、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意。
8、官方反馈邮箱:chinasuc@chinasuc.cn


上一篇:深入理解锁之自旋锁
下一篇:Java中的读写锁ReentrantReadWriteLock介绍与使用
Whatever is worth doing is worth doing well. juvenile hacker league
最新回复 (0)
    • 少客联盟
      2
        登录 注册 QQ登录(停用)
返回