# Artefacts overview

### General

| Name                                    | Type | Description                                                                                                                                                                                | Information / interpretation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Location                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Tool(s)      |                                                      |   |
| --------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ | ---------------------------------------------------- | - |
| Audit `auditd` framework (`audit` logs) | -    | Non default, can be configured to log multiple types of operations, such as authentication successes or failures, process executions, file accesses, user commands executed in a TTY, etc. | <p>Each record / log entry contain a <code>msg</code> field, composed of a timestamp and an unique ID. Multiple records generated as part of the same Auditd event can share the same <code>msg</code> field. For example, <code>cat /etc/passwd</code> can generate <code>SYSCALL</code> + <code>EXECVE</code> records for the execution of <code>cat</code> and a <code>PATH</code> record for the access to the <code>/etc/passwd</code> file.<br><br>The <code>type</code> field contains the type of the record:<br><br>- User authentication and access: <code>USER\_LOGIN\_SUCCESS</code>, <code>USER\_LOGIN\_FAILED</code>, <code>USER\_AUTH\_SUCCESS</code>, <code>USER\_AUTH\_FAILED</code>, <code>USER\_START\_SUCCESS</code>, <code>USER\_START\_FAILED</code>, <code>SESSION\_TERMINATED</code>.<br><br>- Process execution: <code>EXECVE</code> and <code>SYSCALL</code>.<br><br>- Filesystem access: <code>PATH</code> (for relative or absolute file access), <code>CWD</code> (current working directory, useful to reconstruct full path if a relative path has been recorded in <code>PATH</code> records) and <code>OPENAT</code>.<br><br>- Commands entered in a <code>TTY</code> console: <code>TTY</code> or by users: <code>USER\_CMD</code>.<br><br>- Full command-line of process: <code>PROCTITLE</code>. The associated <code>proctitle</code> field MAY be encoded in hexadecimal.<br><br>- Network socket connections: <code>SOCKADDR</code>. The associated <code>saddr</code> field contains IP and port information, and can be interpreted directly at event generation (if <code>log\_format = ENRICHED</code> is set), or with <code>ausearch -i</code> or <a href="https://gist.github.com/Qazeer/3aaa6be263380483d68159cae6f33fd2">simple scripting</a>.<br><br>- Account activity: <code>ADD\_USER</code> or <code>ADD\_GROUP</code>.<br><br>- More record types are listed in the <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sec-audit_record_types">RedHat documentation</a>.<br><br>If present, the <code>auid</code> field defines the ID of the user upon login and remains the same even if the user's identity changes (for instance with <code>su</code>).<br><br>If present, <code>uid</code> / <code>gid</code> and <code>euid</code> / <code>egid</code> fields define the user / group IDs and the effective user / group IDs of the audited process.<br><br>If present, the <code>tty</code> and <code>ses</code> fields define respectively the terminal and session from which the audited process was invoked.<br><br>For <code>SYSCALL</code> records, the <code>aX</code> field(s) define the arguments / parameters of the syscall, represented by unsigned long long integers and as such cannot be used to determine the values taken by the arguments.</p> | <p>Configuration file notably defining the path of the log files:<br><code>/etc/auditd.conf</code><br><br>Configuration defining the rules to apply:<br><code>/etc/audit/audit.rules</code><br>Rules best practice: <https://github.com/Neo23x0/auditd><br><br>Current log files (default location):<br><code>/var/log/audit/audit.log</code><br><code>/var/log/audit/audit.log.1</code><br><br>Rotated log archives (default location):<br><code>/var/log/audit/audit.log.\*.gz</code><br><br>The <code>aureport</code> and <code>ausearch</code> utilities can (and if possible should) be used to search the <code>auditd</code> log files.<br><br>Example:<br><code>aureport -i \[--login | --executable | ...] \[--summary] -if \<AUDIT\_LOG\_FILE></code></p> |   |

### System information

| Name                              | Type                | Description                                                                                                                                                                                                                                          | Information / interpretation                                                                                                                                                                                          | Location                                                                                                                                                                           | Tool(s) |
| --------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `alternatives` logs               | System information  | Logs of the `update-alternatives` utility, used to manage *alternatives* (i.e symbolic links to a given command).                                                                                                                                    |                                                                                                                                                                                                                       | `/var/log/alternatives.log`                                                                                                                                                        |         |
| Environment variables information | System information. | Contains system-wide or user scoped persistent environment variables.                                                                                                                                                                                | -                                                                                                                                                                                                                     | <p>System-wide configuration file:<br><code>/etc/environment</code><br><br>Initialization scripts can also be used to define system-wide or user scoped environment variables.</p> | -       |
| Hostname information              | System information  | Contains the hostname of the system.                                                                                                                                                                                                                 | -                                                                                                                                                                                                                     | `/etc/hostname`                                                                                                                                                                    | -       |
| Mounted filesystems information   | System information. | Contains information on the mounted file systems, such as partition types (ext3 / ext4, etc.).                                                                                                                                                       |                                                                                                                                                                                                                       | <p>Configuration:<br><code>/etc/fstab</code><br><br>Mount logs (such as <code>Mounting</code> operation / keyword):<br><code>/var/log/dmesg</code></p>                             | -       |
| Timezone information              | System information  | Contains the timezone of the system.                                                                                                                                                                                                                 | -                                                                                                                                                                                                                     | <p><code>/etc/timezone</code><br><br><code>/etc/adjtime</code><br><br><code>/etc/localtime</code></p>                                                                              | -       |
| `Syslog` daemon configuration     | System information  | The `Syslog` deamon configuration file(s) notably define where the messages / events received by the `Syslog` daemon will be outputted. The messages are usually written as plaintext files under `/var/log/` but can also be sent over the network. | <p>Example of a configuration file writing logs to common files:<br><br>auth,authpriv.\* /var/log/auth.log<br>*.*;auth,authpriv.none -/var/log/syslog<br>kern.\* -/var/log/kern.log<br>mail.\* -/var/log/mail.log</p> | <p><code>/etc/syslog.conf</code><br><code>/etc/rsyslog.conf</code><br><code>/etc/rsyslog.d/*.conf</code><br><code>/etc/syslog­ng.conf</code><br><code>/etc/syslog­ng/*</code></p>  | -       |

### Filesystem

**Overview**

Contrary to `NTFS` partitions, file information is not stored in a specific location (such as the `MFT`) for `ext*` partitions but scattered across blocks or groups of `blocks` (contiguous blocks combined) across the partition. `Blocks` have a fixed size, determined at the time the filesystem is created.

On `ext4`, each `block group` notably store:

* The `Super block`, only replicated at the beginning of a fraction of `block groups` however, which contains various information about the file system: block size, location of the `inode` tables, size of block groups, etc.
* The `inode bitmap` and a `data block bitmap` that limit the number of `inodes` and `data blocks` of that particular `block group`.
* An `inode table` which is a linear array of `inodes` (first to last `inode`) of that particular `block group`.

  `Inodes` are data struct that define a file and each file is associated with one `inode`. An `inode` stores metadata about the file (size, owner `UID` / `GID`, permissions, timestamps, etc.) and (direct or indirect) pointers to `data blocks` that contain the file data, but does not store the file name and file data.
* `Data blocks`, that store file data.

**Filesystem types supported timestamps**

| Filesystem                                    | atime (access) | mtime (modification) | ctime (metadata change) | crtime (creation / birth) | Comment           |
| --------------------------------------------- | -------------- | -------------------- | ----------------------- | ------------------------- | ----------------- |
| <p><code>ext2</code><br><code>ext3</code></p> | x              | x                    | x                       | -                         |                   |
| `ext4`                                        | x              | x                    | x                       | x                         |                   |
| `XFS`                                         | x              | x                    | x                       | x\*                       | \* Since `XFS v5` |

**Filesystem timelining**

```bash
find <DIRECTORY> -xdev -print0 | xargs -0 stat -c 'crtime="%w" crtime_epoch="%W" mtime="%y" mtime_epoch="%Y" ctime="%z" ctime_epoch="%Z" atime="%x" atime_epoch="%X" size_bytes="%s" userID="%u" username="%U" groupID="%g" groupname="%G" access="%a" access_pretty="%A" filetype="%F" filename="%n" filename_deref="%N"'
```

### Software installation and program execution

| Name                   | Type                   | Description                                                                                     | Information / interpretation | Location                                                                                                                                                             | Tool(s) |
| ---------------------- | ---------------------- | ----------------------------------------------------------------------------------------------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `apt` / `apt-get` logs | Software installation  | Logs of `apt-get` / `apt` operations, including packets installation.                           |                              | <p>Current log file:<br><code>/var/log/apt/history.log</code><br><br>Rotated log archives:<br><code>/var/log/apt/history.log.\*.gz</code></p>                        |         |
| `aptitude` logs        | Software installation. | Logs of the `aptitude` utility (front-end to `apt`) operations, including packets installation. |                              | `/var/log/aptitude`                                                                                                                                                  |         |
| `dpkg` logs            | Software installation. | Logs of `dpkg` operations, including packets installed / removed through the utility.           |                              | <p>Current log files:<br><code>/var/log/dpkg.log</code><br><code>/var/log/dpkg.log.1</code><br><br>Rotated log archives:<br><code>/var/log/dpkg.log.\*.gz</code></p> |         |

### Files and folders access

### Remote Access / Lateral movements

| Name                        | Type                                       | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | Information / interpretation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Location                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Tool(s)                                                                                                                                                                                                                            |                                                                                                                                |   |
| --------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | - |
| `Authorization (auth)` logs | Remote Access / authentication information | <p>Authentication information and <code>sudo</code> commands. More precisely, usage of authorization systems: successful or unsuccessful logins, sudo commands, etc.<br><br>Usually generated by the <code>AUTH</code> and <code>AUTHPRIV</code> facilities of the <code>syslog</code> daemon. <code>AUTH</code> regroups the authentication events / messages while <code>AUTHPRIV</code> regroups the elevation of privileges events / messages (such as commands executed through <code>sudo</code>).</p> | <p>Notably includes:<br><br>- Successful or unsuccessful logins to the <code>sshd</code> deamon. The authentication types (password, pubkey, etc.) or reason of failure (unknown user, invalid password) is specified.<br><br>- Commands executed with elevated privileges using <code>sudo</code>.</p>                                                                                                                                                                                                                                                                                                                                                                         | <p><em>Location of the <code>auth</code> logs depend of the <code>syslog</code> daemon configuration (refer to the "Syslog daemon configuration" artefact below for more information).</em><br><br>\[Debian / Ubuntu based systems]<br><br>Default location:<br><code>/var/log/auth.log</code><br><code>/var/log/auth.log.1</code><br><br>Rotated log archives:<br><code>/var/log/auth.log.\*.gz</code><br><br>\[RedHat / CentOS based systems]<br><br>Default location (for <code>AUTHPRIV</code> logs):<br><code>/var/log/secure</code></p> |                                                                                                                                                                                                                                    |                                                                                                                                |   |
| Login records `*tmp`        | Remote Access / authentication information | <p><code>utmp</code> / <code>utmpx</code>: currently logged users.<br><br><code>wtmp</code> / <code>wtmpx</code>: all current and past logins, with additional details on system reboots, etc.<br><br><code>btmp</code> / <code>btmpx</code>: all bad login attempts.<br><br>The <code>\*tmpx</code> files are extended database files that supersede the <code>\*tmp</code> files on some distributions.</p>                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | <p>Linux:<br><code>/var/run/utmp</code><br><code>/var/log/wtmp</code><br><code>/var/log/btmp</code><br><br>Solaris:<br><code>/var/adm/utmp</code> (deprecated)<br><code>/var/adm/utmpx</code><br><code>/var/adm/wtmp</code> (deprecated)<br><code>/var/adm/wtmpx</code><br><br>FreeBSD 9.0:<br><code>/var/run/utx.active</code> (<code>utmp</code> equivalent)<br><code>/var/log/utx.log</code> (<code>wtmp</code> equivalent)</p>                                                                                                            | `*tmp` login records are not stored in clear-text and must be parsed with adequate utilities, such as `utmpdump <*TMP_FILE>`.                                                                                                      |                                                                                                                                |   |
| `SSH` known hosts           | Lateral movement                           | <p>Possible <code>SSH</code> outgoing connections.<br><br>System-wide or user scoped known <code>SSH</code> keys for remote hosts. Usually collected, and user-validated, from the remote hosts when connecting for the first time.</p>                                                                                                                                                                                                                                                                      | <p>The remote hosts hostname and IP address can be either stored in clear-text or hashed if <code>HashKnownHosts</code> is set to "yes" in the <code>SSH</code> client <code>ssh\_config</code> configuration file.<br>Even if the hosts information are hashed, the following command can be used to check whether the specified hostname is present in the given known hosts file:<br><code>ssh-keygen -l -f \<KNOWN\_HOST\_FILE> -F \<HOSTNAME></code>.<br>Additionally, <code>John</code> can be used to bruteforce known hosts files:<br><code>john --format=known\_hosts \<KNOWN\_HOST\_FILE></code><br><br><code>nmap -sL -Pn -n 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 | grep '^Nmap scan report for'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | cut -d ' ' -f 5 > IP\_list.txt</code><br><code>john --wordlist=IP\_list.txt --format=known\_hosts \<KNOWN\_HOST\_FILE></code><br><br>One of the few endpoint disk artefacts to identify outgoing <code>SSH</code> connections.</p> | <p>System-wide known hosts:<br><code>/etc/ssh/known\_hosts</code><br><br><code>\<USER\_HOME\_DIR>/.ssh/known\_hosts</code></p> |   |

### Local persistence

| Name                         | Type                             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | Information / interpretation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          | Location                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | Tool(s)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ---------------------------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `at` jobs (`atd` daemon)     | Persistence                      | <p>Scheduled jobs that are configured using the <code>at</code> command-line utility to be run exactly one time. The jobs are executed as shell (bash, zsh, etc.) scripts.<br><br>By default, any user can create <code>at</code> jobs.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | <p>Each <code>at</code> jobs is represented by a file, which contains metadata information as comments, the environment variables for the execution, and the configured shell script / commands.<br><br>The filename follows a specific format (<code>\[a=]\<JOB\_NUMBER\_5\_CHAR>\<TIMESAMP\_8\_CHAR></code>) and gives additional information about the job. The following information can be deduced from the file name and the file itself:<br>- File created or last modified timestamp => when the <code>at</code> job was created.<br>- Username, <code>uid</code>, and <code>gid</code> of the user that created the job as shell comments in the file.<br>- Filename first char: <code>a</code> => job is pending or <code>=</code> => job is running.<br>- Filename 5 next chars => job id.<br>- Filename 8 next (and last) chars => hex-encoded minutes since <code>epoch</code> timestamp. Can be converted to retrieve the <code>epoch</code> timestamp of execution by converting to decimal and multiplying by 60.</p> | <p>Configured <code>at</code> jobs locations, each files representing a single <code>at</code> job:<br><code>/var/spool/at/</code><br><code>/var/spool/cron/atjobs/</code><br><br>Configuration files that define the users that can or cannot create <code>at</code> jobs:<br><code>/etc/at.allow</code><br><code>/etc/at.deny</code><br><br>Output of currently running <code>at</code> jobs, saved as email text files:<br><code>/var/spool/at/spool/</code><br><code>/var/spool/cron/atspool/</code><br><br>Number of <code>at</code> jobs that have been created (already executed, executing, or scheduled):<br><code>/var/spool/at/.SEQ</code><br><code>/var/spool/cron/atjobs/.SEQ</code><br><br>Trace of previous <code>at</code> jobs execution can be found in:<br>- Session opening by the <code>atd</code> daemon events in <code>syslog</code> or <code>journal</code> logs.<br>- <code>at</code> jobs email sent events in local email logs.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `cron` jobs (`cron` daemon)  | Persistence                      | <p>Scheduled jobs that, unlike <code>at</code> jobs, are executed repeatedly at a given frequency. <code>cron</code> jobs are executed at a pre-determined time (such as five minutes after midnight every day or at 2:15pm on the first of every month). The jobs are executed as shell (bash, zsh, etc.) scripts.<br><br>If the system is not running when a <code>cron</code> job is planned, the job will not be executed following the system boot.<br><br>By default, only root can define system-wide <code>cron</code> jobs (in <code>/etc/crontab</code> or under <code>/etc/cron.d</code>). But users can be allowed to use the <code>crontab</code> command, and will have their respective jobs created in the <code>/var/spool/cron/crontabs/\<USERNAME></code> file.<br><br>Usage rights of <code>cron</code> are defined by the <code>/etc/cron.allow</code> and <code>/etc/cron.deny</code> files:<br>- If <code>cron.allow</code> exists, only root and users listed in this file can use <code>cron</code> (and <code>cron.deny</code> is ignored).<br>- If only <code>cron.deny</code> exists, all users except the ones listed in this file can use <code>cron</code>.<br>- If neither of the files exist, only root can use cron (default state).</p> | <p>Each <code>cron</code> job is represented by a line in a <code>crontab</code> file.<br><br>The line format is a follow:<br><code>\<MINUTE (0 - 59)> \<HOUR (0 - 23)> \<DAY (1 - 31)> \<MONTH (1 - 12 / jan, feb, ...)> \<DAY\_WEEK (0 - 6 / mon, tue, ...)> \<COMMAND></code>.<br><br>The specifiers can be replaced by a wildcard <code>*</code>, that represents "all". For example, a line with only wildcards (<code>* \* \* \* \* \<COMMAND></code>) means that the command will be executed every minute of every hour of every day of every month.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | <p>System-wide <code>cron</code> jobs:<br><code>/etc/crontab</code> file.<br><code>crontab</code> files under <code>/etc/cron.d/</code>.<br><br>User specific <code>cron</code> jobs, with one <code>crontab</code> file per user (that has configured jobs):<br><code>/var/spool/cron/crontabs/\<USERNAME></code>.<br><br>Usage rights of <code>cron</code>:<br><code>/etc/cron.allow</code><br><code>/etc/cron.deny</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `anacron` jobs               | Persistence                      | <p>Scheduled jobs that are executed with a frequency specified in days or in a time interval (daily, weekly, monthly, or annually). Unlike <code>cron</code> jobs, <code>anacron</code> jobs are executed after a system boot if the system was not running during the last scheduled execution.<br><br>Depending on the Linux distribution, <code>anacron</code> itself may be run as a <code>systemd</code> timer (<code>/lib/systemd/system/anacron.timer</code>), a system cron job (<code>/etc/cron.d/anacron</code>), and / or at boot (<code>/etc/init.d/anacron</code>).<br><br>By default, <code>cron</code> "dot" directories (<code>/etc/cron.{daily,weekly,monthly}</code>) are often run by <code>anacron</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | <p>Each <code>anacron</code> job is represented by a line in an <code>anacrontab</code> file.<br><br>The line format is a follow: <code>\<PERIOD\_IN\_DAYS> \<DELAY\_IN\_MINUTES> \<JOB\_IDENTIFIER\_STRING> \<COMMAND></code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <p>System-wide <code>anacron</code> jobs: <code>/etc/anacrontab</code><br><br><code>cron</code> "dot" directories, that contain shell scripts directly:<br><code>/etc/cron.daily/</code><br><code>/etc/cron.hourly/</code><br><code>/etc/cron.monthly/</code><br><code>/etc/cron.weekly/</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `Run Control (RC)` scripts   | Persistence                      | <p>Deprecated mechanism, in favor of <code>Systemd</code> / <code>init.d</code>, to define and start services as shell scripts at the system startup.<br><br>Scripts are configured to be executed at different run levels, from <code>0</code> (stop) to <code>6</code> (reboot) through <code>1</code> (maintenance mode) and <code>2-5</code> (multi-users mode, such as desktop startup, etc.).</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <p><code>RC</code> scripts locations:<br><code>/etc/rc.local</code><br><br><code>/etc/rc.common</code><br><br><code>/etc/rc<0-6>.d/*</code><br><code>/etc/rcS.d/*</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Shell initialization scripts | Persistence                      | System-wide or user scoped scripts that are executed by shells during their different stages of their initialization.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <p>User scoped initialization script:<br><code>\<USER\_HOME\_DIR>/.profile</code><br><code>\<USER\_HOME\_DIR>/.bash\_profile</code><br><code>\<USER\_HOME\_DIR>/.zprofile</code><br><code>\<USER\_HOME\_DIR>/.bash\_login</code><br><code>\<USER\_HOME\_DIR>/.zlogin</code><br><br>System-wide initialization scripts:<br><code>/etc/profile</code><br><code>/etc/profile.d/\*</code><br><code>/etc/skel/.profile</code> (Not used if <code>\<USER\_HOME\_DIR>/.bash\_profile</code> or <code>\<USER\_HOME\_DIR>/.bash\_login</code> exist).<br><br>Executed if an interactive shell is opened:<br><code>\<USER\_HOME\_DIR>/.bashrc</code><br><code>\<USER\_HOME\_DIR>/.zshrc</code><br><br>Executed at the end of the session:<br><code>\<USER\_HOME\_DIR>/.bash\_logout</code><br><code>/etc/zlogout</code><br><code>\<USER\_HOME\_DIR>/.zlogout</code></p>                                                                                                   |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `SSH` authorization keys     | Persistence                      | Specifies the `SSH` keys that can be used for logging into the user account for which the file is configured, thus allowing permanent access as that user.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <p>Configuration of the <code>SSH</code> authorization keys:<br><code>/etc/ssh/sshd\_config</code> <code>AuthorizedKeysFile</code>directive.<br><br>Default <code>SSH</code> authorization keys location:<br><code>\<USER\_HOME\_DIR>/.ssh/authorized\_keys</code><br><code>\<USER\_HOME\_DIR>/.ssh/authorized\_keys2</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `XDG` autostart entries      | Persistence                      | XDG compliant graphical / desktop systems support `XDG` autostart entries, allowing applications to automatically start during the startup of a desktop environment (after user logon).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <p>Each <code>XDG</code> autostart entry is represented by a file, which contains the following notable keys:<br>- <code>Type</code> key that specifies the entry type (application, link, or directory).<br>- <code>Name</code> key that indicates an arbitrary name assigned by the autostart entry creator.<br>- <code>Exec</code> key that defines the application and command line arguments to be executed.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | <p>User scoped initialization autostart entries:<br><code>\<USER\_HOME\_DIR>/.config/autostart/*.desktop</code><br><br>System-wide autostart entries: <code>/etc/xdg/autostart/*.desktop</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Webshell                     | Command execution / Persistence. | <p>Simply put, webshells are script files that are executed by a webserver. Webshells are notably leveraged to:<br><br>- execute code / commands on the underlying operating system following the exploitation of a web vulnerability (unrestricted file upload, remote code execution, etc.)<br><br>- maintain persistence following the compromise of an host exposing a webserver (usually Internet facing).</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | <p>Usual locations:<br><code>/var/www/html</code><br><code>/usr/local/www/</code><br><br><code>/etc/nginx</code><br><br><code>/etc/apache2</code><br><br><code>/srv/</code><br><code>/srv/www</code><br><br><code>...</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                | <p>Webshells can be uncovered by:<br>- Yara rules aimed at webshells such as <a href="https://github.com/Neo23x0/signature-base/blob/master/yara/gen_webshells.yar"><code>Neo23x0's gen\_webshells.yar</code></a> or <a href="https://github.com/nsacyber/WALKOFF-Apps/blob/master/AlienVault/signature-base/yara/thor-webshells.yar"><code>thor-webshells.yar</code></a>:<br><code>yara -r \<YARA\_RULE\_PATH> \<WEBSERVER\_ROOT></code><br><br>- Reviewing added files or modifications in legitimate files using code repository or a fresh install of the application if possible.<br><br>- Manually by looking for known webshell patterns (<code>Runtime.getRuntime().exec</code>, <code>eval</code>, <code>system</code>, etc.), obfuscated script files, or files modified during the targeted timeframe.<br><br>- Reviewing the webserver access logs if available, looking for exploitation IoCs, unusual requests, large response size, etc.</p> |

### Web browsers and network usage

| Name                | Type                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         | Information / interpretation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | Location                     | Tool(s) |
| ------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------- | ------- |
| `wget` HSTS history | Web browsers and network usage | <p><code>wget</code> utility's <code>HTTP Strict Transport Security (HSTS)</code> history.<br><br><code>HSTS</code> is a mechanism to only allow access to a particular website in <code>HTTPS</code> if that website was accessed in <code>HTTPS</code> once and defines an <code>HSTS</code> policy. The <code>HSTS</code> policy to follow is define by the web server through the <code>Strict-Transport-Security</code> <code>HTTP</code> response header. The web browser or utility has to store the websites accessed in <code>HTTPS</code> (with <code>HSTS</code> implemented) for the duration specified in the header to support <code>HSTS</code>.</p> | <p><code>wget</code>'s <code>HSTS</code> history is implemented as a plaintext file, with an entry per line.<br><br>For each entry, the following notable information are available:<br><br>- Hostname of the accessed website<br>- Created timestamp in <code>UTC</code> (in <code>epoch</code> format) that defines when the entry was created. As the entry is overwritten upon new access to a website defining an <code>HSTS</code> policy, the created timestamp matches the last access to the website.</p> | `<USER_HOME_DIR>/.wget-hsts` | -       |

### Web servers and third-party applications logs

| Name                    | Type             | Description                     | Information / interpretation | Location                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Tool(s) |
| ----------------------- | ---------------- | ------------------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `Apache` webserver logs | Web servers logs | Logs of the `Apache` webserver. |                              | <p>Debian / Ubuntu:<br><code>/var/log/apache2/access.log</code><br><code>/var/log/apache2/error.log</code><br><br>RHEL / Red Hat / CentOS / Fedora :<br><code>/var/log/httpd/access\_log</code><br><code>/var/log/httpd/error\_log</code><br><br>FreeBSD:<br><code>/var/log/httpd-access.log</code><br><code>/var/log/httpd-error.log</code><br><br>Custom definition for access (<code>CustomLog</code> section) or error (<code>ErrorLog</code> section) logs:<br><code>/etc/httpd/conf/httpd.conf</code><br><code>/etc/apache2/apache2.conf</code><br><code>/usr/local/etc/apache22/httpd.conf</code></p> |         |

### TODO

***

journactl

***

\| systemd services | Persistence | The `systemd service manager` is used for managing background daemon processes, known as `services`.\
\
`systemd` relies on `service units` | | System-wide `service unit` files:\
`/usr/lib/systemd/system/*`\
`/etc/systemd/system/*`\
\
User-scoped `service unit` files for user-level persistence:\
`<USER_HOME_DIR>/.config/systemd/user/` | yara rules |

Systemd utilizes configuration files known as service units to control how services boot and under what conditions. By default, these unit files are stored in the /etc/systemd/system and /usr/lib/systemd/system directories and have the file extension .service. Each service unit file may contain numerous directives that can execute system commands:

*Systemd* also defines several *unit types*:

* *Service*: the unit starts, stops, restarts or reloads programs or daemons;
* *Socket*: the unit is activated when it receives incoming traffic on a listening socket or in the context of inter-process communication;
* *Target*: groups of units used at boot time to start the system in a particular state;
* *Device*: the unit is activated when a device is connected to the Linux system;
* *Mount*: the unit controls file system mount points;
* *Automount*: the unit controls on-demand mounting of file system;
* *Timer*: the unit is activated at specific times;
* *Swap*: the unit encapsulates, activates or deactivates swap partitions or files;
* *Path*: the unit is activated when a monitored file is modified;
* *Slice*: group of units that manage system resources;
* *Scope*: the unit organizes and manages foreign processes.

ExecStart, ExecStartPre, and ExecStartPost directives cover execution of commands when a services is started manually by 'systemctl' or on system start if the service is set to automatically start. ExecReload directive covers when a service restarts. ExecStop and ExecStopPost directives cover when a service is stopped or manually by 'systemctl'.

\[Unit] Description=Myservice \[Service] ExecStart=/tmp/46868461631.tmp/malw4re

<https://attack.mitre.org/techniques/T1543/002/>

***

shell history

shell histories are only filled in when the shell is closed

***

init.d

***

Network configuration

Before systemd:

Red Hat and SUSE systems /etc/sysconfig/network-scripts/ /etc/sysconfig/network/ SUSE-only: /etc/wicked/

Debian-based systems

/etc/network/interfaces /etc/network/interfaces.d/

Systemd:

systemd provides its own network management features. It is based on three types of file:

.link files to configure physical network devices; .netdev files to configure virtual netowrk devices (VPN, tunnels...); .network files to configure the network layer. All these files are stored in the following directories:

/usr/lib/systemd/network/ (default files used by systemd daemons systemd-udevd and systemd-networkd); /etc/systemd/network/ (customized files by the system administrator).

Network Manager can also be used to manage network configuration /etc/NetworkManager.conf (general configuration information); /etc/NetworkManager/system-connections/ (configurations for each individual connection, declined by name).

***

DNS nameservers and hosts

/etc/resolv.conf /etc/resolv.conf.bak

The /etc/resolv.conf file is managed either by the openresolv resolvconf framwork or by the systemd's resolvconf framework. The systemd-resolved daemon is configured in the /etc/systemd/resolved.conf file. This file contains the daemon parameters, DNS servers, fallback servers and other DNS resolver configuration. The openresolv framwork stores the same information in the /etc/resolvconf.conf file.

/etc/hosts

***

/etc/network/if-up.d/upstart

/etc/apt/apt.conf.d - persistence

/etc/udev/rules.d/

`<USER_HOME_DIR>/.viminfo`

/etc/security/lastlog Specifies the path to the lastlog file.

/etc/group Contains the basic attributes of groups.

/etc/security/group Contains the extended attributes of groups.

/etc/passwd Contains the basic attributes of users.

/etc/security/passwd Contains password information. => Check user with shell and that have a different uid / gid than default.

/etc/security/environ Contains the environment attributes of users.

/etc/security/user Contains the extended attributes of users.

/etc/security/limits Contains the process resource limits of users. <https://www.ibm.com/docs/en/aix/7.1?topic=formats-lastlog-file-format>

USB devices activity will generate kernel logs, usually in `/var/log/kern.log` and `Syslog` centralized logs (such as `/var/log/syslog`) depending on the syslog daemon configuration.

***

motd message of the day

<https://pberba.github.io/security/2022/02/06/linux-threat-hunting-for-persistence-initialization-scripts-and-shell-configuration/#10-boot-or-logon-initialization-scripts-motd>

***

***

### References

<https://www.sciencedirect.com/science/article/pii/S1742287612000357>

<https://wiki.debian-fr.xyz/Consulter\\_les\\_logs\\_:\\_quoi,_o%C3%B9\\_et\\_comment\\_chercher_%3F>

<https://nostarch.com/download/samples/PracticalLinuxForensics\\_Ch5\\_072721.pdf>

<https://blog.codeasite.com/how-do-i-find-apache-http-server-log-files/>

<https://sematext.com/blog/auditd-logs-auditbeat-elasticsearch-logsene/>

<https://access.redhat.com/documentation/en-us/red\\_hat\\_enterprise\\_linux/7/html/security\\_guide/sec-understanding\\_audit\\_log\\_files>

<https://www.elastic.co/fr/blog/grokking-the-linux-authorization-logs>

<https://unix.stackexchange.com/questions/31549/is-it-possible-to-find-out-the-hosts-in-the-known-hosts-file>

<https://pberba.github.io/security/2021/11/22/linux-threat-hunting-for-persistence-sysmon-auditd-webshell/>

<https://en.wikipedia.org/wiki/Utmp>

<https://pberba.github.io/security/2022/02/06/linux-threat-hunting-for-persistence-initialization-scripts-and-shell-configuration/>

<https://attack.mitre.org/techniques/T1547/013/>

<https://unix.stackexchange.com/questions/411051/how-does-anacron-work-if-its-not-a-daemon>

<https://linux.die.net/man/8/cron>

<https://linux.die.net/man/5/crontab>

<https://linux.die.net/man/8/anacron>

<https://linux.die.net/man/5/anacrontab>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.qazeer.io/dfir/linux/_artefacts_overview.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
