当前位置: 首页 > news >正文

Dotnet通过Http2解决CVE-2025-55315高危漏洞

Pasted image 20251018234404.png

Kestrel 服务器 是默认的跨平台 HTTP 服务器实现。
Kestrel自承载:Kestrel Web 服务器无需任何其他外部 Web 服务器(如 IIS 或 HTTP.sys)即可运行。

最近出现.NET平台中Asp.Net Core 被曝CVE-2025-55315漏洞,可以查看,安全评定危害等级为9.9,算是史诗级漏洞,修复方式除了升级安全补丁版本,除了升级runtimesdk 版本外,和可以考虑将服务升级为http/2,直接改变报文的服务组合方式.官方只维护更新NET10NET9NET8。低版本用.Net Framework(不建议)、增加前置Web服务器例如IIS、Nginx 过滤请求头部或者请求使用http/2Kestrel 启用Https以及配置Http/2,以下是主要讲解使用nginx以及Kestrel启用https方式,对于安装runtimesdk 就不再累述,可以直接查看github 上的讨论内容或者看其他网友的文章

前置准备

创建证书

本地可以使用dotnet dev-certs 创建证书,也可以使用OpenSSL创建。但是需要生成.pem.key 私钥,文件尾缀无所谓,主要是文件格式得对上。
创建目录ssl存放证书。

mkdir ssl
cd ssl

不添加证书密码设置参数-np即可(推荐方法)。

dotnet dev-certs https --format pem -ep ./localhost.pem  -np
A valid HTTPS certificate is already present.

生成证书pem 格式证书文件,设置-p <自定义证书密码>,就需要在加载证书时,输入证书密码(不推荐),对于nginxWindows 中运行存在问题。

dotnet dev-certs https --format pem -ep ./localhost.pem -p <自定义证书密码>
A valid HTTPS certificate is already present.

生成文件结果如下:
Pasted image 20251018230320.png

本地演示项目

模拟的服务站点此处使用一个新建项目ASP.NET Core Web API 空白项目
创建一个目录ssl存储证书,同时设置文件属性为始终复制或者较新复制。
目录结构如下:

│  appsettings.Development.json
│  appsettings.json
│  Program.cs
│  WeatherForecast.cs
│  WebApp.csproj
│  WebApp.csproj.user
│  WebApp.http
├─Properties
│      launchSettings.json
└─ssllocalhost.keylocalhost.pem

调整Program.cs

调整默认代码中注释http重定向到https 中间件。

//app.UseHttpsRedirection();

调试加载配置Properties/launchSettings.json 内容如下。

{"http": {"commandName": "Project","dotnetRunMessages": true,"launchBrowser": false,"applicationUrl": "http://localhost:5100;","environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development"}}
}

服务访问设置为5100,运行访问天气接口http://localhost:5100
Pasted image 20251018212614.png

Nginx配置HttpsHttp/2

Nginx版本要求必须在1.9.5以上,如此才能支持HTTP/2

查看版本

nginx -V
nginx version: nginx/1.25.3

配置证书

server {listen       5443 ssl http2;server_name  localhost;ssl_certificate      ssl/localhost.pem;ssl_certificate_key  ssl/localhost.key;ssl_session_cache    shared:SSL:1m;ssl_session_timeout  5m;ssl_ciphers  HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers  on;location / {proxy_pass http://localhost:5100;}
}

验证配置

如果提示[emerg] the "http2" parameter requires ngx_http_v2_module,则表示当前nginx 编译过程中并未包含ngx_http_v2_module 模块,需要重新编译,编译过程不在此处细说,网上查找资料;或者使用openrestry,这是nginx 的一个国人分支并加入lua 脚本等灵活支持,同样选择1.25.3版本。

>nginx -t
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in ./conf/nginx.conf:111
nginx: the configuration file ./conf/nginx.conf syntax is ok
nginx: configuration file ./conf/nginx.conf test is successful

如果带验证的证书输入密码错误会输出如下结果,Windows不建议设置密码:

>nginx -t
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in ./conf/nginx.conf:111
Enter PEM pass phrase:
nginx: [emerg] cannot load certificate key "./conf/ssl/localhost.key": PEM_read_bio_PrivateKey() failed (SSL: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt error:23077074:PKCS12 routines:PKCS12_pbe_crypt:pkcs12 cipherfinal error error:2306A075:PKCS12 routines:PKCS12_item_decrypt_d2i:pkcs12 pbe crypt error error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib)
nginx: configuration file ./conf/nginx.conf test failed

启动服务

Windows 中使用start 启动nginx

start nginx

查看端口和进程。

>netstat -ano|findstr 5443TCP    0.0.0.0:5443           0.0.0.0:0              LISTENING       24072
>taskkill |findstr 24072
nginx.exe                    24072 Console                    1     11,260 K

验证服务

浏览器访问https://localhost:5443/weatherforecast,结果如下,请求协议为h2 表示配置成功。
Pasted image 20251018231002.png

Kestrel配置HttpsHttp/2

这里只讲解通过配置文件进行配置的方式,通过代码的方式可以查看官方文档。
需要注意的是Properties/launchSettings.json中配置端口不能与Kestrel 节点端口一样。

修改launchSettings.json

修改Properties/launchSettings.json配置,服务端口不能与Kestrel 节点端口冲突。

{"$schema": "https://json.schemastore.org/launchsettings.json","profiles": {"http": {"commandName": "Project","dotnetRunMessages": true,"launchBrowser": false,"applicationUrl": "http://localhost:5000", // 改为其他端口而不是5100"environmentVariables": {"ASPNETCORE_ENVIRONMENT": "Development"}}}
}

添加Kestrel 节点

配置appsettings.Development.json 或者 appsettings.json,添加Kestrel 节点,端口为5100 并且使用https

{"Kestrel": {"Endpoints": {"HTTPS": {"Url": "https://localhost:5100","SslProtocols": [ "Tls12", "Tls13" ],"Protocols": "Http2"}},"Certificates": {"Default": {"Path": "ssl/localhost.pem", "KeyPath": "ssl/localhost.key"}}}
}

验证服务

运行项目,可以看到已经访问https
Pasted image 20251018233122.png

访问https://localhost:5100/weatherforecast,执行结果如下,表示配置成功:
Pasted image 20251018233101.png

http://www.hskmm.com/?act=detail&tid=33954

相关文章:

  • 日志|JAVAWEB|YApi|vue-cli|VUE-Element
  • 20232401 2025-2026-1 《网络与系统攻防技术》实验二实验报告
  • FFT学习小结
  • OI 笑传 #20
  • 幂等的双倍快乐,你值得拥有
  • 2025.10.18——1黄
  • 10.18总结
  • 10.17总结
  • 软考中级学习总结(2)
  • 2025年粉末冶金制品/零件厂家推荐排行榜,高精度耐磨粉末冶金零件,优质粉末冶金制品公司推荐!
  • Neo4j 图数据库搭建和 Springboot 访问
  • 2025粉末冶金制品优质厂家推荐:鸿瑞粉末冶金,专业定制品质卓越!
  • AI元人文理论框架体系研究:价值原语化的文明演进机制与治理范式转变——声明Ai研究
  • 20251018
  • [buuctf]bjdctf_2020_router
  • AtCoder Beginner Contest 428 ABCDE 题目解析
  • 稻草火把下的星辰:回忆我的90年代求学路
  • 10月18日日记
  • 第九章-实战篇-运维杰克
  • AntennaPod - 开源Android播客管理器
  • 硬件基础知识
  • 第三章 权限维持-linux权限维持-隐藏
  • 第五章 linux实战-黑链
  • AI元人文:价值原语化——在创新与传承间搭建文明桥梁
  • Channel小结
  • 线段树历史值学习笔记
  • 连续两行fastq、连续两行MD5值如何转换为每行一个fastq一个MD5格式
  • abc428
  • 深入解析密码库低级lowlevel抽象层接口与高级highlevel抽象层接口 - 实践
  • (第五次)随机森林和xGboost