Skip to content

Registration verification check in Test-Installation never detects successful registration (wrong match string + static log window) #154

Open

Description

@dbachen-dt

The registration-verification loop in Test-Installation produces a false "did not register" warning even when the agent registers successfully. Two independent bugs, either of which alone would cause this:

$didAgentRegister = $false
for ($i = 0; $i -le 40; $i++) {
    if (Test-Path "$($HuntressDirectory)\HuntressAgent.log") {
        $linesFromLog = Get-Content "$($HuntressDirectory)\HuntressAgent.log" | Select-Object -first 4
        ForEach ($line in $linesFromLog) {
            if ($line -like "*Huntress agent registered*") {
                LogMessage "Agent successfully registered in $($i/4) seconds"
                $didAgentRegister = $true
                Start-Sleep -Milliseconds 250
                $i=100
            }
        }
    }
    Start-Sleep -Milliseconds 250
}
if ( ! $didAgentRegister) {
    $err = "WARNING: It does not appear the agent has successfully registered. Check 3rd party AV exclusion lists to ensure Huntress is excluded."
    LogMessage ($err + $SupportMessage)
}

Bug 1 — match string doesn't exist in current log output. The check looks for the literal substring Huntress agent registered. Current agent versions log structured JSON instead, with a message like:

{"level":"info","time":"2026-07-30T13:20:12-04:00","message":"registered agent#17645331 with portal in 1.0627451s"}

That string never contains Huntress agent registered, so the condition can never be true against present-day log output regardless of whether registration actually succeeded.

Bug 2 — the read window is static and never advances. Select-Object -first 4 reads the same first 4 lines of the file on every iteration of the loop (all 40 passes, every 250ms). It never looks further into the file and never tracks what's already been read. In a real log, registration-related lines commonly land past line 4 — in one capture, the registration confirmation was line 8, preceded by service-configuration and Rio-path warning lines:

1  configuring HuntressAgent service
2  unable to open HKLM\SOFTWARE\Huntress Labs\Huntress: ...
3  Rio.exe version: fork/exec ... path not found
4  unable to open HKLM\SOFTWARE\Huntress Labs\Huntress: ...
5  registering HuntressAgent service
6  Rio.exe version: fork/exec ... path not found
7  registration data: {...}
8  registered agent#17645331 with portal in 1.0627451s

Since the loop only ever inspects lines 1-4, it structurally cannot see line 8 no matter how many of the 40 iterations run. This is independent of bug 1 — fixing only the match string would still fail here, and fixing only the window would still fail on the wording mismatch.

Impact: The install script logs a spurious "It does not appear the agent has successfully registered... Check 3rd party AV exclusion lists" warning on every install, even fully successful ones, which is misleading during troubleshooting and could send techs chasing AV exclusions on machines that registered fine.

Suggested fix: Update the match to the current structured log format (e.g. match on "registered agent# or parse the JSON and check the message field), and replace Select-Object -first 4 with a tail-based read (Get-Content -Tail N, or track byte/line offset across iterations) so new lines appended during the wait are actually inspected rather than re-reading the same head of the file.

Activity

  1. dbachen-dt commented on Jul 30, 2026

    @dbachen-dt
    Author

    Add as a comment on the existing registration-verification issue

    While looking at this I found a second check in the same class — a condition that can never evaluate true, so the warning it guards is unreachable.

    logInfo, lines 858-864:

    if (Confirm-ServiceRunning $HuntressEDRServiceName){
        $checkTP = (Confirm-ServiceRunning $HuntressAgentServiceName)
        if ( $null -eq $checkTP ) {
            LogMessage "Warning: Tamper Protection may be enabled; you may need to disable TP or run this as SYSTEM to repair, upgrade, or reinstall this agent. `n"
        } else {
            LogMessage "Pass: Tamper Protection not detected, or this script is running as SYSTEM `n"
        }
    }

    Confirm-ServiceRunning returns a boolean on every code path — $false for a null/empty service name, $false when Get-Service returns nothing, $true when the status is running, $false otherwise. It never returns $null. So $null -eq $checkTP is always false, the warning branch is dead, and the script unconditionally logs the "Pass: Tamper Protection not detected" line whenever the Rio service is running.

    Two separate problems here:

    1. The $null comparison should presumably be a $false comparison, or the helper should return $null in some distinguishable case.
    2. The logic reads oddly regardless: it infers Tamper Protection state from the Agent service's running state, nested inside a check of the Rio service. Neither of those tells you whether TP is enabled. If the intent was to detect that a service query was blocked, that needs to be distinguished from "the service exists and is stopped," which the current helper collapses into the same $false.

    Grouping this with the registration check since the root cause is the same pattern — a verification branch that can't fire, producing log output that reads as a positive result without having verified anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions