Threat Hunting: Initial infection - Identify Scripts Files Written to User Profile Temp Directory

Where in the Cyber Kill Chain?


ThrHuntingInit2_dc297d19-4d82-4db1-8f2a-728c153740b1.png

IDENTIFYING

Written to user profile temp directory

COMPONENT

Remarks

TACTIC

Identify VBS, BAT, or PS1 scripts written to the root of the AppData\Local\Temp directory within any user profile. Meterpreter's persistence module drops a script to this path by default. This saved question deliberately excludes other file extensions such as EXE, CMD, or DLL files as legitimate application installers frequently write these file types to this path.

TECHNIQUE

Trace File Operations. Can be used as-is in most environments

PROCEDURE

Trace File Operations

  1. Open the TaaS Tanium Console.

  2. Use either the Question Builder or Question Bar, proceed to Trace File Operations.

  3. Configure the Sensor with the following settings:

  • Treat Inputs as Regular Expressions: Enabled .

  • Make Stackable/Skip Unique: Disabled .

  • File Path: (?i).*\\appdata\\(local\\temp|roaming)\\\w*\.(vbs|ps1|bat)

  • File Operation: Create

    Question:

    Get Trace File Operations[1 day, 1627935098772|1627938697772, 1, 0, 1, 0, (?i).*\\appdata\\(local\\temp|roaming)\\\w*\.(vbs|ps1|bat), , , , ][1 day,1627935098772|1627938697772,1,0,1,0,(?i).*\\appdata\\(local\\temp|roaming)\\\w*\.(vbs|ps1|bat),Create,,,] from all machines

Limitations

May produce false positives for legitimate usage by applications, or administrattive practices, but should be relatively uncommon.

Technique effective against the following adversary TTPs

  • Initial infections