首页
社区
课程
招聘
8
[分享]模拟发包winhttp和libcurl+openssl
发表于: 2020-3-24 13:46 19501

[分享]模拟发包winhttp和libcurl+openssl

2020-3-24 13:46
19501

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

而c/c++的确那么多行,心里感觉不公平。
就想到之前,为了一个http代理到处找winhttp,貌似也没发现现成的可用的,或者都多少有点小毛病,不能拿来就用。而且也注意到了winhttp不支持s5代理
于是就又找libcurl和openssl,网上教编译openssl的教程很多,但是貌似也没有可以拿来就用的,记得当时还编译了一晚上。
来吧,虽然是小东西,但是总比烂在硬盘里好,虽然意义不大,但是f12的所有的基本全能满足,也免的需要的人再去重新寻找了。

winhttp 支持https  支持http代理 (可带用户密码) 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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;
}


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2020-3-24 14:01 被mlgbwoai编辑 ,原因: lib太大。。上传不了
上传的附件:
收藏
免费 8
支持
分享
赞赏记录
参与人
雪币
留言
时间
一路南寻
为你点赞!
2025-1-9 04:13
shinratensei
感谢你的贡献,论坛因你而更加精彩!
2024-6-1 19:06
PLEBFE
为你点赞~
2023-1-17 05:01
yyqkxxy
为你点赞~
2020-7-31 14:56
Editor
为你点赞~
2020-3-30 14:09
lukarl
为你点赞~
2020-3-25 08:46
MsScotch
为你点赞~
2020-3-24 17:06
黑的默
为你点赞~
2020-3-24 15:53
最新回复 (14)
雪    币: 3117
活跃值: (3826)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
2
现在可以试试 vcpkg 的方式获取libcurl openssl并编译,如果需要用到/MT方式可能得稍微修改下配置
2020-3-24 14:21
0
雪    币: 3836
活跃值: (4142)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
不错不错 支持
2020-3-24 14:48
0
雪    币: 3392
活跃值: (2371)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
封装的挺好
2020-3-24 17:06
0
雪    币: 102
活跃值: (2600)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
5
mark
2020-3-24 17:30
0
雪    币: 6824
活跃值: (6376)
能力值: ( LV5,RANK:65 )
在线值:
发帖
回帖
粉丝
6
感谢分享,收下了!
2020-3-24 18:19
0
雪    币: 8559
活跃值: (5201)
能力值: ( LV4,RANK:45 )
在线值:
发帖
回帖
粉丝
7
这个太棒了,拿走留名
2020-3-25 08:13
0
雪    币: 183
活跃值: (701)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
.....cpprestsdk不香吗
2020-3-26 09:09
0
雪    币: 3836
活跃值: (4142)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
9
柒雪天尚 .....cpprestsdk不香吗
更香
2021-1-14 15:14
0
雪    币: 227
活跃值: (101)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10

cpr网络库了解下,底层还是封了libcurl。

C++ Requests: Curl for People, a spiritual port of Python Requests

官方示例:

1
2
3
4
5
6
7
8
#include <cpr/cpr.h>int main(int argc, char** argv) {
    cpr::Response r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"},
                  cpr::Authentication{"user""pass"},
                  cpr::Parameters{{"anon""true"}, 
                  {"key""value"}});
    r.status_code;         // 200
    r.header["content-type"]; // application/json; charset=utf-8
    r.text;          // JSON text string}


最后于 2021-1-25 23:19 被Malicious编辑 ,原因:
2021-1-25 23:18
0
雪    币: 1540
活跃值: (2807)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
11

楼主winhttp的库,可以下载https的链接吗?

我网上搜的代码只能下载http的链接,是不是这个库无法

下载http的链接?

最后于 2021-5-11 06:26 被limee编辑 ,原因:
2021-5-11 06:25
0
雪    币: 220
活跃值: (851)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
12
Malicious cpr网络库了解下,底层还是封了libcurl。C++ Requests: Curl for People, a spiritual port of Python Requests官方示例:#incl ...
我在用这个上传文件时遇见个问题
"file", cpr::File{ "x.txt"},"image/jpeg"
这时的 Content-Type :image/jpeg 可以正常工作

"file", cpr::Buffer{ code.begin(), code.end(),"x.txt"}, "image/jpeg"
后面的 image/jpeg就不能工作了
2022-2-18 09:57
0
雪    币: 202
活跃值: (196)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
13
感谢老板分享
2022-2-18 23:59
0
雪    币: 14
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
14
好东西!
2022-2-24 14:23
0
雪    币: 73
活跃值: (923)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
15
啊,我记得winhttp是可以支持用户名和密码的呀,https的也支持。
2022-2-24 17:01
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册