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

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

2020-3-24 13:46
18122
今天在一个群里看到了模拟发包谈到了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都删除了)



[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

最后于 2020-3-24 14:01 被mlgbwoai编辑 ,原因: lib太大。。上传不了
上传的附件:
收藏
点赞6
打赏
分享
最新回复 (14)
雪    币: 2924
活跃值: (2562)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
小调调 2020-3-24 14:21
2
0
现在可以试试 vcpkg 的方式获取libcurl openssl并编译,如果需要用到/MT方式可能得稍微修改下配置
雪    币: 3659
活跃值: (3838)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
caolinkai 2020-3-24 14:48
3
0
不错不错 支持
雪    币: 2966
活跃值: (1383)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
MsScotch 2020-3-24 17:06
4
0
封装的挺好
雪    币: 122
活跃值: (1390)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
koflfy 1 2020-3-24 17:30
5
0
mark
雪    币: 5080
活跃值: (4384)
能力值: ( LV5,RANK:65 )
在线值:
发帖
回帖
粉丝
gamehack 2020-3-24 18:19
6
0
感谢分享,收下了!
雪    币: 8271
活跃值: (4796)
能力值: ( LV4,RANK:45 )
在线值:
发帖
回帖
粉丝
v0id_ 2020-3-25 08:13
7
0
这个太棒了,拿走留名
雪    币: 182
活跃值: (576)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
柒雪天尚 2020-3-26 09:09
8
0
.....cpprestsdk不香吗
雪    币: 3659
活跃值: (3838)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
caolinkai 2021-1-14 15:14
9
0
柒雪天尚 .....cpprestsdk不香吗
更香
雪    币: 227
活跃值: (86)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Malicious 2021-1-25 23:18
10
0

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

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

官方示例:

#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编辑 ,原因:
雪    币: 1540
活跃值: (2757)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
limee 2021-5-11 06:25
11
0

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

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

下载http的链接?

最后于 2021-5-11 06:26 被limee编辑 ,原因:
雪    币: 220
活跃值: (626)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
dayang 2022-2-18 09:57
12
0
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就不能工作了
雪    币: 202
活跃值: (196)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
美达不索米亚 2022-2-18 23:59
13
0
感谢老板分享
雪    币: 14
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_dVjWuq1l 2022-2-24 14:23
14
0
好东西!
雪    币: 73
活跃值: (893)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hixhi 2022-2-24 17:01
15
0
啊,我记得winhttp是可以支持用户名和密码的呀,https的也支持。
游客
登录 | 注册 方可回帖
返回