내 라이브러리를 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그런 다음 도구를 사용하여 시스템에서 실행 중인 모든 명령을 검사 할 수 있습니다 .

관련 정보