场景:公司使用的大数据集群云服务器,安全扫描出严重漏洞,扫描漏洞如下:
安全漏洞扫描报告
端口 | 协议 | 服务 | 严重等级 | 漏洞 |
---|---|---|---|---|
– | ICMP | – | 弱 | ICMP timestamp请求响应漏洞 |
– | UDP | – | 弱 | 允许Traceroute探测 |
80 | TCP | http | 严重 严重 严重 严重 严重 弱 | OpenSSL 安全漏洞(CVE-2022-0778) Apache HTTP Server 环境问题漏洞(CVE-2022-22720) Apache HTTP Server 输入验证错误漏洞(CVE-2022-22719) Apache HTTP Server 缓冲区错误漏洞(CVE-2022-23943) Apache HTTP Server 输入验证错误漏洞(CVE-2022-22721) 可通过HTTP获取远端WWW服务信息 |
9010 | TCP | rmiregistry | 弱 | 检测到 Java RmiRegistry服务 |
当前服务版本号
软件名称 | 版本号 |
---|---|
Apache | 2.4.52 |
OpenSSL | 1.1.1m |
按照漏洞报告描述此次安全漏洞影响范围涉及Apache Http Server 2.4.52及之前版本,解决此漏洞需要进行http版本升级,Apache官网查看有最新版本2.4.53。
尝试了两种解决方法:
第一种是通过下载源码包编译安装替换新版本,编译安装成功,但是老版本的httpd服务包.rpm存在且不好删除(被cloudera-scm-agent所依赖),后续yum安装的库如果需要依赖httpd服务也是依赖的老版本。
第二种是通过配置codeIT库源,通过yum来更新httpd服务,推荐此方法实现。
方法一:源码编译安装
下载httpd、apr、pcre源码包
window上下载最新安装包 httpd-2.4.53.tar.gz,上传服务器,解压到/opt/httpd-2.4.53。
官网下载arp ,下载得到apr-util-1.6.1.tar.gz和apr-1.7.0.tar.gz ,上传服务器,解压放到/opt目录中,更名为apr 和 apr-util。
pcre下载,本文选用当时最新的10.37。
安装
安装参考官网安装教程。
编译安装apr
# 解压APR
tar -zxf /opt/apr-1.7.0.tar.gz
mv apr-1.7.0 apr
# 进入apr目录,配置、编译、安装
cd /opt/apr
./configure --prefix=/usr/local/apr
make && make install
编译安装apr-util
# 解压APR-Util
tar -zxf /opt/apr-util-1.6.1.tar.gz
mv apr-util-1.6.1 apr-util
# 进入apr-util目录,配置、编译、安装
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
报错解决
#报错:apr-util make时出错, [xml/apr_xml.lo] Error 1
#解决:原因是缺少expat库,yum install expat-devel即可```
**编译安装pcre2**
```powershell
# 解压pcre
tar -zxf pcre2-10.37.tar.gz
mv pcre2-10.37 pcre2
# 进入pcre2目录,配置、编译、安装
cd /opt/pcre2
./configure --prefix=/usr/local/pcre2
make && make install
# 创建连接将pcre2-config放到/usr/bin目录。
ln -s /usr/local/pcre2/bin/pcre2-config /usr/bin/pcre2-config
报错解决
#报错:http config时出错,error:Did not find script script at pcre2-config。
#解决:将pcre2编译安装目录/usr/local/pcre2/bin/pcre2-config文件链接到/usr/bin/pcre2-config。
ln -s /usr/local/pcre2/bin/pcre2-config /usr/bin/pcre2-config
编译安装httpd
# 解压httpd
tar -zxf /opt/httpd-2.4.53.tar.gz
mv httpd-2.4.53 httpd
#进入安装目录,配置文件,指定安装目录/usr/local/apache-http ,指定openssl安装目录,指定apr安装目录,指定apr-util安装目录,指定pcre安装目录
cd /opt/httpd
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre2 --enable-so --enable-rewrite --enable-module=so
#参数说明
#—prefix 代表服务安装目录
#—with 代表依赖的工具包的目录
#—enable-so 代表静态安装
# 编译安装
make && make install
# 修改编译安装目录/usr/local/apache2/conf/httpd.conf文件
#设置监听端口80
ServerName localhost:80
#注释掉如下内容
#<Directory />
# AllowOverride none
# Require all denied
#</Directory>
#修改DocumentRoot
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
#httpd 停止命令:
httpd stop
#httpd 启动命令
httpd start
#检查httpd 服务是否已停止
ps -ef|grep httpd
# 检查httpd版本命令,如果是全局的,也可以直接使用 httpd -v
httpd -v
报错解决
#报错 1:http make时出错,提示如下
······························
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserCreate'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ParserFree'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetUserData'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_StopParser'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_Parse'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler'
collect2: error: ld returned 1 exit status
# 解决:缺少了xml相关的库,需要安装libxml2-devel包。步骤如下:
# 直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持,要在删除已安装的apr-util并清空缓存重编译安装。
yum install -y libxml2-devel
rm -rf /usr/local/apr-util
cd /opt/apr-util
make clean
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
# 报错2:apachectl -k start启动报错
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.185. Set the 'ServerName' directive globally to suppress this message
修改httpd安装目录下/usr/local/apache2/conf/httpd.conf文件,修改如下:
ServerName localhost:80
# 报错3:systemctl start httpd 失败并提示Unit httpd.service could not be found.
#解决:需要将编译安装的httpd服务添加到linux系统自动服务。
#(1)将/usr/local/apache2/bin/apachectl文件拷贝到 /etc/rc.d/init.d 更名为httpd
cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
#(2)编辑脚本httpd,在#!/bin/sh第二行添加如下注释。
# chkconfig: 35 61 61
# description: Apache
方法二:httpd服务升级 codeit库
此方法需要服务器能访问公网。测试 ping www.baidu.com。
#下载yum repo,为安装epel-release做源。
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 清除所有yum缓存元数据
yum clean all
# 重新建立元数据
yum makecache
# 开启EPEL EPEL提供了CodeIT库需要的依赖
sudo yum install -y epel-release
# 安装codeIT库 这个库提供了最新版本的服务器软件(Apache & Nginx),在/etc/yum.repos.d目录下生成codeit.el7.repo
cd /etc/yum.repos.d
wget https://repo.codeit.guru/codeit.el`rpm -q --qf "%{VERSION}" $(rpm -q --whatprovides redhat-release)`.repo
# 再次查看apache包版本,可以看到新版本的信息。
yum info httpd
# 更新httpd
yum update httpd
# 查看版本
httpd -v
# 重启httpd
systemctl restart httpd
# 查看安装版本,此时rpm包都为最新版本,可被yum安装的其他服务所依赖
rpm -qa | grep httpd
如果服务器网络受限,需要通过跳板机来进行联网。
跳板机安装使用CCProxy
下载免费版:http://www.ccproxy.com/download.htm
设置跳板机IP:在“设置”里,勾选自动检测,此IP为跳板机内网IP。然后“启动”即可。云主机进行相关配置。
云服务器主机进行配置:
/etc/yum.conf 文件末尾添加 porxy=http://跳板机内网ip:808
/etc/wgetrc 文件末尾添加 http_proxy=http://跳板机内网ip:808