华为云HIPS分析:软件篇

admin 2022年12月1日12:26:15评论91 views字数 15438阅读51分27秒阅读模式


华为云HIPS,名叫hostguard

软件包分析

看一下hostguard的安装包有哪些内容

root@unknown#rpm -ql hostguard
/etc/init.d/hostguard
/usr/local/hostguard/benchmarks/apache2.zip
/usr/local/hostguard/benchmarks/nginx.zip
/usr/local/hostguard/benchmarks/redis.zip
/usr/local/hostguard/benchmarks/ssh.zip
/usr/local/hostguard/benchmarks/tomcat.zip
/usr/local/hostguard/bin/curl
/usr/local/hostguard/bin/hostguard
/usr/local/hostguard/bin/libagent.so
/usr/local/hostguard/bin/libbasecomm.so
/usr/local/hostguard/bin/libbaselogger.so
/usr/local/hostguard/bin/libbaseutils.so
/usr/local/hostguard/bin/libmodargoseye.so
/usr/local/hostguard/bin/libmodbackupserver.so
/usr/local/hostguard/bin/libmoddetconf.so
/usr/local/hostguard/bin/libmodemgc.so
/usr/local/hostguard/bin/libmodfastscan.so
/usr/local/hostguard/bin/libmodfilemon.so
/usr/local/hostguard/bin/libmodiso.so
/usr/local/hostguard/bin/libmodkeyfiles.so
/usr/local/hostguard/bin/libmodlogin.so
/usr/local/hostguard/bin/libmodmfalogin.so
/usr/local/hostguard/bin/libmodprocmon.so
/usr/local/hostguard/bin/libmodpuppetdet.so
/usr/local/hostguard/bin/libmodpwd.so
/usr/local/hostguard/bin/libmodwebcms.so
/usr/local/hostguard/bin/libmodwebguard.so
/usr/local/hostguard/bin/libmodwhitelist.so
/usr/local/hostguard/bin/libmodwshell.so
/usr/local/hostguard/bin/pam_hg.so
/usr/local/hostguard/bin/rsync
/usr/local/hostguard/bin/snapshot.sh
/usr/local/hostguard/bin/upgrade
/usr/local/hostguard/conf/agent.conf
/usr/local/hostguard/conf/benchmarkconf
/usr/local/hostguard/conf/cmsvul.dat
/usr/local/hostguard/conf/config_ssh_log
/usr/local/hostguard/conf/config_ssh_xinetd.sh
/usr/local/hostguard/conf/dict.dat
/usr/local/hostguard/conf/graps.conf
/usr/local/hostguard/conf/magic.mgc
/usr/local/hostguard/conf/res.conf
/usr/local/hostguard/conf/selfitgr.dat
/usr/local/hostguard/conf/system.conf
/usr/local/hostguard/conf/user.key
/usr/local/hostguard/conf/version
/usr/local/hostguard/conf/wsyrules.dat
/usr/local/hostguard/lib/ansible.tar.gz
/usr/local/hostguard/lib/libcrypto.so.1.0.0
/usr/local/hostguard/lib/libcurl.so.4.5.0
/usr/local/hostguard/lib/libgcc_s.so.1
/usr/local/hostguard/lib/libmagic.so.1.0.0
/usr/local/hostguard/lib/libsecurec.so
/usr/local/hostguard/lib/libssl.so.1.0.0
/usr/local/hostguard/lib/libstdc_plus.so.6.0.14
/usr/local/hostguard/lib/libyara.so.3.4.0
/usr/local/hostguard/lib/libz.so.1.2.11
/usr/local/hostguard/lib/securecat.tar.gz

可见它是往/etc/init.d安装了一个服务,其它文件都安装在/usr/local/hostguard下,一共四个目录

  • bin: 执行文件和一些库
  • conf: 配置文件
  • lib: 库
  • benchmarks:基线

库分析

静态分析一个没有源代码的软件,在很多时候要看它引用了什么样的第三方库。因为很多第三方库的资料可以查询到,可以由此推断该软件可能会具体什么功能。

root@unknown#ls -l /usr/local/hostguard/lib 
total 4940
drwxr-xr-x 8 root root    4096 May 29  2019 ansible
lrwxrwxrwx 1 root root      43 Oct 26  2018 libcrypto.so -> /usr/local/hostguard/lib/libcrypto.so.1.0.0
-r-x------ 1 root root 2271262 Aug 25  2018 libcrypto.so.1.0.0
lrwxrwxrwx 1 root root      41 Oct 26  2018 libcurl.so -> /usr/local/hostguard/lib/libcurl.so.4.5.0
lrwxrwxrwx 1 root root      41 Oct 26  2018 libcurl.so.4 -> /usr/local/hostguard/lib/libcurl.so.4.5.0
-r-x------ 1 root root  516362 Aug 25  2018 libcurl.so.4.5.0
lrwxrwxrwx 1 root root      38 Oct 26  2018 libgcc_s.so -> /usr/local/hostguard/lib/libgcc_s.so.1
-r-x------ 1 root root   88552 Aug 25  2018 libgcc_s.so.1
lrwxrwxrwx 1 root root      42 Oct 26  2018 libmagic.so -> /usr/local/hostguard/lib/libmagic.so.1.0.0
lrwxrwxrwx 1 root root      42 Oct 26  2018 libmagic.so.1 -> /usr/local/hostguard/lib/libmagic.so.1.0.0
-r-x------ 1 root root  153612 Aug 25  2018 libmagic.so.1.0.0
-r-x------ 1 root root   47560 Aug 25  2018 libsecurec.so
lrwxrwxrwx 1 root root      40 Oct 26  2018 libssl.so -> /usr/local/hostguard/lib/libssl.so.1.0.0
-r-x------ 1 root root  518093 Aug 25  2018 libssl.so.1.0.0
-r-x------ 1 root root  999448 Aug 25  2018 libstdc_plus.so.6.0.14
lrwxrwxrwx 1 root root      47 Oct 26  2018 libstdc++.so.6 -> /usr/local/hostguard/lib/libstdc_plus.so.6.0.14
lrwxrwxrwx 1 root root      41 Oct 26  2018 libyara.so -> /usr/local/hostguard/lib/libyara.so.3.4.0
lrwxrwxrwx 1 root root      41 Oct 26  2018 libyara.so.3 -> /usr/local/hostguard/lib/libyara.so.3.4.0
-r-x------ 1 root root  330039 Aug 25  2018 libyara.so.3.4.0
lrwxrwxrwx 1 root root      39 Oct 26  2018 libz.so -> /usr/local/hostguard/lib/libz.so.1.2.11
lrwxrwxrwx 1 root root      39 Oct 26  2018 libz.so.1 -> /usr/local/hostguard/lib/libz.so.1.2.11
-r-x------ 1 root root  105663 Aug 25  2018 libz.so.1.2.11
drwxr-xr-x 5 root root    4096 Aug 25  2018 securecat

由上面内容可见:

  • ansible是一个IT自动化工具,用于批量运维的。由此可知**hostguard是通过ansible来远程更新配置,升级,服务管控**
  • libcryptolibssl.soopenssl提供的库,说明**hostguard需要做数据加密传输的 **
  • libcurl.so是一个免费且易于使用的客户端 URL 传输库, 说明**hostguard和远端应该是基于https协议传输数据**
  • libgcc_s.so是一个基础库,提供浮点运算和异常处理,和libstdc++, 说明**hostguard是用C++实现的**
  • libmagic.so是用来进行文件类型识别的, libyara.so是用于识别恶意文件的,两者结合说明**hostguard具有根据文件类型识别恶意软件的能力**
  • libz.so是对数据进行压缩的,说明**hostguard可能会对传输的数据进行压缩**

上面剩余securecatlibsecurec.so还不清楚用途。

root@unknown#tree securecat/
securecat/
├── __init__.py
├── linux
│   ├── apache_conf_parser.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── mysql_conf_parser.py
│   ├── nginxparser.py
│   └── nginxparser.pyc
├── modules
│   ├── file_permission.py
│   ├── __init__.py
│   ├── shell.py
│   └── xml_query.py
└── utils
    ├── __init__.py
    ├── __init__.pyc
    ├── playbook.py
    ├── playbook.pyc
    ├── runcontext.py
    ├── runcontext.pyc
    ├── template.py
    ├── template.pyc
    ├── variables.py
    └── variables.pyc

3 directories, 21 files

可见,securecat是用Python写的,用于对apache, mysql, nginx的配置检测的。说明**hostguard具有对apache,mysql,nginx配置安全扫描的功能**

root@unknown#readelf -s libsecurec.so |grep -v "UND"

Symbol table '.dynsym' contains 81 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     1: 0000000000001638     0 SECTION LOCAL  DEFAULT   10 
    28: 00000000000048c0  6212 FUNC    GLOBAL DEFAULT   12 securec_winput_s
    29: 0000000000002320  1360 FUNC    GLOBAL DEFAULT   12 cfltcvt
    30: 0000000000002c20  6462 FUNC    GLOBAL DEFAULT   12 securec_input_s
    31: 0000000000002870   108 FUNC    GLOBAL DEFAULT   12 vsnprintf_helper
    32: 00000000000028e0    40 FUNC    GLOBAL DEFAULT   12 getHwSecureCVersion
    33: 0000000000009810   149 FUNC    GLOBAL DEFAULT   12 wscanf_s
    34: 0000000000009100    88 FUNC    GLOBAL DEFAULT   12 vwscanf_s
    35: 0000000000008bb0   139 FUNC    GLOBAL DEFAULT   12 swprintf_s
    36: 00000000000098e8    16 FUNC    GLOBAL DEFAULT   13 _fini
    37: 0000000000001ed0    75 FUNC    GLOBAL DEFAULT   12 putWcharStrEndingZero
    38: 0000000000009540   258 FUNC    GLOBAL DEFAULT   12 wcsncpy_s
    39: 0000000000009010    95 FUNC    GLOBAL DEFAULT   12 vswprintf_s
    40: 0000000000001fb0    76 FUNC    GLOBAL DEFAULT   12 write_string_a
    41: 0000000000008c40   144 FUNC    GLOBAL DEFAULT   12 swscanf_s
    42: 0000000000009160   305 FUNC    GLOBAL DEFAULT   12 wcscat_s
    43: 0000000000008aa0   269 FUNC    GLOBAL DEFAULT   12 strtok_s
    44: 0000000000009070   130 FUNC    GLOBAL DEFAULT   12 vswscanf_s
    45: 0000000000006110  4363 FUNC    GLOBAL DEFAULT   12 securec_output_s
    46: 0000000000001b50   141 FUNC    GLOBAL DEFAULT   12 gets_s
    47: 0000000000001d40    84 FUNC    GLOBAL DEFAULT   12 memset_s
    48: 0000000000001f50    92 FUNC    GLOBAL DEFAULT   12 write_multi_char_a
    49: 0000000000001e40    34 FUNC    GLOBAL DEFAULT   12 memcpy_8b
    50: 0000000000001da0   149 FUNC    GLOBAL DEFAULT   12 scanf_s
    51: 0000000000001ac0   144 FUNC    GLOBAL DEFAULT   12 fwscanf_s
    52: 00000000000092a0   221 FUNC    GLOBAL DEFAULT   12 wcscpy_s
    53: 0000000000008d30    82 FUNC    GLOBAL DEFAULT   12 vfwscanf_s
    54: 00000000000097b0    89 FUNC    GLOBAL DEFAULT   12 wmemmove_s
    55: 0000000000008470   136 FUNC    GLOBAL DEFAULT   12 snprintf_s
    56: 0000000000008800   403 FUNC    GLOBAL DEFAULT   12 strncat_s
    57: 0000000000008df0   137 FUNC    GLOBAL DEFAULT   12 vsnprintf_s
    58: 000000000020b198     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
    59: 0000000000008620   271 FUNC    GLOBAL DEFAULT   12 strcat_s
    60: 000000000020b1a8     0 NOTYPE  GLOBAL DEFAULT   24 _end
    61: 0000000000001a30   144 FUNC    GLOBAL DEFAULT   12 fscanf_s
    62: 0000000000008cd0    82 FUNC    GLOBAL DEFAULT   12 vfscanf_s
    63: 0000000000007220  4687 FUNC    GLOBAL DEFAULT   12 securec_woutput_s
    64: 0000000000009650   256 FUNC    GLOBAL DEFAULT   12 wcstok_s
    65: 0000000000001be0   192 FUNC    GLOBAL DEFAULT   12 memcpy_s
    66: 0000000000001ca0   151 FUNC    GLOBAL DEFAULT   12 memmove_s
    67: 0000000000008ee0   151 FUNC    GLOBAL DEFAULT   12 vsscanf_s
    68: 0000000000008590   144 FUNC    GLOBAL DEFAULT   12 sscanf_s
    69: 00000000000089a0   251 FUNC    GLOBAL DEFAULT   12 strncpy_s
    70: 0000000000008e80    87 FUNC    GLOBAL DEFAULT   12 vsprintf_s
    71: 0000000000001e70    94 FUNC    GLOBAL DEFAULT   12 util_memmove
    72: 000000000020b198     0 NOTYPE  GLOBAL DEFAULT   23 _edata
    73: 0000000000008d90    88 FUNC    GLOBAL DEFAULT   12 vscanf_s
    74: 0000000000001f20    39 FUNC    GLOBAL DEFAULT   12 write_char_a
    75: 0000000000008f80   133 FUNC    GLOBAL DEFAULT   12 vswprintf_helper
    76: 0000000000008500   139 FUNC    GLOBAL DEFAULT   12 sprintf_s
    77: 0000000000009750    89 FUNC    GLOBAL DEFAULT   12 wmemcpy_s
    78: 0000000000008730   202 FUNC    GLOBAL DEFAULT   12 strcpy_s
    79: 0000000000009380   438 FUNC    GLOBAL DEFAULT   12 wcsncat_s
    80: 0000000000001638     0 FUNC    GLOBAL DEFAULT   10 _init

可知libsecurec.so只是提供一些字符串操作的安全函数,解决缓冲区溢出的。这只是软件工程上的东西,对分析没用。

从库的分析可知,hostguard是使用C++开发的,具有恶意软件识别,对apache, nginx, mysql有配置检测能力,并把检测压缩通过HTTPS传输给远端的HIPS,它的批量运维能力是由ansible提供

基线分析

查看benchmarks目录,

root@unknown#tree benchmarks/
benchmarks/
├── apache2.zip
├── nginx.zip
├── redis.zip
├── ssh.zip
└── tomcat.zip

可见,它集成了apache2, nginx, redis, ssh, tomcat的基线检查

展开ssh.zip来看

root@unknown#ls ssh
log  playbook.py  roles
root@unknown#ls ssh/roles/
hw
root@unknown#ls ssh/roles/hw
tasks  templates
root@unknown#ls ssh/roles/hw/tasks/
t_1_10.py  t_1_11.py  t_1_12.py  t_1_13.py  t_1_14.py  t_1_15.py  t_1_1.py  t_1_2.py  t_1_3.py  t_1_4.py  t_1_5.py  t_1_6.py  t_1_7.py  t_1_8.py  t_1_9.py
root@unknown#ls ssh/roles/hw/templates/
en_us  simple  zh_cn
root@unknown#ls ssh/roles/hw/templates/simple/
t_1_10.j2  t_1_11.j2  t_1_12.j2  t_1_13.j2  t_1_14.j2  t_1_15.j2  t_1_1.j2  t_1_2.j2  t_1_3.j2  t_1_4.j2  t_1_5.j2  t_1_6.j2  t_1_7.j2  t_1_8.j2  t_1_9.j2  total.j2
root@unknown#head -n 20 ssh/roles/hw/tasks/t_1_10.py
# -*- coding: UTF-8 -*-

import os
import re
import sys
import json
from utils import template

def getTags():
    return ['1','1.10']

def getTitle(lang):
    if lang == 'en_us':
        return "1.10 Rule:Use a more secure Ciphers algorithm."
    else:
        return "1.10 规则:使用更加安全的Ciphers算法"

def runTask(runcontext):
    ansibleParams=runcontext.getModParamsInstance()
    runcontext.setModParamsInstanceValue(ansibleParams,"chdir",None)
root@unknown#for f in `ls -d ssh/roles/hw/tasks/*`; do sed -n '16p' $f; done
        return "1.10 规则:使用更加安全的Ciphers算法"
        return "1.11 规则:确保使用更安全的MAC算法"
        return "1.12 规则:确保配置了SSH空闲超时间隔"
        return "1.13 规则:确保SSH LoginGraceTime设置为一分钟或更短"
        return "1.14 规则:确保对密钥文件的权限进行了配置"
        return "1.15 规则:确保配置了SSH警告横幅"
    else:
        return "1.2 规则:确保SSH协议设置为2"
        return "1.3 规则:确保SSH的LogLevel设置成INFO或VERBOSE"
        return "1.4 规则:确保SSH X11转发被禁用"
        return "1.5 规则:确保SSH中MaxAuthTries设置为小于等于4"
        return "1.6 规则:确保SSH中IgnoreRhosts设置为enabled"
        return "1.7 规则:确保SSH中HostbasedAuthentication关闭"
        return "1.8 规则:确保SSH PermitEmptyPasswords被禁用"
        return "1.9 规则:确保SSH PermitUserEnvironment被禁用"

是对sshd_config一些安全配置进行检查的脚本。

对其它zip文件也是同样结果。

可见,hostguard集成apache2, tomcat, ssh, nginx, redis的安全配置基线检查的脚本

配置分析

root@unknown#tree conf
conf
├── agent.conf
├── agentinfo
├── benchmarkconf
├── cmsvul.dat
├── config_ssh_log
├── config_ssh_xinetd.sh
├── dict.dat
├── graps.conf
├── magic.mgc
├── master.dat
├── policy.dat
├── res.conf
├── selfitgr.dat
├── sending.dat
├── system.conf
├── user.key
├── version
└── wsyrules.dat

1 directory, 17 files

其中*.dat文件都是数据文件,无法查看,只能从名称判断,应该是一些策略,字典文件。

magic.mgc是用于识别文件类型的数据文件。

那么看那些*.conf文件,

root@unknown#ls *.conf
agent.conf  graps.conf  res.conf  system.conf
root@unknown#cat system.conf 
[system]
master=https://xxx.xxx.xxx.xxx:443/hostmgr/websocket
connect_retry=20

[log]
maxsize=10

[argoseye]
limit_size=5
root@unknown#cat res.conf 
[reslimits]
max_mem=150
max_cpu=10
max_cpu_period=30
root@unknown#cat agent.conf 
[agent]
init=modpwd
mode=tenant

可以看到对端地址是多少,是websocket, 连接重试(次数20次或间隔20秒),argoseye监控(5个线程或5个队列或5个对象),进程资源消耗(CPU在10%以内,内存150M以内,达到最大cpu是30秒还是30次?),云agent的配置

而通过graps.conf文件分析,则是有意思多了。节选部分

###################################################################
# detshell module config
# web server path.
[web_path] /srv/www/htdocs

# file type.
[file_type] css
[file_type] gif

# regex rule.
[file_size] 40960

# regex rule.
[regex_rule] eval.*($_POST[(.*)]);|1
[regex_rule] eval.*($_GET[(.*)]);|1
[regex_rule] eval.*(base64_decode(|1
[regex_rule] `$_REQUEST[.*]`|1
[regex_rule] echo.*preg_replace(".*/.*e.*id|1
[regex_rule] create_function(|1
[regex_rule] passthru(|2
[regex_rule] shell_exec(|2
[regex_rule] exec(|9
[regex_rule] base64_decode(|7
[regex_rule] phpspy|1
[regex_rule] mix.dll|1
[regex_rule] cmd.exe|1
[regex_rule] back_connect.*="|1
[regex_rule] eval(gzinflate(base64_decode(|1
[regex_rule] eval(gzuncompress(base64_decode(|1
[regex_rule] eval(base64_decode(|1
[regex_rule] eval(gzinflate(|1
[regex_rule] eval(.*gzinflate(base64_decode(|1
[regex_rule] WScript.Network|1
[regex_rule] clsid:72C24DD1-D70A-438B-8A42-98424B88AFB8|1
[regex_rule] classid:093FF999-1EA0-4079-9525-9614C3504B74|1
[regex_rule] clsid:F935DC22-1CF0-11D0-ADB9-00C04FD58A0B|1
[regex_rule] clsid:093FF999-1EA0-4079-9525-9614C3504B74|1
[regex_rule] clsid:F935DC26-1CF0-11D0-ADB9-00C04FD58A0B|1
[regex_rule] clsid:0D43FE01-F093-11CF-8940-00A0C9054228|1
[regex_rule] clsid:13709620-C279-11CE-A49E-444553540000|1

这是对Web目录进行Webshell的检测,特别是clsid, classid这些规则,可是对利用windows的COM机制的webshell进行检测。

可见, hostguard具有对Webshell的检测能力

对两个config开头的文件分析

root@unknown#file conf/config*
conf/config_ssh_log:       ASCII text
conf/config_ssh_xinetd.sh: Bourne-Again shell script, ASCII text executable
root@unknown#head -n 10 conf/config_ssh_log
#/bin/bash

facility=""
if [ -f "/etc/ssh/sshd_config" ]; then
    facility=$(grep "^SyslogFacility" /etc/ssh/sshd_config|awk '{print $2}')
fi

if [ "x${facility}" == "x" ]; then
    facility="auth"
fi

从内容分析,只是把sshd的syslog配置变更,为了后面好采集。

执行文件分析

看一下bin目录的东西

root@unknown#tree bin
bin
├── a.out
├── curl
├── hostguard
├── hostguard.pid
├── libagent.so
├── libbasecomm.so
├── libbaselogger.so
├── libbaseutils.so
├── libmodargoseye.so
├── libmodbackupserver.so
├── libmoddetconf.so
├── libmodemgc.so
├── libmodfastscan.so
├── libmodfilemon.so
├── libmodiso.so
├── libmodkeyfiles.so
├── libmodlogin.so
├── libmodmfalogin.so
├── libmodprocmon.so
├── libmodpuppetdet.so
├── libmodpwd.so
├── libmodwebcms.so
├── libmodwebguard.so
├── libmodwhitelist.so
├── libmodwshell.so
├── pam_hg.so
├── rsync
├── snapshot.sh
└── upgrade

从名字来看,应该是这样:

  • libbasecomm.so:基础通信模块
  • libbaselogger.so:抓取系统日志,还是本身日志管理?
  • libbaseutils.so:基础工具
  • libmodargoseye.so: 未知,按照名称含义,应该多角度监控
  • libmodbackupserver.so:备份?之前使用它防篡改功能,应该是通过这个实现的。
  • libmoddetconf.so: 配置检测
  • libmodemgc.so: 未知
  • libmodfastscan.so: 快速扫描
  • libmodfilemon.so: 文件监控,通过readelf -s libmodfilemon.so|grep inotify是看到,有实时监控
  • libmodiso.so: 未知
  • libmodkeyfiles.so: 关键文件监控?还是密钥管理?
  • libmodlogin.so: 登录监控?
  • libmodmfalogin.so: 多因素登录监控?
  • libmodprocmon.so:  进程监控
  • libmodpuppetdet.so: 僵尸进程监控?
  • libmodpwd.so: 弱密码监控?
  • libmodwebcms.so:  对cms系统漏洞监控
  • libmodwebguard.so:web防护
  • libmodwhitelist.so: 白名单管理
  • libmodwshell.so: webshell检测?
  • pam_hg.so:pam模块?用来做什么?

由此可见, hostguard具有防篡改,配置检测,扫描,文件监控,登录监控,进程监控,弱密码监控,cms漏洞监控,web防护,webshell检测,白名单管理的功能

=========================================

暗号:a7c77


原文始发于微信公众号(debugeeker):华为云HIPS分析:软件篇

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年12月1日12:26:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   华为云HIPS分析:软件篇https://cn-sec.com/archives/1435438.html

发表评论

匿名网友 填写信息