【技术分享】Linux 攻击面分析与行为记录

admin 2023-12-06 20:43:47 AnQuanKeInfo 来源:ZONE.CI 全球网 0 阅读模式

https://p0.ssl.qhimg.com/t012a0317c986ea5a89.jpg

译者:pwnzi

预估稿费:130RMB

投稿方式:发送邮件至linwei#360.cn,或登陆网页版在线投稿


前言

我们最近做了一个应用安全审查项目.其中,在Linux上安装一些软件时,我分析了大量安装之前和之后Linux中的状态和变化.这让我意识到我应该错过了某些linux下的分析工具,就像微软的Attack Surface Analyzer这种工具.显然,现在已经有很多的监控工具了,用以记录安全信息日志和事件管理.


工具的特性与扩展

这些工具通常归为SIEM(安全信息和事件管理(Security Information And Event Management))类工具.比如一款很经典的SEIM工具Tripwire.而且随着现在越来越火的机器学习和大数据的出现,有相当多的SEIM工具可供我们选择.这些工具看起来很拉风,或许你开会的时候可以拿出来给大家展示.但是这不是我真正想要的工具.这些工具有其使用场景,我用起来有点大材小用了. 我想,你肯定想要个有效且简单灵活的工具.该工具应该能在绝大部分的Linux系统里安装运行,并且能有良好的可扩展功能.于是我用python(3.x)和其标准库实现了一款工具.而且不需要复杂的后台进程和安装步骤.只需要放置几个Python脚本,就可以使用这个工具了.要完全实现自动化也比较容易,如果需要的话可以使用CI/DevOps类的工具,比如puppet和ansible.

另外,我想方便的扩展它.所以我决定简单的依赖于各种命令行工具.当然,也不仅仅是简单的解析命令行工具的输出,比如GNU的ls命令.好吧,就这么决定了.这就是我想要一个工具的原因,在做项目时我可以很快地扩展。测试结果还是比较可靠的,并且能得到及时的反馈.当然,在数百台不同的Linux/UNIX平台上测试时,可靠性结果差异还是挺大的,但是在不中断的情况下,还是能够产生一些可靠的结果.

有一些常见的陷阱,例如包括解析文件和处理命令行输出等.但是,不要让这阻止了脚步,事实上,在现实场景中,完美解析这个输出是完全不可能的。(比如).有很多软件都依赖于输出结果,比如GNU的ls.尽管某些命令行开发者添加了很多改动或者错误,我们最好依然能输出默认的正常结果.stackexchange


实际测试

对该工具介绍的挺多了,现在我们开始实际的测试下,测试环境是Ubuntu和Debian系统.如果你要用其他的操作系统进行测试,你可能需要针对BSD环境添加些特殊参数(e.g. ls –color=yes versus ls -G respectively).只需要少量工作量就可以在其他的系统里进行运行了. 具体不再多讲了.下面是dawgmon –dawg 监控的一些输出.我们运行该工具首先需要建立一个基线,用以和较新的结果进行比较.一个示例正在运行,其中已经有一个基线,然后我们打开一个端口,接着再关闭它,可能如下所示:

# ./dawgmon -gfA
0 changes detected (0 warnings)           
# nc -l -p 4455 &
[1] 12489
# ./dawgmon -gfA
1 change detected (0 warnings)            
+ port 4455 tcp opened
# fg
nc -l -p 4455
^C
# ./dawgmon -gfA
1 change detected (0 warnings)            
+ port 4455 tcp closed
#

从上面的结果看,我们可以准确的发现相应的端口关闭了.这不需要hook netlink链接库.它只是转化netstat的输出,并与先前缓存的结果比较。 在这个示例中,基线已经被缓存了,第一次dawgmon运行的时候,我们发现没有什么改变.然后Vbox正在安装运行另一个dawgmon并产生一个非常有用的检测到的攻击面列表。

# ./dawgmon -gfA
0 changes detected (0 warnings)            
# apt install virtualbox-5.1
[...]
# ./dawgmon -gfA
33 changes detected (0 warnings)          
+ size of file /etc/group changed from 937 to 954
+ file /etc/group got modified on 2017-09-14 19:29:51.804811 +0200
+ size of file /etc/group- changed from 934 to 937
+ file /etc/group- got modified on 2017-09-14 19:29:14.000000 +0200
+ file /etc/gshadow got modified on 2017-09-14 19:29:51.812811 +0200
+ size of file /etc/gshadow- changed from 777 to 794
+ size of file /etc/mailcap changed from 40777 to 41063
+ file /etc/mailcap got modified on 2017-09-14 19:29:51.632812 +0200
+ file /etc/systemd/system/multi-user.target.wants/vboxautostart-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=49)
+ file /etc/systemd/system/multi-user.target.wants/vboxballoonctrl-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=51)
+ file /etc/systemd/system/multi-user.target.wants/vboxdrv.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=35)
+ file /etc/systemd/system/multi-user.target.wants/vboxweb-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=43)
+ file /etc/udev/rules.d/60-vboxdrv.rules got created (owner=root, group=root, perm=-rw-r--r--, size=747)
+ group vboxusers added
+ package virtualbox-5.1 is to be installed
+ suid binary /usr/lib/virtualbox/VBoxHeadless got created (owner=root, group=root, perm=-r-s--x--x, size=158304)
+ suid binary /usr/lib/virtualbox/VBoxNetAdpCtl got created (owner=root, group=root, perm=-r-s--x--x, size=23144)
+ suid binary /usr/lib/virtualbox/VBoxNetDHCP got created (owner=root, group=root, perm=-r-s--x--x, size=158304)
+ suid binary /usr/lib/virtualbox/VBoxNetNAT got created (owner=root, group=root, perm=-r-s--x--x, size=158304)
+ suid binary /usr/lib/virtualbox/VBoxSDL got created (owner=root, group=root, perm=-r-s--x--x, size=158296)
+ suid binary /usr/lib/virtualbox/VBoxVolInfo got created (owner=root, group=root, perm=-r-s--x--x, size=10472)
+ suid binary /usr/lib/virtualbox/VirtualBox got created (owner=root, group=root, perm=-r-s--x--x, size=158304)
+ i-node for listening UNIX socket /run/systemd/private changed from 3428734 to 3452848
+ systemd property NInstalledJobs changed from 8392199 to 3238035463
+ systemd property NNames changed from 261 to 263
+ systemd unit file vboxautostart-service.service added
+ systemd unit file vboxballoonctrl-service.service added
+ systemd unit file vboxdrv.service added
+ systemd unit file vboxweb-service.service added
+ systemd unit 'vboxautostart-service.service' added
+ systemd unit 'vboxballoonctrl-service.service' added
+ systemd unit 'vboxdrv.service' added
+ systemd unit 'vboxweb-service.service' added

这里需要注意下,以上行为并不都是错误的;但是我们想要看虚拟机里是否有本地权限提升漏洞利用的行为,至少我们知道从哪里开始(suid root二进制文件就是一个观察点,其中有可能包含权限提升的漏洞). 这个工具目前看起来还是很有用的.目前该工具已经被一些企业开始实用了,我们经常收到回复邮件.比起那些复杂昂贵的SIEM工具,dawgmon就简单实用多了.它可以给我们一些警告提示,比如机器重启,某些配置文件不经意被修改等.下面是部分邮件截图: 

http://p4.qhimg.com/t018cc16befd280fa2e.png

 这些邮件来自不同组件的测试结果.比如监控着 SystemD, System V IPC, UNIX sockets, TCP/UDP 端口的变化,以及处理和修改`/etc`,`/boot`里文件的行为等.一些注意事项都写在了README里了,可在源代码中找到.下面是dawgmon 1.0版本的一些命令:

$ ./dawgmon -E
NAME                DESCRIPTION
check_boot          analyzes /boot directory
check_etc           analyzes /etc directory
check_groups        analyze UNIX group changes
check_users         analyze UNIX user changes
env                 monitor changes in environment variables
kernel_version      analyze changes in kernel version
list_blkdev         analyze changes in available block devices
list_ifaces         analyze changes in network interfaces
list_mount          analyze changes in file system mounts
list_msq            analyze changes in System V message queues
list_packages       analyze changes in installed Debian packages
list_pipes          lists named pipes
list_processes      monitors changes in the running processes (mostly for debugging)
list_sem            analyze changes in System V sempahores
list_shm            analyze changes in System V shared memory segments
list_suids          lists setuid/setgid executables
list_sysvinit_jobs  analyze changes in available System V init jobs
list_tcpudp_ports   list changes in listening TCP/UDP ports for both IPv4/IPv6
list_unix_ports     list changes in listening UNIX ports
lsb_version         analyze changes in Linux Standard Base release settings
needs_restart       checks whether a reboot is required (Ubuntu-only)
systemd_props       show all systemd properties
systemd_sockets     list systemd sockets
systemd_timers      list systemd timers
systemd_unitfiles   list all available systemd unit files
systemd_units       list all available systemd units
uptime              show uptime and check if reboot happened


总结与源码

我很高兴听到对该工具的各种建议,比如添加些其他命令和模块.那么请赶快通过github和邮件来提交patch吧.

在Anvil Ventures企业的github页面上你可以找到该工具的源代码:dawgmon.欢迎提交补丁,评论,建议和批评. 联系方式: github Twitter [email protected]

weinxin
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
评论:0   参与:  0