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: 20170829 19:23:12.160 - 20170829 19:50:57.654

Selected time forreport: 20170829 19:23:12 - 20170829 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 authentications1,因爲我在剛纔使用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操作!






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章