linux auditd審計的簡單使用和理解


Linux審計主要用於查看系統改動的信息,如系統密碼修改,用戶的新建,主要用於保障系統的安全,下面簡單介紹審計如何使用

 

1啟動審計進程:

[tommy@xie-testlog]$ sudo service auditd start

 

2查看當前審計規則

[tommy@xie-testlog]$ sudo auditctl -l

[sudo] passwordfor tommy:

LIST_RULES:exit,always watch=/etc/passwd perm=rwxa

 

我這里已經新建了一條規則,默認是no rules

 

3新建臨時規則

[tommy@xie-testlog]$ sudo auditctl -w /etc/passwd -p rxwa

參數說明

-w :審計監視的路徑

-p:目錄或者文件的權限 ,rxwa分別是讀、執行、寫、屬性

在輸入命令

[tommy@xie-testlog]$ sudo auditctl -l

就能看到添加的一條規則,這里是對/etc/passwd這個密碼文件的監視,如果這個文件發生修改那么就會在審計日志中被記錄下來

 

說明:sudo auditctl -w /etc/passwd -p rxwa這條命令只是新建一條臨時規則,如果服務重啟或者系統重啟,那么這條命令會被清空,如果要讓其成為永久的規則,必須修改audit.rules文件,如下

[tommy@xie-testlog]$ sudo vi /etc/audit/audit.rules

[sudo] passwordfor tommy:

 

# This filecontains the auditctl rules that are loaded

 

# whenever theaudit daemon is started via the initscripts.

 

# The rules aresimply the parameters that would be passed

 

# to auditctl.

 

# First rule -delete all

 

-D

# Increase thebuffers to survive stress events.

 

# Make thisbigger for busy systems

-b 320

# Feel free toadd below this line. See auditctl man page

-w /etc/passwd -p rwxa

 

上面紅色的語句就是添加的規則

 

4下面來測試passwd文件改動的審計信息

新建一個用戶和設置密碼

[tommy@xie-testlog]$ sudo useradd lily

[tommy@xie-testlog]$ sudo passwd lily

輸入用戶密碼:

 

再次輸入密碼:

 

然后通過ausearch工具查看審計日志,通過useradd篩選出剛才添加用戶的審計信息

 

[tommy@xie-test log]$ sudo ausearch -f/etc/passwd | grep useradd

 

type=SYSCALLmsg=audit(1504005888.886:16996): arch=c000003e syscall=2 success=yes exit=4a0=7fceac18869a a1=80000 a2=1b6 a3=0 items=3 ppid=27342 pid=27343 auid=503uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=2416comm="useradd" exe="/usr/sbin/useradd" key=(null)

type=SYSCALLmsg=audit(1504005888.887:16997): arch=c000003e syscall=2 success=yes exit=5a0=7fceb3434ce0 a1=2 a2=1b6 a3=0 items=3 ppid=27342 pid=27343 auid=503 uid=0gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=2416 comm="useradd" exe="/usr/sbin/useradd"key=(null)

type=SYSCALLmsg=audit(1504005888.899:16998): arch=c000003e syscall=2 success=yes exit=9a0=7fceac18869a a1=80000 a2=1b6 a3=0 items=3 ppid=27342 pid=27343 auid=503uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=2416comm="useradd" exe="/usr/sbin/useradd" key=(null)

type=SYSCALLmsg=audit(1504005888.900:17000): arch=c000003e syscall=2 success=yes exit=10a0=7fceac18869a a1=80000 a2=1b6 a3=0 items=3 ppid=27342 pid=27343 auid=503uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=2416comm="useradd" exe="/usr/sbin/useradd" key=(null)

type=SYSCALLmsg=audit(1504005889.008:17004): arch=c000003e syscall=82 success=yes exit=0a0=7fff8135ec40 a1=7fceb3434ce0 a2=7fff8135eb00 a3=0 items=13 ppid=27342pid=27343 auid=503 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0tty=pts1 ses=2416 comm="useradd" exe="/usr/sbin/useradd"key=(null)

 

參數說明:

time :審計時間。

•name :審計對象

•cwd :當前路徑

•syscall :相關的系統調用

•auid :審計用戶ID

•uid和 gid :訪問文件的用戶ID和用戶組ID

•comm :用戶訪問文件的命令

•exe :上面命令的可執行文件路徑

 

通過aureport查看生成的審計報告

[tommy@xie-testlog]$ sudo aureport

Summary Report

 

======================

 

Range of time inlogs: 2017年08月29日 19:23:12.160 - 2017年08月29日 19:50:57.654

Selected time forreport: 2017年08月29日 19:23:12 - 2017年08月29日 19:50:57.654

Number ofchanges in configuration: 3

Number ofchanges to accounts, groups, or roles: 6

Number oflogins: 0

Number of failedlogins: 0

Number ofauthentications: 3

Number of failedauthentications: 1

Number of users:3

Number ofterminals: 5

Number of hostnames: 1

Number ofexecutables: 9

Number of files:6

Number of AVC's:0

Number of MACevents: 0

Number of failedsyscalls: 0

Number ofanomaly events: 0

Number ofresponses to anomaly events: 0

Number of cryptoevents: 0

Number of keys:0

Number ofprocess IDs: 47

Number ofevents: 505

 

這里看到了錯誤的認證fail authentications是1,因為我在剛才使用sudo命令的時候提示輸入用戶密碼輸入錯了一次,所以被記錄了下來

 

注意:auditd的審計日志是在/var/log/audit/audit.log這里,如果設置的rules較多,日志會很大,所以要定期刪除日志,在刪除日志的時候注意要重啟auditd服務

對auditd.conf文件的分析

 

這里說明一下幾個關鍵的參數:

log_file:審計日志文件的位置

num_logs:審計日志文件的數量

max_log_file:審計日志文件的容量

max_log_file_action:當審計日志文件超過容量大小時候的操作,這里是rotate,會循環原來的日志文件

 

對audit.log日志文件的分析

 

msg=audit后面那串數字冒號前面的是linux系統的時間,我們需要用工具把它轉換為我們熟悉的時間格式,這里使用這個網站的工具,輸入這個時間就能看到

網址:tool.chinaz.com/Tools/unixtime.aspx

 

輸入后可以看到相應的時間

addr:就是進行上述操作(sshd)的主機地址

 

2018-05-22補充說明

 

查看audit.log的時候發覺日志很多,能找到對應操作如useradd操作,但是卻碰到一個難題,並不知道這個操作對應是哪個IP的,探討了一天,下面以/etc/passwd這個文件的審計為例子,在此對這個問題進行分析:

為了方便觀察,我用工具把/var/log/audit.log這個文件先拷出來,然后用notepad++把審計日志打開,因為在一開始我使用了useradd lily 和passwd等操作,我首先輸入comm快速定位到有useradd或者passwd操作命令記錄的日志位置

 

 

可以看到我畫紅線的部分,已經定位到useradd這個增加用戶的操作記錄,然后在這條記錄的左手面,可以找到“ppid”這個字

眼,注意,這個是父進程,非常關鍵,這個就是對應那個ip登錄的重要信息,如下圖

 

 

可以看到我畫紅線的ppid是15111

然后我們根據這個15111,再在文件中查看15111這個數字,知道找到有詳細的IP出現的位置,有驚喜發現!

 

 

可以看到我找到了user id=15111,ip為192.168.10.43這個IP主機,這個user id和剛才的ppid是對應的,所以就說明是

192.168.10.43這個IP的主機進行了剛才的useradd操作!


---------------------
版權聲明:本文為CSDN博主「丟你劉某」的原創文章,遵循CC 4.0 by-sa版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/qq_26614295/article/details/77675912

 

 

經測試 如果監控/root/a.txt ,必須使用/root/a.txt為路徑 才能監控上


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM