LoginSignup
27
12

More than 1 year has passed since last update.

【悪用厳禁】straceコマンドで他の人の行動を追跡する

Posted at

船井総研デジタルのよもぎたです。

Linuxでのstraceコマンドの使い方まとめ記事を書いていて、他の人のシェルにアタッチすれば、アタッチしたシェルで何をしているか追跡できるよね、と思ったので、具体的に考えてみました。

タイトルにある通り、悪用厳禁でお願いします。他のユーザーのプライバシーは尊重しましょう。

相手が悪意を持ったユーザーでもない限り、使う場面はないと思います。ただ、気付いたらまとめておきたい性分なので、まとめます。

他のユーザーが実行したコマンドを追跡する

execveシステムコールを追跡することで、他のユーザーが実行したコマンドを追跡します。

追跡される側

$ ps | grep bas[h]
   2935 pts/2    00:00:00 bash
$ who >/dev/null
$ bash -c "date >/dev/null"
$ <CTRL-D>
logout

追跡する側

$ sudo strace -e execve -f -p 2935
strace: Process 2935 attached
strace: Process 2969 attached
strace: Process 2970 attached
[pid  2969] execve("/usr/bin/ps", ["ps"], 0x557f10ea52a0 /* 24 vars */) = 0
[pid  2970] execve("/usr/bin/grep", ["grep", "--color=auto", "bas[h]"], 0x557f10ea52a0 /* 24 vars */) = 0
[pid  2969] +++ exited with 0 +++
[pid  2970] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2969, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 2971 attached
[pid  2971] execve("/usr/bin/who", ["who"], 0x557f10ea52a0 /* 24 vars */) = 0
[pid  2971] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2971, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 2973 attached
[pid  2973] execve("/usr/bin/bash", ["bash", "-c", "date >/dev/null"], 0x557f10ea52a0 /* 24 vars */) = 0
strace: Process 2974 attached
[pid  2974] execve("/usr/bin/date", ["date"], 0x560baa96cf30 /* 24 vars */) = 0
[pid  2974] +++ exited with 0 +++
[pid  2973] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2974, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
[pid  2973] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2973, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
strace: Process 2975 attached
[pid  2975] execve("/usr/bin/clear_console", ["/usr/bin/clear_console", "-q"], 0x557f10ea52a0 /* 24 vars */) = 0
[pid  2975] +++ exited with 1 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=2975, si_uid=1000, si_status=1, si_utime=0, si_stime=0} ---
+++ exited with 0 +++

suした時のパスワードも丸見え

read()write()を追跡することで、suした時のパスワードも見えてしまいます。

追跡される側

$ su - test
Password:
su: warning: cannot change directory to /home/test: No such file or directory
$ <CTRL-D>
$ <CTRL-D>

追跡する側

~$ sudo strace -e read,write -f -p 3486 2>&1 | grep -A1 Password
[pid  3502] write(2, "Password: ", 10)  = 10
[pid  3502] read(0, "P@ssw0rd\n", 511)  = 9

同じようなやり方で、sshの秘密鍵を盗み見ることも出来てしまいます。冒頭にも書きましたが悪用厳禁、他のユーザーのプライバシーを尊重するようにお願いします。

最後までお読みいただきありがとうございました。

27
12
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
12