Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

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

$
0
0
【技术分享】linux 攻击面分析与行为记录

2017-09-27 17:44:14

阅读:1074次
点赞(0)
收藏
来源: anvilventures.com





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

作者:pwnzi





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

译者: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 0changesdetected(0warnings) #nc-l-p4455& [1]12489 #./dawgmon-gfA 1changedetected(0warnings) +port4455tcpopened #fg nc-l-p4455 ^C #./dawgmon-gfA 1changedetected(0warnings) +port4455tcpclosed #

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

#./dawgmon-gfA 0changesdetected(0warnings) #aptinstallvirtualbox-5.1 [...] #./dawgmon-gfA 33changesdetected(0warnings) +sizeoffile/etc/groupchangedfrom937to954 +file/etc/groupgotmodifiedon2017-09-1419:29:51.804811+0200 +sizeoffile/etc/group-changedfrom934to937 +file/etc/group-gotmodifiedon2017-09-1419:29:14.000000+0200 +file/etc/gshadowgotmodifiedon2017-09-1419:29:51.812811+0200 +sizeoffile/etc/gshadow-changedfrom777to794 +sizeoffile/etc/mailcapchangedfrom40777to41063 +file/etc/mailcapgotmodifiedon2017-09-1419:29:51.632812+0200 +file/etc/systemd/system/multi-user.target.wants/vboxautostart-service.servicegotcreated(owner=root,group=root,perm=lrwxrwxrwx,size=49) +file/etc/systemd/system/multi-user.target.wants/vboxballoonctrl-service.servicegotcreated(owner=root,group=root,perm=lrwxrwxrwx,size=51) +file/etc/systemd/system/multi-user.target.wants/vboxdrv.servicegotcreated(owner=root,group=root,perm=lrwxrwxrwx,size=35) +file/etc/systemd/system/multi-user.target.wants/vboxweb-service.servicegotcreated(owner=root,group=root,perm=lrwxrwxrwx,size=43) +file/etc/udev/rules.d/60-vboxdrv.rulesgotcreated(owner=root,group=root,perm=-rw-r--r--,size=747) +groupvboxusersadded +packagevirtualbox-5.1istobeinstalled +suidbinary/usr/lib/virtualbox/VBoxHeadlessgotcreated(owner=root,group=root,perm=-r-s--x--x,size=158304) +suidbinary/usr/lib/virtualbox/VBoxNetAdpCtlgotcreated(owner=root,group=root,perm=-r-s--x--x,size=23144) +suidbinary/usr/lib/virtualbox/VBoxNetDHCPgotcreated(owner=root,group=root,perm=-r-s--x--x,size=158304) +suidbinary/usr/lib/virtualbox/VBoxNetNATgotcreated(owner=root,group=root,perm=-r-s--x--x,size=158304) +suidbinary/usr/lib/virtualbox/VBoxSDLgotcreated(owner=root,group=root,perm=-r-s--x--x,size=158296) +suidbinary/usr/lib/virtualbox/VBoxVolInfogotcreated(owner=root,group=root,perm=-r-s--x--x,size=10472) +suidbinary/usr/lib/virtualbox/VirtualBoxgotcreated(owner=root,group=root,perm=-r-s--x--x,size=158304) +i-nodeforlisteningUNIXsocket/run/systemd/privatechangedfrom3428734to3452848 +systemdpropertyNInstalledJobschangedfrom8392199to3238035463 +systemdpropertyNNameschangedfrom261to263 +systemdunitfilevboxautostart-service.serviceadded +systemdunitfilevboxballoonctrl-service.serviceadded +systemdunitfilevboxdrv.serviceadded +systemdunitfilevboxweb-service.serviceadded +systemdunit'vboxautostart-service.service'added +systemdunit'vboxballoonctrl-service.service'added +systemdunit'vboxdrv.service'added +systemdunit'vboxweb-service.service'added

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


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

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

$./dawgmon-E NAMEDESCRIPTION check_bootanalyzes/bootdirectory check_etcanalyzes/etcdirectory check_groupsanalyzeUNIXgroupchanges check_usersanalyzeUNIXuserchanges envmonitorchangesinenvironmentvariables kernel_versionanalyzechangesinkernelversion list_blkdevanalyzechangesinavailableblockdevices list_ifacesanalyzechangesinnetworkinterfaces list_mountanalyzechangesinfilesystemmounts list_msqanalyzechangesinSystemVmessagequeues list_packagesanalyzechangesininstalledDebianpackages list_pipeslistsnamedpipes list_processesmonitorschangesintherunningprocesses(mostlyfordebugging) list_semanalyzechangesinSystemVsempahores list_shmanalyzechangesinSystemVsharedmemorysegments list_suidslistssetuid/setgidexecutables list_sysvinit_jobsanalyzechangesinavailableSystemVinitjobs list_tcpudp_portslistchangesinlisteningTCP/UDPportsforbothIPv4/IPv6 list_unix_portslistchangesinlisteningUNIXports lsb_versionanalyzechangesinLinuxStandardBasereleasesettings needs_restartcheckswhetherarebootisrequired(Ubuntu-only) systemd_propsshowallsystemdproperties systemd_socketslistsystemdsockets systemd_timerslistsystemdtimers systemd_unitfileslistallavailablesystemdunitfiles systemd_unitslistallavailablesystemdunits uptimeshowuptimeandcheckifreboothappened

总结与源码

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

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



【技术分享】Linux 攻击面分析与行为记录
【技术分享】Linux 攻击面分析与行为记录
本文由 安全客 翻译,转载请注明“转自安全客”,并附上链接。
原文链接:https://anvilventures.com/blog/linux-attack-surface-analysis.html

Viewing all articles
Browse latest Browse all 12749

Latest Images

Trending Articles





Latest Images