# Finding Evidence of Persistence Mechanisms

## Persistence Mechanism

**AutoRun keys:** They are a common persistence mechanism used by attackers to maintain access to a compromised system. They are registry entries that specify programs or scripts that are automatically executed upon system boot or user login.

* `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
* `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce`
* `HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run`
* `HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce`

Let's open **`SOFTWARE`** and **`NTUSER.DAT`** hives using Registry Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FIBGC73fqU0cNWXZy2O0h%2FScreenshot(12).png?alt=media&#x26;token=a95e385f-2b8e-4cc0-8958-d68372004795" alt=""><figcaption></figcaption></figure>

And for **`NTUSER.DAT`** hive.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FT6uoUdXV0gjTOk3E3Rm1%2FScreenshot(13).png?alt=media&#x26;token=edb5c952-cc9c-4fb4-87b2-5e6fd1f9365e" alt=""><figcaption></figcaption></figure>

We can also review the results previously obtained from RegRipper.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FkMUWILiTJrF1znm48hPq%2FScreenshot(14).png?alt=media&#x26;token=a5dccab4-ff13-4c6c-a110-69a20a1d29c8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FSB6JTf8h1goj72823Gvr%2FScreenshot(15).png?alt=media&#x26;token=cf635778-652c-40ef-b0b1-b0bd8c8be64e" alt=""><figcaption></figcaption></figure>

## Startup Folders

In Windows, **Startup Folders** are directories where shortcuts to programs or scripts can be placed to execute automatically when the system boots or a user logs in. These folders are commonly used by legitimate applications but are also abused by attackers to establish persistence.

* **System-Wide Startup Folder**\
  Applies to all users on the system:
  * Path:\
    `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp`
* **Per-User Startup Folder**\
  Applies only to a specific user:
  * Path:\
    `C:\Users\<Username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\StartUp`

Q) What is the name of the suspicious script in the Startup folder?

First, let's review the System Startup folder to identify any relevant findings.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F6zqkPH3IsbHRWgfVW1Wm%2FScreenshot(16).png?alt=media&#x26;token=d7323216-6ccb-45da-954f-ec083219c30d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5c1IHUYBpm6loRGGwXB1%2FScreenshot(17).png?alt=media&#x26;token=912527d0-b88d-42d6-af92-10c345fbab84" alt=""><figcaption></figcaption></figure>

Next, for the Per-User Startup Folder.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fwntbv8WEpCnedPLCtZbz%2FScreenshot(19).png?alt=media&#x26;token=8b61d5a7-d282-4039-8d76-77baa01208a4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fjt9gDyjuq4T5lcBxAEmp%2FScreenshot(20).png?alt=media&#x26;token=7db14d67-0cf1-4434-9c28-1246ed1dee70" alt=""><figcaption></figcaption></figure>

The $MFT can be analyzed to track the contents and modifications of Startup Folders during a forensic investigation. We already have an MFT.csv file available for this purpose.

Let's use Ubuntu on Windows.

```bash
cd /mnt/c/Cases/Analysis/NTFS
ls -l
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F87HaSEBuOllzvkDxhuyB%2FScreenshot.png?alt=media&#x26;token=33a559b5-49ad-4a2b-b26f-647ec1496d7a" alt=""><figcaption></figcaption></figure>

```bash
grep StartUp MFT.csv
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FvNNtN7XgVXIjiR9xHSHw%2FScreenshot(1).png?alt=media&#x26;token=a57c5c01-dcd1-4ab7-9c9d-12e815d78e3d" alt=""><figcaption></figcaption></figure>

Let's verify if it still exists on the disk.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FPxB32YKhHirLAS11I3r9%2FScreenshot(2).png?alt=media&#x26;token=7457df9a-9063-4e57-b59d-9ef4b65f436a" alt=""><figcaption></figcaption></figure>

## Windows Services

Windows services is a critical part of a forensic investigation, as services are often abused by attackers to maintain persistence, execute malicious payloads, or escalate privileges.

* **Persistence Mechanism**: Attackers may create malicious services or hijack legitimate ones to ensure their payloads are executed on boot.
* **Privilege Escalation**: Services often run with SYSTEM privileges, making them a target for abuse.
* **Indicator of Compromise (IOC)**: Unusual or unauthorized services can indicate malware or an adversary's presence.

**Registry**: `HKLM\SYSTEM\CurrentControlSet\Services`

Let's open the System hive using Registry Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F9gyTTQY028LiyiN8BcQl%2FScreenshot(3).png?alt=media&#x26;token=c334f913-4169-4d9d-99e8-b0a7baecfc34" alt=""><figcaption></figcaption></figure>

We can also review the results previously obtained from RegRipper.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FHlTXvkGUpgueonoPwJYa%2FScreenshot(4).png?alt=media&#x26;token=4efe19db-032b-4ea5-89d2-430ccbb73a5b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FZa6Bkh2gxrw77Ifb7Xc1%2FScreenshot(5).png?alt=media&#x26;token=6d012018-4483-416b-b684-e2e625c6cef5" alt=""><figcaption></figcaption></figure>

## Scheduled Tasks

**Registry:**&#x20;

* `HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks`
* `HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree`

Scheduled Tasks are a critical mechanism in Windows often used for legitimate purposes such as system maintenance or application updates. However, they are frequently exploited by attackers as a persistence method or to execute malicious payloads at specified intervals.

* **Persistence Mechanism**: Attackers use tasks to ensure payloads are executed repeatedly or at system startup.
* **Privilege Escalation**: Tasks can run with elevated privileges, making them a potential target for exploitation.
* **Malware Execution**: Tasks may run scripts or executables associated with malicious activity.

**Path:** `C:\Windows\System32\Tasks`

Let's load the `SOFTWARE` hive into Registry Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F6CxmHztG9zcJnjVLqWOf%2FScreenshot(6).png?alt=media&#x26;token=860e4a88-7022-4a5e-acfa-ac50e0c4c0a4" alt=""><figcaption></figcaption></figure>

Or using RegRipper.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fw0oDmPxCxAB0FCliVPrg%2FScreenshot(7).png?alt=media&#x26;token=b1e2b648-fae5-4f5a-b375-7f4fc9b537d7" alt=""><figcaption></figcaption></figure>

Let's check the path also `C:\Windows\System32\Tasks`.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fy1EJPQWxONxJD8ozR4Cv%2FScreenshot(8).png?alt=media&#x26;token=8518d54b-288b-46c5-9cb4-859c125c4348" alt=""><figcaption></figcaption></figure>

Let's open them in Notepad.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5M3f5zoYy5iOqZQlxnac%2FScreenshot(9).png?alt=media&#x26;token=ee068559-ded6-41f0-a383-1f5850a68aac" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FvFoqR55LW2n9pdpy2TGR%2FScreenshot(22).png?alt=media&#x26;token=c15c3f3b-f518-41e5-8991-56a338cf4798" alt=""><figcaption></figcaption></figure>

## Persistence Analysis with Sysinternals Autoruns

Sysinternals Autoruns is a powerful tool for analyzing persistence mechanisms on a Windows system.

Autoruns identifies and enumerates all programs configured to run automatically when the system starts or when a user logs in. This includes entries from various persistence locations like registry keys, startup folders, scheduled tasks, and more.

Detects all startup items, including those from known persistence mechanisms (e.g., registry Run keys, startup folders, services, and scheduled tasks).

* **Logon:** Includes startup folder items and Run/RunOnce registry keys.
* **Services:** Displays Windows services configured to run at startup.
* **Scheduled Tasks:** Shows scheduled tasks, including hidden or malicious ones.
* **Explorer:** Identifies shell extensions and browser helper objects.

Let's analyze the E:\ drive using Autoruns.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FVTbLLbXLAFbqBFgMMX8o%2FScreenshot(1).png?alt=media&#x26;token=d97f2f07-463d-4ddc-9afe-1cf18de30b6b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FVNG9GssR6TMyk7L6m5c9%2FScreenshot(2).png?alt=media&#x26;token=d7e37e00-17b3-4bfc-a94b-f1f4bda66d24" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FZjKNbKW6Vt02E4WRN4SV%2FScreenshot(3).png?alt=media&#x26;token=87fcc3e7-e96e-428b-ab40-36a9d2450ef0" alt=""><figcaption></figcaption></figure>
