
커널 함수 실행 시간 변화 분석을 통한 루트킷 파일 숨김 활동 탐지
이 저장소는 루트킷이 파일을 숨길 때 조작하는 커널 함수의 시간 측정값을 수집하는 코드와, 커널 함수 실행 시간의 변화를 분석하는 반지도 학습 기반 탐지 방법을 포함합니다. 이 구현은 오픈소스 루트킷 CARAXES에 의존하며, 이 루트킷은 filldir 함수를 래핑하여 ls 명령 실행 시 파일 열거 결과를 조작합니다. eBPF 프로브를 사용하여 getdents 시스템 콜( filldir 포함)의 여러 함수에서 시간 측정값을 수집합니다. 탐지에는 통계적 검정에 기반한 간단한 머신러닝 모델을 적용합니다. 데이터 수집 및 이상 탐지 메커니즘에 대한 자세한 설명은 다음 출판물을 참조하십시오. 이 저장소의 리소스를 사용하는 경우 다음 출판물을 인용해 주십시오:
다음 단계는 루트킷을 설정하고 커널 함수에서 시간 측정값을 수집하는 방법을 설명합니다. 이상 탐지만 관심이 있고 공개 데이터셋을 사용하려는 경우 이 섹션을 건너뛸 수 있습니다.
루트킷과 프로빙은 Linux 커널 5.15-6.11 및 Python 3.10에서 테스트되었습니다. 도구를 실행하려면 이 저장소를 다운로드하고 루트킷 및 프로빙 메커니즘 실행에 필요한 다음 종속 항목을 설치하십시오.
ubuntu@ubuntu:~$ git clone https://github.com/ait-aecid/rootkit-detection-ebpf-time-trace.git
ubuntu@ubuntu:~$ cd rootkit-detection-ebpf-time-trace
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ sudo apt update
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ sudo apt install python3-bpfcc make gcc flex bison python3-pip linux-headers-$(uname -r)
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ pip install -r requirements.txt
일부 시나리오에는 추가 리소스가 필요합니다. 특히 ls-basic 시나리오는 ls-basic 스크립트를 컴파일해야 하고, 시스템 부하 시나리오는 stress-ng를 설치해야 합니다. 이러한 시나리오를 사용하지 않으려면 다음 종속 항목을 건너뛸 수 있습니다.
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ gcc -o ls-basic ls-basic.c
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ sudo apt install stress-ng
다음 명령은 필수입니다. 루트킷은 기본적으로 getdents 시스템 콜을 조작하지만, 현재 프로빙은 filldir 조작만 지원합니다. 루트킷을 다운로드하고, 이 저장소에 제공된 파일로 hooks.h를 교체한 후(이렇게 하면 getdents 대신 filldir이 후킹됨), 루트킷을 컴파일하십시오.
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ cd ..
ubuntu@ubuntu:~$ git clone https://github.com/ait-aecid/caraxes.git
ubuntu@ubuntu:~$ cd caraxes/
ubuntu@ubuntu:~/caraxes$ cp ../rootkit-detection-ebpf-time-trace/hooks.h .
ubuntu@ubuntu:~/caraxes$ sudo make
루트킷 설치에 문제가 있거나 예상대로 작동하는지 테스트하려면 CARAXES GitHub 페이지의 ReadMe를 확인하십시오.
그런 다음 이 저장소로 돌아와서 linux.py를 열고 변수 KERNEL_OBJECT_PATH를 방금 복제한 caraxes 폴더를 가리키도록 편집하십시오. 기본 경로는 "/home/ubuntu/caraxes/"입니다.
ubuntu@ubuntu:~/caraxes$ cd ../rootkit-detection-ebpf-time-trace
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ vim linux.py
이제 프로빙 메커니즘을 실행할 준비가 되었습니다. 이 메커니즘은 자동으로 커널에 프로브를 주입하고, 루트킷을 시작하며, 시간 측정 데이터를 파일에 저장하고, 루트킷을 중지합니다. 시스템 콜을 트리거하기 위해 스크립트는 숨길 파일이 있는 디렉터리를 만들고 프로브를 폴링하면서 ls를 100회 실행합니다(-i 플래그로 수정 가능). 이 스크립트는 루트킷이 있는 경우(--rootkit 플래그), 루트킷이 없는 경우(--normal 플래그) 또는 둘 다 측정을 수집할 수 있으며 여러 시나리오를 지원합니다. 다음 명령으로 기본 시나리오를 실행하십시오:
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ sudo python3 probing.py --normal --rootkit
compiling eBPF probes...
probes compiled!
attached bpf probes:
iterate_dir-enter
iterate_dir-return
dcache_readdir-enter
dcache_readdir-return
filldir64-enter
filldir64-return
verify_dirent_name-enter
verify_dirent_name-return
touch_atime-enter
touch_atime-return
Running experiment with ls for 100 times.
Iteration 0...
detection_PID: 70133
Iteration 1...
detection_PID: 70134
...
Iteration 99...
detection_PID: 70338
polled 40 times!
done with the "rootkit version"
Experiment finished, saving output.
Saved data to events/events_2025-01-17T09:59:52.183801_rootkit.json.gz
412K events/events_2025-01-17T09:59:52.183801_rootkit.json.gz
측정값은 events 디렉터리에 저장됩니다. python3 probing.py -h로 도움말 페이지를 확인하여 다른 시나리오(예: ls 대신 ls-basic 사용 또는 시스템 부하 시뮬레이션)에서 데이터 수집을 설정하고 다른 실행에 이름을 할당(--description)할 수 있는 다른 매개변수를 알아보십시오. 매개변수화된 명령어를 보려면 repeat_seq.sh를 확인하십시오. 실제로 이 스크립트를 사용하여 공개 데이터셋을 수집했습니다. 참고로 getdents 시스템 콜에서 사용 가능한 커널 함수 중 일부만 고려합니다. 프로빙 메커니즘이 프로브를 연결할 함수를 지정하려면 probing.py를 열고 파일 시작 부분의 probe_points 목록에서 함수 이름을 추가하거나 제거하십시오.
이상 탐지 알고리즘을 실행하려면 python 종속 항목만 설치하면 됩니다. 이전 단계에서 아직 설치하지 않은 경우 다음 명령을 실행하여 pip로 요구 사항을 설치하십시오.
ubuntu@ubuntu:~$ git clone https://github.com/ait-aecid/rootkit-detection-ebpf-time-trace.git
ubuntu@ubuntu:~$ cd rootkit-detection-ebpf-time-trace
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ pip install -r requirements.txt
그런 다음 Zenodo에서 제공하는 데이터셋을 다운로드하여 압축을 푸십시오. 이전 단계에서 직접 데이터를 생성했고 이를 사용하려면 이 단계를 건너뛰십시오.
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ wget https://zenodo.org/records/14679675/files/events.zip
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ unzip events.zip
이제 다음과 같이 이상 탐지를 실행할 준비가 되었습니다. 측정 데이터가 포함된 디렉터리(-d), 훈련에 사용할 정상 데이터의 비율(-t), 작동 모드(-m) 및 그룹화 함수(-g)를 지정하십시오. 스크립트는 지정된 디렉터리에서 모든 파일을 로드하고, 훈련 및 테스트 데이터로 분할(출력에 요약), 탐지 메트릭을 계산 및 출력, 혼동 행렬을 플롯합니다.
ubuntu@ubuntu:~/rootkit-detection-ebpf-time-trace$ python3 evaluate.py -d events -t 0.333 -m offline -g fun
100%|█████████████████████████████████████████████| 1250/1250 [02:47<00:00, 7.45it/s]
Processed all files from events
Normal batches: 750
Normal batches for training: 250
default: 50
file_count: 50
system_load: 50
ls_basic: 50
filename_length: 50
Normal batches for testing: 500
default: 100
file_count: 100
system_load: 100
ls_basic: 100
filename_length: 100
Anomalous batches: 500
default: 100
file_count: 100
system_load: 100
ls_basic: 100
filename_length: 100
Results (Run 1)
Threshold=3.5111917342151415e-16
Time=0.0027740001678466797
TP=499
FP=9
TN=491
FN=1
TPR=R=0.998
FPR=0.018
TNR=0.982
P=0.9822834645669292
F1=0.9900793650793651
ACC=0.99
MCC=0.9801254640896192
Confusion Matrix (Run 1)
Predicted
default file_count system_load ls_basic filename_length
Pos Neg Pos Neg Pos Neg Pos Neg Pos Neg
100 0 100 0 100 0 100 0 100 0 Pos - Actual default
3 97 100 0 99 1 100 0 2 98 Neg - Actual default
100 0 100 0 100 0 100 0 100 0 Pos - Actual file_count
100 0 0 100 100 0 100 0 100 0 Neg - Actual file_count
100 0 100 0 100 0 100 0 100 0 Pos - Actual system_load
100 0 100 0 4 96 100 0 100 0 Neg - Actual system_load
100 0 100 0 100 0 99 1 100 0 Pos - Actual ls_basic
100 0 100 0 100 0 2 98 100 0 Neg - Actual ls_basic
99 1 100 0 100 0 100 0 100 0 Pos - Actual filename_length
3 97 100 0 99 1 100 0 0 100 Neg - Actual filename_length
python3 evaluate.py -h로 매뉴얼을 확인하여 이 스크립트의 사용 가능한 매개변수에 대해 자세히 알아보십시오. 또한 demo.sh를 살펴보면 논문의 평가에 사용된 매개변수화된 명령어를 볼 수 있습니다.
이 저장소의 리소스를 사용하는 경우 다음 출판물을 인용해 주십시오: