私のライブラリをLinuxの他のバイナリにどのようにリンクできますか?

私のライブラリをLinuxの他のバイナリにどのようにリンクできますか?

私の目標は、システムにコマンドを記録するための教育目的のツールを開発することです。これまでこれを行う原始的な方法が見つかりましたが、すべて簡単に迂回できるため、命令をすぐに傍受しようというアイデアがあり、 を紹介するようになりましたLD_PRELOADING

私はCプログラムで実行されるコマンドを傍受するために使用できる動作するCコードを正常に作成しましたが、グローバルexecveレベルでこれを達成する方法を知りたいです。

ありがとうございます。皆さんの意見を聞いてくれて本当に嬉しいです!

ベストアンサー1

マニュアルページで答えを見つけることができますld.so(8)

          There are various methods of specifying libraries to be
          preloaded, and these are handled in the following order:

          (1) The LD_PRELOAD environment variable.

          (2) The --preload command-line option when invoking the
              dynamic linker directly.

          (3) The /etc/ld.so.preload file (described below).

...

   /etc/ld.so.preload
          File containing a whitespace-separated list of ELF shared
          objects to be loaded before the program.  See the
          discussion of LD_PRELOAD above.  If both LD_PRELOAD and
          /etc/ld.so.preload are employed, the libraries specified
          by LD_PRELOAD are preloaded first.  /etc/ld.so.preload has
          a system-wide effect, causing the specified libraries to
          be preloaded for all programs that are executed on the
          system.  (This is usually undesirable, and is typically
          employed only as an emergency remedy, for example, as a
          temporary workaround to a library misconfiguration issue.)

ところで、Linuxカーネルにはすでにプロセス会計システムで実行されている各プロセスの機能を記録できます。この機能の唯一の欠点は、コマンドライン全体と引数ではなくプロセス名だけを記録することです。

完全なコマンドライン引数が本当に必要な場合は、次のものを使用できます。審査フレームワークを設定し、execveシステムコールルールを設定します。

auditctl -a exit,always -F arch=b64-S execve -k all-commands

ausearchその後、ツールを使用してシステムで実行されているすべてのコマンドを確認できます。

おすすめ記事