Creating remediation tasks

You can include remediations when you create surveys and notifications. When you create a survey, one question can include a remediation task that the endpoint user can choose to run to resolve an issue. When you create a notification, you can include a remediation that triggers when users acknowledge the notification. In addition to the default remediation packages that are included with Engage, you can define your own custom remediation tasks that use existing Tanium packages, or packages that you define.

Default remediation tasks

The following remediation tasks are included with Engage.

Restart Endpoint

Restarts the target device.

Clear Microsoft Teams Cache

Clears cache to resolve problems with Microsoft Teams.

Clear DNS Cache

Clears DNS cache to help resolve network issues.

Enable / Disable Fast Start

Enables or disables the Windows OS Fast Start feature.

Restart <application>

Restarts the (macOS) Apple Safari, Cisco Webex, Google Chrome, Microsoft Edge, Microsoft Outlook, Microsoft Teams, Mozilla Firefox, Slack, or Zoom application.

User Disk Cleanup

Performs light (Recycle bin empty) clean.

Create remediation package

Before you create a remediation task, choose or create a package that you want to deploy as a part of the remediation task.

Tanium packages

To browse the packages that are already in your environment, go to Administration > Packages.

Important: You cannot use sensor-sourced packages as a remediation task. Sensor-sourced packages include a sensor name with pipe characters in the package command, for example: ||Reveal - Confirmed Files_File||

Custom package

Create remediation task

  1. From the Main menu, go to Modules > Engage > Remediations.
  2. Click Create Task.
  3. Enter a name, description, and content set to which you want to save the remediation task.
  4. Click Add Package and choose a package to run.
  5. Save your changes.

Sample: (Windows with PowerShell Script and Notepad) Create remediation package that runs as user

Use this sample to create a task that runs as the user answering the survey on a Windows endpoint. This script uses the TaniumRunAsUser.exe utility that ships with the Engage tools.

  1. This sample includes a script that opens Notepad in the user context on the endpoint. Create the OpenNotepadAsUser.ps1 file by copying and pasting the following code into a text file.

    OpenNotePadAsUser.ps1

    JAVASCRIPT
    param (
        # The SID of the user
        [Parameter(Position = 0, Mandatory = $true)]
        [string]$UserSID
    )
    
    $UserSID = [system.uri]::UnescapeDataString( $UserSID )
    
    function Get-SessionFromSid( [string] $UserSID) {
        # Assume that the user has explorer.exe running
        foreach ( $process in (Get-CimInstance Win32_Process -filter "name = 'explorer.exe'")) {
            $owners = (Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid)
            foreach ($owner in (Where-Object -InputObject $owners -Property ReturnValue -EQ 0)) {
                if ($UserSID -eq $owner.SID) {
                    return $process.SessionId
                }
            }
        }
    }
    
    # you should check that this is not $null and exit gracefully
    $sessionId = Get-SessionFromSid $UserSID
    if ($sessionId -eq $null) {  
        Write-Error "Could not find session for user SID: $UserSID"  
        exit 1  
    }
    
    # Take note of the extra quotes around the inner command
    $command = "cmd.exe /d /c start ""C:\Windows\notepad.exe"""
    
    # Note: /sessionid=<value> is one group
    #       /cmd is one group, and has more quotes around $command
    #       /userenv ensures that we will load the user's environment variables
    $arguments = ("/noconsole", "/wrap", "/userenv", "/sessionid=$sessionId", "/cmd ""$command""")
    
    
    $fileName = "$Env:TANIUM_CLIENT_ROOT\Tools\Engage\tasks\TaniumRunAsUser.exe"
    Start-Process -FilePath $fileName -ArgumentList $arguments
    Important:

    Follow these guidelines in your script to prevent potential security issues, such as privilege escalation or malicious code execution:

    • The TaniumRunAsUser.exe file should be run from the default Tanium Client path, at: <Tanium Client>\Tools\Engage\tasks\TaniumRunAsUser.exe. Use the path exactly as it is provided in the OpenNotePadAsUser.ps1 code sample.

    • Any commands that run from within your package file should run from explicitly specified paths that are not writable by non-admin users. For example, the following command includes a path that is not writable:  "<Tanium Client>\Tools\Engage\tasks\TaniumRunAsUser.exe" /noconsole /wrap /userenv /sessionid= /cmd "cmd.exe /d /c start "non\user\writable\path\TARGET_PROCESS"

    • If the TaniumRunAsUser.exe command is run with the /userenv switch, environment variables that are referenced from within the TARGET_PROCESS resolve to the target user’s environment variables. Avoid executing scripts or executable files from within the TARGET_PROCESS using an unreliable path. A path that references user environment variables can lead to execution of unintended files.

    • The self-authored package file code should validate package parameters before appending them directly to other commands.

  2. Create the package in Tanium Console. From the Main menu, go to Administration > Packages > New Package.

  3. Enter the package details.

    Remediation package details for the Windows with PowerShell Script and Notepad example
    1. In the Command field, enter the following command: cmd.exe /d /c powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -NoProfile -File OpenNotepadAsUser.ps1 $1

    2. Verify that Launch this package command in a process group is not selected.

    3. Click Add File and upload the OpenNotepadAsUser.ps1 file.

    4. Click Add Parameter > Text Input.

    5. In the Label field, enter USER_SID.

    6. In the Options list, select Provide Default Value and then enter PARAM_USER_SID. Click Save.

      Important: This specific parameter placeholder, PARAM_USER_SID, is replaced with the actual user security identifier (SID) at runtime only when run as a remediation task through Engage. If you want to use this package outside of Engage, you need to manually provide the actual identifier value.
  4. Choose this package when you create your remediation task. For more information, see Create remediation task.

Sample: (Windows with PowerShell Script) Create remediation package that runs as user

Use this sample to create a task that runs as the user answering the survey on a Windows endpoint. This script uses the TaniumRunAsUser.exe utility that ships with the Engage tools.

  1. This sample script runs a PowerShell script in the user context on the endpoint. Create the RunPowershellScriptAsUser.ps1 file and paste the following code into the file.

    RunPowershellScriptAsUser.ps1

    JAVASCRIPT
    param ( 
        # The SID of the user 
        [Parameter(Position = 0, Mandatory = $true)] 
        [string]$UserSID 
    ) 
     
    $UserSID = [system.uri]::UnescapeDataString( $UserSID ) 
     
    function Get-SessionFromSid( [string] $UserSID) { 
        # Assume that the user has explorer.exe running 
        foreach ( $process in (Get-CimInstance Win32_Process -filter "name = 'explorer.exe'")) { 
            $owners = (Invoke-CimMethod -InputObject $process -MethodName GetOwnerSid) 
            foreach ($owner in (Where-Object -InputObject $owners -Property ReturnValue -EQ 0)) { 
                if ($UserSID -eq $owner.SID) { 
                    return $process.SessionId 
                } 
            } 
        } 
    } 
     
    # you should check that this is not $null and exit gracefully 
    $sessionId = Get-SessionFromSid $UserSID 
    if ($sessionId -eq $null) {  
        Write-Error "Could not find session for user SID: $UserSID"  
        exit 1  
    } 
     
    # Take note of the extra quotes around the inner command 
    $command = "powershell.exe -NoProfile -ExecutionPolicy bypass -File .\TestPowerShellScript.ps1" 
    
    # Note: /sessionid=<value> is one group
    #       /cmd is one group, and has more quotes around $command 
    #       /userenv ensures that we will load the user's environment variables 
    $arguments = ("/noconsole", "/wrap", "/userenv", "/sessionid=$sessionId", "/cmd ""$command""") 
     
    $fileName = "$Env:TANIUM_CLIENT_ROOT\Tools\Engage\tasks\TaniumRunAsUser.exe" 
    Start-Process -FilePath $fileName -ArgumentList $arguments
    Important:

    Follow these guidelines in your script to prevent potential security issues, such as privilege escalation or malicious code execution:

    • The TaniumRunAsUser.exe file should be run from the default Tanium Client path, at: <Tanium Client>\Tools\Engage\tasks\TaniumRunAsUser.exe. Use the path exactly as it is provided in the RunPowershellScriptAsUser.ps1 code sample.

    • Any commands that run from within your package file should run from explicitly specified paths that are not writable by non-admin users. For example, the following command includes a path that is not writable:  "<Tanium Client>\Tools\Engage\tasks\TaniumRunAsUser.exe" /noconsole /wrap /userenv /sessionid= /cmd "cmd.exe /d /c start "non\user\writable\path\TARGET_PROCESS"

    • If the TaniumRunAsUser.exe command is run with the /userenv switch, environment variables that are referenced from within the TARGET_PROCESS resolve to the target user’s environment variables. Avoid executing scripts or executable files from within the TARGET_PROCESS using an unreliable path. A path that references user environment variables can lead to execution of unintended files.

    • The self-authored package file code should validate package parameters before appending them directly to other commands.

  2. In the RunPowershellScriptAsUser.ps1 file, replace the command variable RunPowershellScriptAsUser.ps1 with your PowerShell script file.

  3. Create the package in Tanium Console. From the Main menu, go to Administration > Packages > New Package.

  4. Enter the package details.

    Remediation package details for the Windows with PowerShell Script example
    1. In the Command field, enter the following command: cmd.exe /d /c powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NonInteractive -NoProfile -File RunPowershellScriptAsUser.ps1 $1

    2. Verify that Launch this package command in a process group is not selected.

    3. Click Add File and upload the RunPowershellScriptAsUser.ps1 file.

    4. Click Add File and upload your PowerShell script file.

    5. Click Add Parameter > Text Input.

    6. In the Label field, enter USER_SID.

    7. In the Options list, select Provide Default Value and then enter PARAM_USER_SID. Click Save.

      Important: This specific parameter placeholder, PARAM_USER_SID, is replaced with the actual user security identifier (SID) at runtime only when run as a remediation task through Engage. If you want to use this package outside of Engage, you need to manually provide the actual identifier value.
  5. Choose this package when you create your remediation task. For more information, see Create remediation task.

Sample: (macOS with Shell Script and TXT File) Create remediation package that runs as user

Use this sample to create a task that runs as the user answering the survey on a macOS endpoint.

  1. This sample script writes the user’s home directory to a text file. Create the run-as-user-sample.sh file and paste the following code into the file:

    run-as-user-sample.sh

    CODE
    #!/bin/sh  
    #@INCLUDE=i18n/UTF8Decode.sh  
    #@START_INCLUDES_HERE  
     
    user_id=$(utf8decode "$1")  
    username=$(utf8decode "$2")  
     
    launchctl asuser ${user_id} sudo -Hu ${username} /bin/sh -c 'echo $HOME >> $HOME/echoed.txt'
  2. Create the package in Tanium Console. From the Main menu, go toAdministration > Packages > New Package.

  3. Enter the package details.

    Remediation package details for the macOS with Shell Script and TXT File example
    1. In the Command field, enter the following command: /bin/sh run-as-user-sample.sh $1 $2

    2. Verify that Launch this package command in a process group is not selected.

    3. Click Add File and upload the run-as-user-sample.sh file.

    4. Click Add Parameter > Text Input to define the first input, $1.

    5. In the Label field, enter User ID.

    6. In the Options list, select Provide Default Value and then enter PARAM_USER_ID.

    7. ClickAdd Parameter > Text Input to define the second input, $2.

    8. In the Label field, enter Username.

    9. In the Options list, select Provide Default Value and then enter PARAM_USER_NAME. Click Save.

      Important: The specific parameter placeholders, PARAM_USER_ID and PARAM_USER_NAME, are replaced with the actual user identifier and username at runtime only when run as a remediation task through Engage. If you want to use this package outside of Engage, you need to manually provide the actual values for the user identifier and username.
  4. Choose this package when you create your remediation task. For more information, see Create remediation task.

Sample: (macOS with Shell Script) Create remediation package that runs as user

Use this sample to create a task that runs as the user answering the survey on a macOS endpoint.

  1. This sample script runs a Shell script in the user context on the endpoint. Create the RunScriptAsUser.sh file and paste the following code into the file:

    RunScriptAsUser.sh

    JAVASCRIPT
    #!/bin/sh 
    
    awk_script=' 
    function hex_to_octal(hex) { 
    decimal=hex_to_decimal(hex) 
    return sprintf("\\0%03o", decimal) 
    } 
    
    function hex_to_decimal(value, result) { 
    for(j=1; j<=length(value); j++) { 
    result=(result*16) + HEX[substr(value, j, 1)] 
    } 
    return(result) 
    } 
    
    function convert(s) { 
    while(match(s, /%../)) { 
    encoded=substr(s, RSTART, RLENGTH) 
    sub(encoded, hex_to_octal(encoded), s) 
    } 
    return s 
    } 
    
    BEGIN { 
    HEX["0"] = 0 
    HEX["1"] = 1 
    HEX["2"] = 2 
    HEX["3"] = 3 
    HEX["4"] = 4 
    HEX["5"] = 5 
    HEX["6"] = 6 
    HEX["7"] = 7 
    HEX["8"] = 8 
    HEX["9"] = 9 
    HEX["a"] = 10 
    HEX["b"] = 11 
    HEX["c"] = 12 
    HEX["d"] = 13 
    HEX["e"] = 14 
    HEX["f"] = 15 
    HEX["A"] = 10 
    HEX["B"] = 11 
    HEX["C"] = 12 
    HEX["D"] = 13 
    HEX["E"] = 14 
    HEX["F"] = 15 
    } 
    
    { 
    printf("%s\n", convert($0)) 
    } 
    ' 
    
    usable_awk() { 
    if found=`command -v nawk`; then 
    echo "$found" 
    return 
    fi 
    
    if [ -x /usr/xpg4/bin/awk ]; then 
    echo /usr/xpg4/bin/awk 
    return 
    fi 
    
    command -v awk 
    } 
    
    utf8decode() { 
    awk_bin=`usable_awk` 
    printf "%b\n" "`echo "$1" | $awk_bin "$awk_script"`" 
    } 
    
    user_id=$(utf8decode "$1") 
    username=$(utf8decode "$2") 
    
    if [ -z ${username} ]; then 
    echo "No username specified." 
    usage 
    fi 
    
    if [ -z ${user_id} ]; then 
    echo "No user id specified." 
    usage 
    fi 
    
    launchctl asuser ${user_id} sudo -Hu ${username} /bin/sh ./TestScript.sh
  2. In the RunScriptAsUser.sh file, replace the command variable TestScript.sh with your Shell script file.

  3. Create the package in Tanium Console. From the Main menu, go toAdministration > Packages > New Package.

  4. Enter the package details.

    Remediation package details for the macOS with Shell Script example
    1. In the Command field, enter the following command: /bin/sh RunScriptAsUser.sh $1 $2

    2. Verify that Launch this package command in a process group is not selected.

    3. Click Add File and upload the RunScriptAsUser.sh file.

    4. Click Add File and upload your Shell script file.

    5. Click Add Parameter > Text Input to define the first input, $1.

    6. In the Label field, enter User ID.

    7. In the Options list, select Provide Default Value and then enter PARAM_USER_ID.

    8. ClickAdd Parameter > Text Input to define the second input, $2.

    9. In the Label field, enter Username.

    10. In the Options list, select Provide Default Value and then enter PARAM_USER_NAME. Click Save.

      Important: The specific parameter placeholders, PARAM_USER_ID and PARAM_USER_NAME, are replaced with the actual user identifier and username at runtime only when run as a remediation task through Engage. If you want to use this package outside of Engage, you need to manually provide the actual values for the user identifier and username.
  5. Choose this package when you create your remediation task. For more information, see Create remediation task.