Investigating Logs
Investigating Logs
Understanding Logs
Collecting Logs
Log Management
Log Analysis
Windows Logs Analysis
Enable success and failure logging on all
categories
Auditing Windows Event Logs from command
line
Investigating Event logs with PowerShell
Auditing all the logs in the local PC
Auditing log providers
Listing log providers with 'powershell' as a
keyword
Listing events related to windows
powershell
Listing available logs containing given
keyword
Listing events on a specific log path
Finding process related information using a
given keyword about the process
listing application logs from WLMS provider
and generated at the given time
Displaying events logged for processes
initiated network connections.
listing security logs with sam as target
usrname and event id equals to 4724
listing security logs with event id equals to
400
listing logs from log file with event id = 104
and format as list displaying all events
properties
listing logs from log file with event id =
4104 with string 'ScriptBlockText' and
format as list displaying all events
properties
listing logs from log file with event id =13
with string 'enc' in the message field and
format as list displaying all events
properties
filtering events using time range
listing security logs with sam as target
usrname and event id equals to 4799
Listing accounts validation logs in the last
10 days
Auditing accounts logged on/off in the last
two days
Auditing access to file shares, file system,
SAM and registry in the last two days
Auditing the use of privilege
Auditing system changes and integrity
events
Detecting the use of psexec
Investigating Logs with Sysmon and Powershell
Hunting for Metasploit events
Filtering for Network connections
Filtering for Network connections in format
list with maximum quantity of one
Filtering for process access events
specifically lsass.exe
Filtering for Alternate Data Streams events
Filtering for process hollowing events
Investigating IIS logs
Investigating Windows Event Logs with Timeline
explorer
Investigating Windows Event Logs with Sysmon
View
Windows Event IDs
Security
Sysmon Events
Linux Log Analysis
Manual Analysis
Auditing authentication logs
Auditing User login logs in Ubuntu
Auditing samba activity
Auditing cron job logs
Auditing sudo logs
Filtering 404 logs in Apache
Auditing files requested in Apache
View root user command history
View last logins
Network Logs
Logs Centralization
SIEM
Syslog Protocol
Understanding Logs
Premise
Following security best practices, it is typical for a
modern environment to employ log forwarding. Log
forwarding means that the SOC will move or
“forward” logs from the host machine to a central
server or indexer. Even if an attacker can delete logs
from the host machine, they could already be off of
the device and secured.
Log entries are often given a severity level to
categorize and communicate their relative
importance or impact. These severity levels help
prioritize responses, investigations, and actions
based on the criticality of the events. Different
systems might use slightly different severity levels,
but commonly, you can expect to find the following
increasing severity levels: Informational, Warning,
Error, and Critical.
Log Files
Log files are records of events committed to a file in
a list format. They can include all sorts of information
about events that happened at a particular time.
Every device on the network creates log files, thus
giving you a history of what's been happening.
Logs typically contain five headed-up areas. They
are:
Collecting Logs
The process of log collection relies heavily on the
accuracy of your time settings therefore its
recommended to utilize the Network Time Protocol
(NTP) to achieve synchronization and ensure the
integrity of the timeline stored in the logs.
You can do so on Linux system manually by running
the below command
ntpdate pool.ntp.org
cd /etc/rsyslog.d
nano apache.logs
YAML
$FileCreateMode 0644
Restart
Log Analysis
Definition
Log analysis examines and interprets log event data
generated by various data sources (devices,
applications, and systems) to monitor metrics and
identify security incidents.
Log analysis involves several steps that starts with
collecting, parsing, and processing log files to turn
data into actionable objectives. Then analysts would
correlate log data to find links and connections
between events to paint a story of what happened.
Creating a Timeline
A timeline is a chronological representation of the
logged events, ordered based on their occurrence.
Creating a timeline is important to construct the
series of events that eventually led to the security
incident which can aid analysis identify the initial
point compromise and understand the attacker's
tactics, techniques and procedures (TTPs).
Looking for patterns of security incidents
Multiple failed login attempts
Unusually high numbers of failed logins within a
short time may indicate a brute-force attack.
Unusual login times
Login events outside the user's typical access hours
might signal unauthorized access or compromised
accounts.
Geographic anomalies
Login events from IP addresses in countries the user
does not usually access can indicate potential
account compromise or suspicious activity.
In addition, simultaneous logins from different
geographic locations may suggest account sharing
or unauthorized access.
Frequent password changes
Log events indicating that a user's password has
been changed frequently in a short period may
suggest an attempt to hide unauthorized access or
take over an account.
Unusual user-agent strings
In HTTP traffic logs, requests from users with
uncommon user-agent strings that deviate from their
typical browser may indicate automated attacks or
malicious activities.
For example, by default, the Nmap scanner will log a
user agent containing "Nmap Scripting Engine."
The Hydra brute-forcing tool by default, will include "
(Hydra)" in its user-agent. These indicators can be
useful in log files to detect potential malicious
activity.
Attack Patterns and signatures
SQL Injection
When looking for patterns of SQL Injection, we try to
find evidence of SQL queries in the logs such as
UNION SELECT. Sometimes the SQL Payloads may
be URL-encoded, requiring an additional processing
step to identify it efficiently.
XSS
To identify common XSS attack patterns, it is often
helpful to look for log entries with unexpected or
unusual input that includes script tags and event
handlers (onmouseover, onclick, onerror).
Directory Traversal
To identify common traversal attack patterns, look
for traversal sequence characters (../ and ../../) and
indications of access to sensitive files
(/etc/passwd, /etc/shadow).
wevtutil.exe
wevtutil.exe /?
[1]
[2]
Get-WinEvent -FilterHashtable
@{logname=”Microsoft-Windows-
PrintService/Admin”} | fl -property *
Get-WinEvent -FilterHashTable
@{Logname='System';ID='7045'} | where
{$_.Message.contains("PSEXEC")}
Investigating Logs with Sysmon and
Powershell
Hunting for Metasploit events
PS C:\> (Get-WebConfigurationProperty
'/system.applicationHost/sites/siteDef
aults' -Name
'logfile.directory').Value
PS C:\> $LogDirPath =
"C:\inetpub\logs\LogFiles\srvname"
Extracting an IP pattern
.\EvtxECmd.exe -f
'C:\Users\user\Desktop\sysmon.evtx' --
csv 'C:\Users\user\Desktop\' --csvf
sysmon.csv
The above command uses EvtxECmd.exe to perform
the process.
The below figure shows the logs after importing
them to Timeline Explorer
Event ID 4719
Event ID 4739
User created or added
Event ID 4720
User successfully authenticated
Event ID 4625
Account logon
Event ID 4624
Account logoff
Event ID 4634
Process creation
Event ID 4688
Execution blocked due to restrictive policy
Event ID 4100
Member added to a universal security group
Event ID 4104
Member added from a universal security
group
Event 4756
Member removed to a global security group
Event ID 4757
Member removed from a global security group
Event ID 4728
Event ID 4729
Pass The Hash
Passing the hash will generate 2 Event ID 4776
on the Domain Controller, the first event 4776 is
generated during the authentication of the
victim computer, the second event 4776
indicates the validation of the account from the
originating
computer (infected host), when accessing the
target workstation (victim).
Event ID 4776
Event ID 4624 with a Logon Process of
NtLmSSP and/or an Authentication Package of
NTLM.
Account Lockout
Event ID 4625 and/or Event ID 4740.
Windows Security audit log was cleared
Event ID 1102
Log file was cleared
Event ID 104
Windows Event Log service was shut down
Event ID 1100
Powershell script block execution
Event ID 4104
Powershell command invocation
Event ID 4103
Sysmon Events
Event ID 1: Process Creation
Event ID 5: Process Terminated
Event ID 3: Network Connection
Event ID 7: Image Loaded
Event ID 8: CreateRemoteThread [Persistence
operations - process migration]
Event ID 11: File Created
Event ID 12 / 13 / 14: Registry Event
Event ID 15: FileCreateStreamHash
Event ID 22: DNS Event
Event ID 13: Registry Value Set
Event ID 4720: New user created
Event ID 4103 : Powershell logging enabled
Event ID 4732: A member was added to a group
Event ID 4624: Pass The Hash
Linux Log Analysis
var/log/syslog
The syslog file stores all system activity,
including startup activity. Note that this is not the
syslog protocol used to collect log entries from other
systems.
var/log/messages
This log contains a wide variety of general
system messages. It includes some messages
logged during startup, some messages related to
mail, the kernel, and messages related to
authentication.
var/log/boot.log
This log includes entries created when the
system boots.
var/log/auth.log
The authentication log contains information
related to successful and unsuccessful logins.
var/log/faillog
This log contains information on failed login
attempts. It can be viewed using the faillog
command.
/var/log/kern.log
The kernel log contains information logged
by the system kernel, which is the central part of the
Linux operating system.
/var/log/httpd/
If the system is configured as an Apache web
server, you can view access and error logs within
this directory.
Web Servers:
Nginx:
Access
Logs: /var/log/nginx/access.log
Error
Logs: /var/log/nginx/error.log
Apache:
Access
Logs: /var/log/apache2/access.log
Error
Logs: /var/log/apache2/error.log
Databases:
MySQL:
Error
Logs: /var/log/mysql/error.log
PostgreSQL:
Error and Activity
Logs: /var/log/postgresql/postgres
ql-{version}-main.log
Web Applications:
PHP:
Error Logs: /var/log/php/error.log
Operating Systems:
Linux:
General System
Logs: /var/log/syslog
Authentication
Logs: /var/log/auth.log
Firewalls and IDS/IPS:
iptables:
Firewall Logs: /var/log/iptables.log
Snort:
Snort Logs: /var/log/snort/
Manual Analysis
Auditing authentication logs
tail /var/
Auditing samba activity
# cat /root/.*history
last
Network Logs
Network logs record traffic on the network. These
logs are on a variety of devices such as routers,
firewalls, web servers, and network intrusion
detection/prevention systems. You can typically
manipulate these devices to log specific information,
such as logging all traffic that the device passes, all
traffic that the device blocks, or both. These logs are
useful when troubleshooting connectivity issues and
when identifying potential
intrusions or attacks.
Logs Centralization
SIEM
Definition
A security information and event management (SIEM)
system provides a centralized solution for collecting,
analyzing, and managing data from multiple sources.
How it works
Syslog Protocol
Definition
The syslog protocol specifies a general log entry
format and the details on how to transport log
entries. You can deploy a centralized syslog server
to collect syslog entries from a variety of devices in
the network, similar to how a SIEM server collects log
entries.
How it works
Any systems sending syslog messages are
originators. They send syslog log entries to a
collector (a syslog server). The collector can receive
messages from external devices or services and
applications on the same system. For example, Linux
systems include the syslogd daemon, which is the
service that handles the syslog messages. It collects
the entries and processes them based on entries in
the /etc/syslog.conf file. Many syslog messages
are routed to the /var/syslog file.
Syslog Software Tools For Linux