引言
在搭建漏洞验证环境的时候, 遇到需要使用https服务的场景。 为了不用费力去申请CA机构认证的证书,这篇文章主要介绍自签名证书实现https 服务。
笔者搭建https服务器的原因:
- 漏洞验证环境需要支持https 请求
- 漏洞验证环境需要支持通过post请求来下载文件
通过查询网络上的各种资源,找到了一个简单的解决方案。
https服务搭建
主要参考资料:
https://juejin.cn/post/7011703754999201823
参考github 地址:
https://github.com/zer1t0/httpsweet
生成 证书和私钥
openssl genrsa -out test.key 2048
openssl req -new -x509 -days 3650 -key test.key -out test.crt
运行https 服务
环境: Python 3.8
下面命令可以重新编译
python3 setup.py install
下面命令可以启动https服务。
python3 httpsweet --bind {ip} --directory {directory} --cert {cert} --key {key} {port}
修改源码支持POST 请求下载文件
这个服务器写的比较简洁,看下代码, 修改下相关逻辑即可支持post 请求下载文件。
修改的文件名称:
parameters.py
原函数为 POST请求直接上传动作, 把逻辑修改一下:
修改前:
@classmethod
def from_method(cls, method):
if method == "POST" or method == "PUT":
return cls(action=Action.UPLOAD)
else:
return cls(action=Action.DOWNLOAD)
修改后:
@classmethod
def from_method(cls, method):
if method == "PUT":
return cls(action=Action.UPLOAD)
else:
return cls(action=Action.DOWNLOAD)
修改源码后记得重新编译,再运行
python3 setup.py install
总结
这个项目比较简单, 可以阅读学习源码,并根据自己的需求做相应修改进行使用。