Linux服务器被黑遭敲诈,3小时紧急逆袭!

2017 年 9 月 21 日 DBAplus社群 陈浩


作者介绍

陈浩,北信源研发工程师,五年Linux运维工作经验,热衷运维技术研究、实践和团队分享。


1

起因


本来在家正常休息了,我们放在上海托管机房的线上服务器突然崩了远程不了,服务启动不了,然后让上海机房重启了一次,还是直接挂了,一直到我远程上才行。


2

现象

远程服务器发现出现这类信息


Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!


登录信息,然后翻墙去了国外网站查看




这个意思大概是:

问候,
你的服务器被黑客攻击和你的文件已经被删除了。
他们被删除之前,我们支持我们的服务器控制。
你必须发送总共3 BTC地址:1 b1ou6edreyffif3*******
不这么做将导致文件被删除后5天。
我们也可能泄露你的文件。

你可以通过电子邮件与onewayout@sigaint.org联系。我们不会提供任何文件之前付款。
再见!


呀的,被黑了!



3

开始排查


首先检查日志,以前做过安全运维,所以写过类似于检查命令和工具,开始一一排查。


#查看是否为管理员增加或者修改
find / -type f -perm 4000
#显示文件中查看是否存在系统以外的文件
rpm -Vf /bin/ls
rpm -Vf /usr/sbin/sshd
rpm -Vf /sbin/ifconfig
rpm -Vf /usr/sbin/lsof
#检查系统是否有elf文件被替换
#在web目录下运行
grep -r "getRuntime" ./
#查看是否有木马
find . -type f -name "*.jsp" | xargs grep -i  "getRuntime"
#运行的时候被连接或者被任何程序调用
find . -type f -name "*.jsp" | xargs grep -i  "getHostAddress"
#返回ip地址字符串
find . -type f -name "*.jsp" | xargs grep -i  "wscript.shell"
#创建WshShell对象可以运行程序、操作注册表、创建快捷方式、访问系统文件夹、管理环境变量
find . -type f -name "*.jsp" | xargs grep -i  "gethostbyname"
#gethostbyname()返回对应于给定主机名的包含主机名字和地址信息的hostent结构指针
find . -type f -name "*.jsp" | xargs grep -i  "bash"
#调用系统命令提权
find . -type f -name "*.jsp" | xargs grep -i  "jspspy"
#Jsp木马默认名字
find . -type f -name "*.jsp" | xargs grep -i  "getParameter"
fgrep - R "admin_index.jsp" 20120702.log > log.txt
#检查是否有非授权访问管理日志
#要进中间件所在日志目录运行命令
fgrep - R "and1=1"*.log>log.txt
fgrep - R "select "*.log>log.txt
fgrep - R "union "*.log>log.txt
fgrep - R "../../"*.log >log.txt

fgrep - R "Runtime"*.log >log.txt
fgrep - R "passwd"*.log >log.txt
#查看是否出现对应的记录
fgrep - R "uname -a"*.log>log.txt
fgrep - R "id"*.log>log.txt
fgrep - R "ifconifg"*.log>log.txt
fgrep - R "ls -l"*.log>log.txt
#查看是否有shell攻击

#以root权限执行
cat /var/log/secure
#查看是否存在非授权的管理信息
tail -n 10  /var/log/secure
last cat /var/log/wtmp
cat /var/log/sulog
#查看是否有非授权的su命令
cat /var/log/cron
#查看计划任务是否正常
tail -n 100 ~./bash_history | more
查看临时目录是否存在攻击者入侵时留下的残余文件
ls -la /tmp
ls -la /var/tmp
#如果存在.c .py .sh为后缀的文件或者2进制elf文件。




检查出有点类似于黑客的IP,只能猜测然后查看IP地址过滤出这个IP的访问信息

并查看IP地址是那边的。


Apr 17 03:14:56 localhost sshd[11499]: warning: /etc/hosts.deny, line 14: missing ":" separator
Apr 17 03:15:01 localhost sshd[11499]: Address 46.214.146.198 maps to 46-214-146-198.next-gen.ro, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Apr 17 03:15:01 localhost sshd[11499]: Invalid user ubnt from 46.214.146.198
Apr 17 03:15:01 localhost sshd[11500]: input_userauth_request: invalid user ubnt
Apr 17 03:15:01 localhost sshd[11499]: pam_unix(sshd:auth): check pass; user unknown
Apr 17 03:15:01 localhost sshd[11499]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=46.214.146.198 
Apr 17 03:15:01 localhost sshd[11499]: pam_succeed_if(sshd:auth): error retrieving information about user ubnt
Apr 17 03:15:03 localhost sshd[11499]: Failed password for invalid user ubnt from 46.214.146.198 port 34989 ssh2
Apr 17 03:15:03 localhost sshd[11500]: Connection closed by 46.214.146.198



就是他了,查看历史记录。


日志发现 Invalid user ubnt from 46.214.146.198。


历史记录和相关访问日志已经被删除,痕迹清除。


安装chrootkit检查是否有rootkit
mkdir chrootkit
cd chrootkit/
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
tar zxvf chkrootkit.tar.gz 
cd chkrootkit-0.50/
ls
yum install -y glibc-static
make sense
./chkrootkit


发现检查没有异常




打开 vi /etc/motd 发现


[root@mall ~]# vi /etc/motd 
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!
Hi, please view: http://pastie.org/pastes/10800563/text?key=hzzm4hk4ihwx1jfxzfizzq for further information in regards to your files!


查找不出后门也找不到相关命令,感觉思路受损,晕头转向。


最后查找下当天的Web访问日志和相关IP访问。


发现一条命令让我好奇,GET /cgi-bin/center.cgi?id=20 HTTP/1.1。


并且有点异常



发现像目前最流行的bash shell 漏洞,测试一下,果然存在漏洞。


env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
[root@mall ~]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable
this is a test


4

修复升级命令


yum -y install yum-downloadonly

yum -y install bash-4.1.2-33.el6_7.1.x86_64.rpm 

[root@mall tmp]# yum -y install bash-4.1.2-33.el6_7.1.x86_64.rpm 

已加载插件:fastestmirror,security


设置安装进程

诊断 bash-4.1.2-33.el6_7.1.x86_64.rpm: bash-4.1.2-33.el6_7.1.x86_64

bash-4.1.2-33.el6_7.1.x86_64.rpm 将作为 bash-4.1.2-15.el6_4.x86_64 的更新

Loading mirror speeds from cached hostfile

 * base: ftp.sjtu.edu.cn

 * extras: mirrors.skyshe.cn

 * updates: ftp.sjtu.edu.cn


解决依赖关系

--> 执行事务检查

---> Package bash.x86_64 0:4.1.2-15.el6_4 will be 升级

---> Package bash.x86_64 0:4.1.2-33.el6_7.1 will be an update

--> 完成依赖关系计算

依赖关系解决

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

总文件大小:3.0 M

下载软件包:

运行 rpm_check_debug 

执行事务测试

事务测试成功

执行事务

  正在升级   : bash-4.1.2-33.el6_7.1.x86_64

  清理 : bash-4.1.2-15.el6_4.x86_64

  Verifying  : bash-4.1.2-33.el6_7.1.x86_64

  Verifying  : bash-4.1.2-15.el6_4.x86_64

更新完毕:

  bash.x86_64 0:4.1.2-33.el6_7.1

完毕!


重新测试

[root@mall tmp]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

this is a test


5

完成后做了如下措施


  1. 修改了系统账号密码;

  2. 修改了sshd端口为2220;

  3. 修改Nginx用户nologin;

  4. 发现系统服务器存在bash严重漏洞 破壳漏洞(Shellshock)并修复;

  5. 更新完成后没有发现被入侵或者服务器自动宕机现象。



6

漏洞被利用过程


我发送GET请求–>目标服务器cgi路径


目标服务器解析这个get请求,碰到UserAgent后面的参数,Bash解释器就执行了后面的命令。



7

Shellshock介绍


Shellshock,又称Bashdoor,是在Unix中广泛使用的Bash shell中的一个安全漏洞,首次于2014年9月24日公开。许多互联网守护进程,如网页服务器,使用bash来处理某些命令,从而允许攻击者在易受攻击的Bash版本上执行任意代码。这可使攻击者在未授权的情况下访问计算机系统。



8

更多文章推荐


  • http://zone.wooyun.org/content/15392

  • http://www.freebuf.com/articles/system/50707.html

  • http://bobao.360.cn/news/detail/408.html 

  • http://hacker-falcon.blog.163.com/blog/static/23979900320148294531576/


文章来源:51CTO技术栈,经作者同意授权转载


近期热文:

有了这套脚本,DB维护 & MGR部署事半功倍!

从一次火烧眉毛的SQL优化,看应用架构规范与敏捷之殇

2017 Gdevops北京站:说好的干货与PPT来喽!

警惕:重Java轻SQL乃性能大忌!

从苦逼到牛逼,详解Linux运维工程师的打怪升级之路


登录查看更多
0

相关内容

JSP(全称 Java Server Pages)是由 Sun Microsystems 公司倡导和许多公司参与共同创建的一种使软件开发者可以响应客户端请求,而动态生成 HTML、XML 或其他格式文档的 Web 网页的技术标准。
【2020新书】实战R语言4,323页pdf
专知会员服务
98+阅读 · 2020年7月1日
【实用书】学习用Python编写代码进行数据分析,103页pdf
专知会员服务
190+阅读 · 2020年6月29日
【实用书】Python爬虫Web抓取数据,第二版,306页pdf
专知会员服务
115+阅读 · 2020年5月10日
深度神经网络实时物联网图像处理,241页pdf
专知会员服务
76+阅读 · 2020年3月15日
TensorFlow Lite指南实战《TensorFlow Lite A primer》,附48页PPT
专知会员服务
68+阅读 · 2020年1月17日
【干货】大数据入门指南:Hadoop、Hive、Spark、 Storm等
专知会员服务
94+阅读 · 2019年12月4日
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
Kali Linux 渗透测试:密码攻击
计算机与网络安全
15+阅读 · 2019年5月13日
PHP使用Redis实现订阅发布与批量发送短信
安全优佳
7+阅读 · 2019年5月5日
百度开源项目OpenRASP快速上手指南
黑客技术与网络安全
5+阅读 · 2019年2月12日
抖音爬虫
专知
3+阅读 · 2019年2月11日
去哪儿网开源DNS管理系统OpenDnsdb
运维帮
21+阅读 · 2019年1月22日
如何用GitLab本地私有化部署代码库?
Python程序员
9+阅读 · 2018年12月29日
比Selenium快100倍的方法爬东方财富网财务报表
程序人生
8+阅读 · 2018年10月31日
Python | Jupyter导出PDF,自定义脚本告别G安装包
程序人生
7+阅读 · 2018年7月17日
Arxiv
3+阅读 · 2019年3月1日
Bidirectional Attention for SQL Generation
Arxiv
4+阅读 · 2018年6月21日
Arxiv
3+阅读 · 2018年4月5日
Arxiv
3+阅读 · 2017年12月18日
VIP会员
相关资讯
msf实现linux shell反弹
黑白之道
49+阅读 · 2019年8月16日
Kali Linux 渗透测试:密码攻击
计算机与网络安全
15+阅读 · 2019年5月13日
PHP使用Redis实现订阅发布与批量发送短信
安全优佳
7+阅读 · 2019年5月5日
百度开源项目OpenRASP快速上手指南
黑客技术与网络安全
5+阅读 · 2019年2月12日
抖音爬虫
专知
3+阅读 · 2019年2月11日
去哪儿网开源DNS管理系统OpenDnsdb
运维帮
21+阅读 · 2019年1月22日
如何用GitLab本地私有化部署代码库?
Python程序员
9+阅读 · 2018年12月29日
比Selenium快100倍的方法爬东方财富网财务报表
程序人生
8+阅读 · 2018年10月31日
Python | Jupyter导出PDF,自定义脚本告别G安装包
程序人生
7+阅读 · 2018年7月17日
Top
微信扫码咨询专知VIP会员