![Linux 시작 중에 사용된 모든 파일을 나열하는 방법](https://linux55.com/image/3704/Linux%20%EC%8B%9C%EC%9E%91%20%EC%A4%91%EC%97%90%20%EC%82%AC%EC%9A%A9%EB%90%9C%20%EB%AA%A8%EB%93%A0%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EB%82%98%EC%97%B4%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
Linux 부팅 프로세스 중에 사용되는 파일 목록을 얻고 싶습니다. 우리는 RHEL 6.4를 기반으로 보호된 엔터프라이즈 시스템을 개발하고 있습니다. 지정된 파일의 무결성은 특수 하드웨어로 검사됩니다.
따라서 문제는 이러한 파일 목록을 얻는 방법입니다(다양한 부팅 서비스 및 데몬의 종속성이 해결됨).
답변1
설정감사 하위 시스템에 대한 통화를 녹음하세요 open
.
auditctl -a exit,always -S open,openat,creat,execve
/sbin/init
기본 시스템이 부팅될 때(실제 루트 파일 시스템에서) 규칙이 적용되도록 initramfs에서 이 작업을 수행합니다.
귀하가 제안한 내용은 일반적인 설정에 대한 실제 보안을 초래하지 않습니다. 이러한 파일을 다른 버전으로 교체할 수 있는 사람은 누구나 루트 액세스 권한을 가지며 로깅 시스템에 잘못된 데이터를 제공할 수도 있습니다.
부트 미디어가 외부적으로 보호되는 경우 루트는 이를 수정할 수 없으며(예: 읽기 전용이거나 보안 부트 로더의 독점적 제어를 받기 때문에) 커널 모듈 로드가 차단된 경우 올바르게 수행되면 측정 파일 신뢰할 수 있습니다. 그러나 이러한 조치로 수행하는 작업이 참조 값과 비교하는 것뿐이라면 이는 무결성 보호 루트 파일 시스템을 사용하는 것보다 더 어렵고(예: 실제로 dmcrypt에서 Trusted Grub을 부트로더로 사용) 효율성이 떨어집니다.
답변2
좋은 시작점은 시작하려는 런레벨을 /etc/rci.d
나타내는 숫자입니다. i
예를 들어 서버가 헤드리스인 경우 i
일반적으로 3입니다. 아래를 보면 /etc/rc3.d
런레벨 3으로 부팅할 때 어떤 서비스가 시작되는지 확인할 수 있습니다.
답변3
atime
커널에서 루트 및 부팅 파일 시스템이 활성화되어 있는지(또는 설정되지 않았는지 ) 확인한 noatime
다음 부팅한 후 이를 사용하여 stat
각 파일의 액세스 시간을 확인하고 부팅 중에 어떤 파일에 액세스했는지 확인할 수 있습니다.
답변4
RHEL의 지원 덕분에 우리는 명확한 해결책을 찾았습니다. systemtap 커널 모듈의 사용을 기반으로 합니다. 에서 인용여기링크 실패를 방지하기 위해. 모든 제안에 다시 한번 감사드립니다 :)
systemtap이 init 스크립트 이전에 시작되어 시작 프로세스를 추적할 수 있다는 것은 상상조차 할 수 없습니다. 정말 고마워요빨간 모자 지원하다그리고 개인적으로 Pushpendra Chavan에게 이 완벽한 도구에 대한 도움을 요청했습니다(불행히도 이 방법이 정확히 어느 개발자의 것인지는 알 수 없습니다. 그렇지 않으면 애초에 그들을 신뢰했을 것입니다).
따라서 두 가지 간단한 스크립트를 만들어야 합니다.
bootinit.sh
:
#!/bin/sh
# Use tmpfs to collect data
/bin/echo "Mounting tmpfs to /tmp/stap/data"
/bin/mount -n -t tmpfs -o size=40M none /tmp/stap/data
# Start systemtap daemon & probe
/bin/echo "Loading bootprobe2.ko in the background. Pid is :"
/usr/bin/staprun \
/root/bootprobe2.ko \
-o /root/bootprobe2.log -D
# Give daemon time to start collecting...
/bin/echo "Sleeping a bit.."
sleep 5
# Hand off to real init
/bin/echo "Starting."
exec /sbin/init 3
그리고 bootprobe2.1.stp
임베디드 systemtap 스크립트 언어로 작성되었습니다:
global ident
function get_usertime:long() {
return task_utime() + @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->signal->utime;
}
function get_systime:long() {
return task_stime() + @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->signal->stime;
}
function timestamp() {
return sprintf("%d %s", gettimeofday_s(), ident[pid()])
}
function proc() {
return sprintf("%d \(%s\)", pid(), execname())
}
function push(pid, ppid) {
ident[ppid] = indent(1)
ident[pid] = sprintf("%s", ident[ppid])
}
function pop(pid) {
delete ident[pid]
}
probe syscall.fork.return {
ret = $return
printf("%s %s forks %d \n", timestamp(), proc(), ret)
push(ret, pid())
}
probe syscall.execve {
printf("%s %s execs %s \n", timestamp(), proc(), filename)
}
probe syscall.open {
if ($flags & 1) {
printf("%s %s writes %s \n", timestamp(), proc(), filename)
} else {
printf("%s %s reads %s \n", timestamp(), proc(), filename)
}
}
probe syscall.exit {
printf("%s %s exit with user %d sys %d \n", timestamp(), proc(), get_usertime(), get_systime())
pop(pid())
}
<linux sched.h=""><linux sched.h="">
</linux></linux>
시작하는 동안 액세스한 파일 목록을 systemtap 로그 형식으로 받으려면 다음을 구현해야 합니다.
올바른 이름의 버전 systemtap
과 kernel debuginfo
패키지를 다운로드하여 설치합니다.이 링크, 하지만 다음을 사용하는 것이 좋습니다이것CentOS를 사용하는 경우)
생성 /tmp/stap
및/tmp/stap/data
mkdir -p /tmp/stap/data
bootprobe2.1.stp
and bootinit.sh
를 넣고 /root
실행 가능하게 만듭니다: chmod +x /root/boot*
5가 기본 실행 수준인 경우 bootinit.sh
"exec /sbin/init 3"을 편집하여 "exec /sbin/init 5"로 변경합니다.
bootprobe2.stp에서 .ko 모듈 생성
cd /root
stap bootprobe2.1.stp -m bootprobe2 -p4
재시작.
일시 정지 grub
(Esc 또는 Shift 누르기)하고 기본 코어에서 "a"를 누르십시오. 커널 줄 끝에 다음을 입력하고 Enter를 누릅니다.
init=/root/bootinit.sh,
정상적인 시작이 재개됩니다. 로그인하면 kill
프로세스가 디렉터리 에서 stapio
복사되어 제거됩니다.bootprobe2.log
tmpfs
/tmp/stap/data
killall stapio
cp /tmp/stap/data/bootprobe2.log /tmp/stap/
umount /tmp/stap/data
이제 파일 /tmp/stap/bootprobe2.log
file을 확인하여 시작 중에 읽은 모든 파일 목록을 확인하세요.