禁用3DES和DES弱加密算法,保证SSL证书安全
Posted 就是洒家呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了禁用3DES和DES弱加密算法,保证SSL证书安全相关的知识,希望对你有一定的参考价值。
漏洞介绍
一、 最近在工作中,公司产品负责人反馈了项目地区一台服务器里tomcat被客户检测到有漏洞,这是绿盟给到的漏洞报告反馈如下图:
1、第一个漏洞是CVE-2021-42340,这个不多介绍,当时服务器Apache Tomcat版本为8.5.69,在受影响的版本范围内,升级到8.5.72版本以上即可修复。
2、主要看这个CVE-2016-2183漏洞
那么简单介绍下CVE-2016-2183漏洞。
漏洞描述:
SSL全称是Secure Sockets Layer,安全套接字层,它是由网景公司(Netscape)设计的主要用于Web的安全传输协议,目的是为网络通信提供机密性、认证性及数据完整性保障。如今,SSL已经成为互联网保密通信的工业标准。SSL最初的几个版本(SSL 1.0、SSL2.0、SSL 3.0)由网景公司设计和维护,从3.1版本开始,SSL协议由因特网工程任务小组(IETF)正式接管,并更名为TLS(Transport Layer Security),发展至今已有TLS 1.0、TLS1.1、TLS1.2,TLS1.3这几个版本。TLS, SSH, IPSec协商及其他产品中使用的DES及Triple DES密码存在大约四十亿块的生日界,这可使远程攻击者通过Sweet32攻击,获取纯文本数据。
风险级别:低
该漏洞又称为SWEET32(https://sweet32.info)是对较旧的分组密码算法的攻击,它使用64位的块大小,缓解SWEET32攻击OpenSSL 1.0.1和OpenSSL 1.0.2中基于DES密码套件从“高”密码字符串组移至“中”;但OpenSSL 1.1.0发布时自带这些,默认情况下禁用密码套件。该问题在新的openssl版本中已解决。
在上图中可以看出,服务器10004端口存在低级别的加密算法。我们来自己测试下。
使用nmap扫描工具测试。输入命令nmap -sV -p 10004 --script ssl-enum-ciphers 服务器IP
如下图,可以看出存在C低级别3DES算法。A级别为符合安全的算法。
解决办法
二、避免使用3DES和DES算法
对于apache服务器禁止使用3DES加密算法
Tomcat中:
在tomcat/conf/server.xml中找到https端口配置,添加Ciphers="......",此处添加支持的算法,不支持的算法请勿加入其中!
<Connector port="10004" protocol="org.apache.coyote.http11.Http11NioProtocol" maxHttpHeaderSize="8192" minSpareThreads="250" maxSpareThreads="1000"
enableLookups="false" acceptCount="1000" connectionTimeout="8000"
maxProcessors="2000" maxThreads="2000" SSLEnabled="true" scheme="https" secure="true" keystoreFile="cert/XXXXXXXXXXXX.pfx" keystoreType="xxxxx" keystorePass="xxxxxxxx" sslEnabledProtocols="TLSv1" clientAuth="false" SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
Ciphers="TLS_DHE_RSA_WITH_AES_128_CBC_SHA ,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_CBC_SHA,TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA ,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
/>
重新启动Tomcat
cd tomcat-home/bin/
./shutdown.sh :关闭
./startup.sh :启动
Nginx中:
在nginx/conf/nginx.conf中配置https端口配置
server
listen 80;
listen 443 ssl https2;
#使用HTTP/2,需要Nginx1.9.7以上的版本
ssl on;
server_name ykqi.cn www.ykqi.cn;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/dist/ykqi;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
add_header X-Frame-Options DENY;
#禁止被嵌入框架
add_header X-Content-Type-Options nosniff;
#防止在IE9、Chrome和Safari中的MIME类型混淆攻击
ssl_certificate /www/server/panel/vhost/ssl/1_ykqi_bundle.crt;
ssl_certificate_key /www/server/panel/vhost/ssl/2_ykqi.key;
#SSL证书文件位置
ssl_dhparam /www/server/panel/vhost/ssl/dhparam.pem;
#DH-Key交换**文件位置
#SSL优化配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#只允许TLS协议
ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
#加密套件,这里用了CloudFlares Internet facing SSL cipher configuration
ssl_prefer_server_ciphers on;
#由服务器协商最佳的加密算法
ssl_session_cache builtin:1000 shared:SSL:10m;
#Session Cache,将Session缓存到服务器,这可能会占用更多的服务器资源
ssl_session_tickets on;
#开启浏览器的Session Ticket缓存
ssl_session_timeout 10m;
#SSL session过期时间
add_header Strict-Transport-Security "max-age=6307200; includeSubdomains; preload";
#开启HSTS,并设置有效期为“6307200秒”(6个月),包括子域名(根据情况可删掉),预加载到浏览器缓存(根据情况可删掉)
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
#PROXY-START
location /
proxy_pass http://localhost:8090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
#持久化连接相关配置
#proxy_connect_timeout 30s;
#proxy_read_timeout 86400s;
#proxy_send_timeout 30s;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
#add_header X-Cache $upstream_cache_status;
#expires 12h;
#禁止访问的文件或目录
location ~ ^/(\\.user.ini|\\.htaccess|\\.git|\\.svn|\\.project|LICENSE|README.md)
return 404;
#一键申请SSL证书验证目录相关设置
location ~ \\.well-known
allow all;
access_log /www/wwwlogs/ykiq.cn.log;
error_log /www/wwwlogs/ykqi.cn.error.log;
配置完重新启动Nginx!
CentOS 6.x下面:
service nginx restart
CentOS 7.x下面:
systemctl restart nginx
现在已经禁用了3DES算法了!
然后再重新nmap扫描。
beego禁用3DES和DES弱加密算法--SSL/TLS协议信息泄露漏洞(CVE-2016-2183)原理扫描
目录
程序代码
用beego起的一个 https 服务,被扫描出了漏洞(SSL/TLS协议信息泄露漏洞(CVE-2016-2183)),需要禁用DES加密算法
参考源码,解决方法如下:
beego.Run()前添加
ciphers := []uint16
tls.TLS_AES_128_GCM_SHA256,
tls.TLS_CHACHA20_POLY1305_SHA256,
tls.TLS_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
beego.BeeApp.Server.TLSConfig = &tls.ConfigPreferServerCipherSuites: true
beego.BeeApp.Server.TLSConfig.CipherSuites = ciphers
nmap重新扫描
需自行安装nmap
nmap -sV -p 扫描端口 --script ssl-enum-ciphers 扫描IP
扫描后加密算法中已踢出DES
root@ip:~# nmap -sV -p 443 --script ssl-enum-ciphers ip
Starting Nmap 7.60 ( https://nmap.org ) at 2022-07-06 11:32 CST
Nmap scan report for ip
Host is up (0.000044s latency).
PORT STATE SERVICE VERSION
443/tcp open ssl/https beegoServer:2.0.0
| fingerprint-strings:
| FourOhFourRequest, GetRequest, HTTPOptions:
| HTTP/1.0 200 OK
| Access-Control-Allow-Credentials: true
| Access-Control-Allow-Headers: Access-Control-Allow-Origin,ContentType,Authorization,accept,accept-encoding, authorization, content-type, token
| Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS
| Access-Control-Allow-Origin: *
| Access-Control-Max-Age: 1728000
| Server: beegoServer:2.0.0
| Date: Wed, 06 Jul 2022 03:32:42 GMT
| Content-Length: 73
| Content-Type: text/plain; charset=utf-8
| "result":"SESSION_OUT","resultMsg":"token must not null","retData":null
| GenericLines:
| HTTP/1.1 400 Bad Request
| Content-Type: text/plain; charset=utf-8
| Connection: close
|_ Request
|_http-server-header: beegoServer:2.0.0
| ssl-enum-ciphers:
| TLSv1.0:
| ciphers:
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
| compressors:
| NULL
| cipher preference: server
| TLSv1.1:
| ciphers:
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
| compressors:
| NULL
| cipher preference: server
| TLSv1.2:
| ciphers:
| TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (rsa 2048) - A
| TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (rsa 2048) - A
| compressors:
| NULL
| cipher preference: server
|_ least strength: A
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port443-TCP:V=7.60%T=SSL%I=7%D=7/6%Time=62C5025A%P=x86_64-pc-linux-gnu%
SF:r(GetRequest,209,"HTTP/1\\.0\\x20200\\x20OK\\r\\nAccess-Control-Allow-Creden
SF:tials:\\x20true\\r\\nAccess-Control-Allow-Headers:\\x20Access-Control-Allow
SF:-Origin,ContentType,Authorization,accept,accept-encoding,\\x20authorizat
SF:ion,\\x20content-type,\\x20token\\r\\nAccess-Control-Allow-Methods:\\x20POST
SF:,\\x20GET,\\x20PUT,\\x20OPTIONS\\r\\nAccess-Control-Allow-Origin:\\x20\\*\\r\\nA
SF:ccess-Control-Max-Age:\\x201728000\\r\\nServer:\\x20beegoServer:2\\.0\\.0\\r\\n
SF:Date:\\x20Wed,\\x2006\\x20Jul\\x202022\\x2003:32:42\\x20GMT\\r\\nContent-Length
SF::\\x2073\\r\\nContent-Type:\\x20text/plain;\\x20charset=utf-8\\r\\n\\r\\n\\"resu
SF:lt\\":\\"SESSION_OUT\\",\\"resultMsg\\":\\"token\\x20must\\x20not\\x20null\\",\\"r
SF:etData\\":null")%r(HTTPOptions,209,"HTTP/1\\.0\\x20200\\x20OK\\r\\nAccess-Co
SF:ntrol-Allow-Credentials:\\x20true\\r\\nAccess-Control-Allow-Headers:\\x20Ac
SF:cess-Control-Allow-Origin,ContentType,Authorization,accept,accept-encod
SF:ing,\\x20authorization,\\x20content-type,\\x20token\\r\\nAccess-Control-Allo
SF:w-Methods:\\x20POST,\\x20GET,\\x20PUT,\\x20OPTIONS\\r\\nAccess-Control-Allow-
SF:Origin:\\x20\\*\\r\\nAccess-Control-Max-Age:\\x201728000\\r\\nServer:\\x20beego
SF:Server:2\\.0\\.0\\r\\nDate:\\x20Wed,\\x2006\\x20Jul\\x202022\\x2003:32:42\\x20GMT
SF:\\r\\nContent-Length:\\x2073\\r\\nContent-Type:\\x20text/plain;\\x20charset=ut
SF:f-8\\r\\n\\r\\n\\"result\\":\\"SESSION_OUT\\",\\"resultMsg\\":\\"token\\x20must\\x2
SF:0not\\x20null\\",\\"retData\\":null")%r(FourOhFourRequest,209,"HTTP/1\\.0\\x
SF:20200\\x20OK\\r\\nAccess-Control-Allow-Credentials:\\x20true\\r\\nAccess-Cont
SF:rol-Allow-Headers:\\x20Access-Control-Allow-Origin,ContentType,Authoriza
SF:tion,accept,accept-encoding,\\x20authorization,\\x20content-type,\\x20toke
SF:n\\r\\nAccess-Control-Allow-Methods:\\x20POST,\\x20GET,\\x20PUT,\\x20OPTIONS\\
SF:r\\nAccess-Control-Allow-Origin:\\x20\\*\\r\\nAccess-Control-Max-Age:\\x20172
SF:8000\\r\\nServer:\\x20beegoServer:2\\.0\\.0\\r\\nDate:\\x20Wed,\\x2006\\x20Jul\\x2
SF:02022\\x2003:32:42\\x20GMT\\r\\nContent-Length:\\x2073\\r\\nContent-Type:\\x20t
SF:ext/plain;\\x20charset=utf-8\\r\\n\\r\\n\\"result\\":\\"SESSION_OUT\\",\\"result
SF:Msg\\":\\"token\\x20must\\x20not\\x20null\\",\\"retData\\":null")%r(GenericLin
SF:es,67,"HTTP/1\\.1\\x20400\\x20Bad\\x20Request\\r\\nContent-Type:\\x20text/plai
SF:n;\\x20charset=utf-8\\r\\nConnection:\\x20close\\r\\n\\r\\n400\\x20Bad\\x20Reques
SF:t");
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 93.80 seconds
root@iZ254d5laqgZ:~# ^C
root@iZ254d5laqgZ:~# ls
kh tools
root@iZ254d5laqgZ:~#
Welcome to Ubuntu 18.04.6 LTS (GNU/Linux 4.15.0-177-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
New release '20.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
以上是关于禁用3DES和DES弱加密算法,保证SSL证书安全的主要内容,如果未能解决你的问题,请参考以下文章
beego禁用3DES和DES弱加密算法--SSL/TLS协议信息泄露漏洞(CVE-2016-2183)原理扫描
beego禁用3DES和DES弱加密算法--SSL/TLS协议信息泄露漏洞(CVE-2016-2183)原理扫描