Adversaries may clear system logs to hide evidence of an intrusion. macOS and Linux both keep track of system or user-initiated actions via system logs. The majority of native system logging is stored under the/var/log/
directory. Subfolders in this directory categorize logs by their related functions, such as:(Citation: Linux Logs) */var/log/messages:
: General and system-related messages */var/log/secure
or/var/log/auth.log
: Authentication logs */var/log/utmp
or/var/log/wtmp
: Login records */var/log/kern.log
: Kernel logs */var/log/cron.log
: Crond logs */var/log/maillog
: Mail server logs */var/log/httpd/
: Web server access and error logs
Atomic Test #3 - Delete log files using built-in log utility
Atomic Test #4 - Truncate system log files via truncate utility
Atomic Test #5 - Truncate system log files via truncate utility (freebsd)
Atomic Test #6 - Delete log files via cat utility by appending /dev/null or /dev/zero
Atomic Test #7 - Delete log files via cat utility by appending /dev/null or /dev/zero (freebsd)
Atomic Test #9 - Overwrite macOS system log via echo utility
Atomic Test #10 - Overwrite FreeBSD system log via echo utility
Atomic Test #12 - Delete system log files via unlink utility
Atomic Test #13 - Delete system log files via unlink utility (freebsd)
Atomic Test #14 - Delete system log files using shred utility
Atomic Test #18 - Delete system journal logs via rm and journalctl utilities
Delete system and audit logs
Supported Platforms: macOS, Linux
auto_generated_guid: 989cc1b1-3642-4260-a809-54f9dd559683
| Name | Description | Type | Default Value | |——|————-|——|—————| | syslog_path | path of syslog file to delete. On macos it’s /var/log/system.log, on linux, it’s /var/log/syslog. Also note for File events, that on macos, /var/ is a link to /private/var/. | string | /var/log/system.log| | macos_audit_path | path of audit file to delete | string | /var/audit/20220725213300.202208110700021|
1
sh
! Elevation Required (e.g. root or admin)1
2
sudo rm -rf #{syslog_path}
if [ -d /var/audit ] ; then sudo rm -rf #{macos_audit_path} ; fi
1
sh
!1
if [ -d /var/audit ] ; then stat #{macos_audit_path} ; fi && stat #{syslog_path}
1
2
touch #{syslog_path}
if [ -d /var/audit ] ; then touch #{macos_audit_path} ; fi
Delete messages and security logs
Supported Platforms: Linux
auto_generated_guid: bd8ccc45-d632-481e-b7cf-c467627d68f9
1
sh
! Elevation Required (e.g. root or admin)1
2
rm -rf /var/log/messages
rm -rf /var/log/security
This test deletes main log datastore, inflight log data, time-to-live data(TTL), fault and error content
Supported Platforms: macOS
auto_generated_guid: 653d39cd-bae7-499a-898c-9fb96b8b5cd1
1
sh
! Elevation Required (e.g. root or admin)1
2
sudo log erase --all
sudo log erase --ttl #Deletes only time-to-live log content
This test truncates the system log files using the truncate utility with (-s 0) parameter which sets file size to zero, thus emptying the file content
Supported Platforms: macOS
auto_generated_guid: 6290f8a8-8ee9-4661-b9cf-390031bf6973
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path of system log to delete. | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
sudo truncate -s 0 #{system_log_path} #size parameter shorthand
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
This test truncates the system log files using the truncate utility with (-s 0 or –size=0) parameter which sets file size to zero, thus emptying the file content
Supported Platforms: Linux
auto_generated_guid: 14033063-ee04-4eaf-8f5d-ba07ca7a097c
1
sh
! Elevation Required (e.g. root or admin)1
2
truncate -s 0 /var/log/messages #size parameter shorthand
truncate --size=0 /var/log/security #size parameter
The first sub-test truncates the log file to zero bytes via /dev/null and the second sub-test fills the log file with null bytes(zeroes) via /dev/zero, using cat utility
Supported Platforms: macOS
auto_generated_guid: c23bdb88-928d-493e-b46d-df2906a50941
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path of system log to delete. | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
2
sudo cat /dev/null > #{system_log_path} #truncating the file to zero bytes
sudo dd if=/dev/zero bs=1000 count=5 of=#{system_log_path} #log file filled with null bytes(zeros)
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
The first sub-test truncates the log file to zero bytes via /dev/null and the second sub-test fills the log file with null bytes(zeroes) via /dev/zero, using cat utility
Supported Platforms: Linux
auto_generated_guid: 369878c6-fb04-48d6-8fc2-da9d97b3e054
1
sh
! Elevation Required (e.g. root or admin)1
2
cat /dev/null > /var/log/messages #truncating the file to zero bytes
cat /dev/zero > /var/lol/messages #log file filled with null bytes(zeros)
This test finds and deletes the system log files within /var/log/ directory using various executions(rm, shred, unlink)
Supported Platforms: macOS
auto_generated_guid: bc8eeb4a-cc3e-45ec-aa6e-41e973da2558
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_name1 | name or prefix of system log to delete. | string | system.log| | system_log_name2 | name or prefix of system log to delete. | string | system.log.97.gz| | system_log_name3 | name or prefix of system log to delete. | string | system.log.98.gz|
1
sh
! Elevation Required (e.g. root or admin)1
2
3
sudo find /var/log -name '#{system_log_name1}*' -exec rm {} \; #using "rm" execution
sudo find /var/log -name "#{system_log_name2}*" -exec shred -u -z -n 3 {} \; #using "shred" execution
sudo find /var/log -name "#{system_log_name3}*" -exec unlink {} \; #using "unlink" execution
1
sh
!1
stat /var/log/#{system_log_name1} /var/log/#{system_log_name2} /var/log/#{system_log_name3}
1
touch /var/log/#{system_log_name1} /var/log/#{system_log_name2} /var/log/#{system_log_name3}
This test overwrites the contents of system log file with an empty string using echo utility
Supported Platforms: macOS
auto_generated_guid: 0208ea60-98f1-4e8c-8052-930dce8f742c
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
sudo echo '' > #{system_log_path}
This test overwrites the contents of system log file with an empty string using echo utility
Supported Platforms: Linux
auto_generated_guid: 11cb8ee1-97fb-4960-8587-69b8388ee9d9
1
sh
! Elevation Required (e.g. root or admin)1
echo '' > /var/log/messages
This test reads real-time system log file and writes empty string to it, thus clearing the log file without tampering with the logging process
Supported Platforms: macOS
auto_generated_guid: 848e43b3-4c0a-4e4c-b4c9-d1e8cea9651c
1
sh
! Elevation Required (e.g. root or admin)1
sudo log -f /var/log/system.log | : > /var/log/system.log
This test deletes the system log file using unlink utility
Supported Platforms: macOS
auto_generated_guid: 03013b4b-01db-437d-909b-1fdaa5010ee8
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
sudo unlink #{system_log_path}
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
This test deletes the messages log file using unlink utility
Supported Platforms: Linux
auto_generated_guid: 45ad4abd-19bd-4c5f-a687-41f3eee8d8c2
1
sh
! Elevation Required (e.g. root or admin)1
unlink /var/log/messages
This test overwrites the contents of the log file with zero bytes(-z) using three passes(-n 3) of data, and then delete the file(-u) securely
Supported Platforms: macOS
auto_generated_guid: 86f0e4d5-3ca7-45fb-829d-4eda32b232bb
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
sudo shred -u -z -n 3 #{system_log_path}
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
This test securely deletes the system log files individually and recursively using the srm utility. Install srm using Homebrew with the command: brew install khell/homebrew-srm/srm Refer: https://github.com/khell/homebrew-srm/issues/1 for installation
Supported Platforms: macOS
auto_generated_guid: b0768a5e-0f32-4e75-ae5b-d036edcf96b6
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log| | system_log_folder | path to log parent folder | string | /var/log/|
1
sh
! Elevation Required (e.g. root or admin)1
2
sudo srm #{system_log_path} #system log file deletion
sudo srm -r #{system_log_folder} #recursive deletion of log files
1
sh
!1
stat #{system_log_path} #{system_log_folder}
1
mkdir -p #{system_log_folder} && touch #{system_log_path} #{system_log_folder}/system.log
This test deletes the system log file using osascript via “do shell script”(sh/bash by default) which in-turn spawns rm utility, requires admin privileges
Supported Platforms: macOS
auto_generated_guid: 810a465f-cd4f-47bc-b43e-d2de3b033ecc
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
osascript -e 'do shell script "rm #{system_log_path}" with administrator privileges'
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
This test deletes the system log file using applescript using osascript via Finder application Note: The user may be prompted to grant access to the Finder application before the command can be executed successfully as part of TCC(Transparency, Consent, and Control) Framework. Refer: https://www.rainforestqa.com/blog/macos-tcc-db-deep-dive
Supported Platforms: macOS
auto_generated_guid: e62f8694-cbc7-468f-862c-b10cd07e1757
| Name | Description | Type | Default Value | |——|————-|——|—————| | system_log_path | path to system.log | string | /var/log/system.log|
1
sh
! Elevation Required (e.g. root or admin)1
osascript -e 'tell application "Finder" to delete POSIX file "#{system_log_path}"'
1
sh
!1
stat #{system_log_path}
1
touch #{system_log_path}
The first sub-test deletes the journal files using rm utility in the “/var/log/journal/” directory and the second sub-test clears the journal by modifiying time period of logs that should be retained to zero.
Supported Platforms: Linux
auto_generated_guid: ca50dd85-81ff-48ca-92e1-61f119cb1dcf
| Name | Description | Type | Default Value | |——|————-|——|—————| | journal_folder | path to journal logs | string | /var/log/journal|
1
sh
! Elevation Required (e.g. root or admin)1
2
sudo rm #{journal_folder}/* #physically deletes the journal files, and not just their content
sudo journalctl --vacuum-time=0 #clears the journal while still keeping the journal files in place
1
sh
!1
stat #{journal_folder}
1
mkdir -p #{journal_folder} && touch #{journal_folder}/T1070_002.journal
This test overwrites the Linux mail spool of a specified user. This technique was used by threat actor Rocke during the exploitation of Linux web servers.
Supported Platforms: Linux
auto_generated_guid: 1602ff76-ed7f-4c94-b550-2f727b4782d4
| Name | Description | Type | Default Value | |——|————-|——|—————| | username | Username of mail spool | string | root|
1
bash
! Elevation Required (e.g. root or admin)1
echo 0> /var/spool/mail/#{username}
1
sh
!1
stat /var/spool/mail/#{username}
1
touch /var/spool/mail/#{username}
This test overwrites the specified log. This technique was used by threat actor Rocke during the exploitation of Linux web servers.
Supported Platforms: Linux
auto_generated_guid: d304b2dc-90b4-4465-a650-16ddd503f7b5
| Name | Description | Type | Default Value | |——|————-|——|—————| | log_path | Path of specified log | path | /var/log/secure|
1
bash
! Elevation Required (e.g. root or admin)1
echo 0> #{log_path}
1
if [ "/var/log/secure" != "#{log_path}" ] ; then rm -f #{log_path} ; fi