Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ BUG ] Receive commands generate index out of range errors even when successful #382

Open
TigerC10 opened this issue Feb 20, 2024 · 6 comments
Assignees
Labels
bug Something isn't working fix available Self-applied fix available in issue

Comments

@TigerC10
Copy link

TigerC10 commented Feb 20, 2024

Describe the bug
Executing Receive-FalconInstaller results in an ArgumentOutOfRangeException. However, the sensor installer is actually successfully downloaded!

To Reproduce

$sensorInfo=(Get-FalconInstaller -Filter "platform:'windows'" -Limit 1 -Detailed)
Receive-FalconInstaller -Id $sensorInfo.sha256 -Path "${Env:ProgramData}\CrowdStrike\WindowsSensor.exe" -Force 

Expected behavior
I do not expect the exception.

Environment (please complete the following information):

  • OS: Windows Server 2019
  • PowerShell: 5.1
  • PSFalcon: 2.2.6

Additional context
The sensor downloads successfully, it's just an odd error that pops out after the download is complete.

I cannot replicate the issue on PowerShell 7.1, it seems that something was introduced that makes PSFalcon incompatible with PowerShell 5.1. Since PS 5.1 is the default "Windows PowerShell", this is unfortunate.

Transcript content

VERBOSE: 02:15:03 [Receive-FalconInstaller] /sensors/entities/download-installer/v1:get
VERBOSE: 02:15:03 [ApiClient.Invoke] GET https://api.crowdstrike.com/sensors/entities/download-installer/v1?id=b04b4925643fdc0138aa715d054cfa25418c3ba4095a6e5a00e652f67fd958f0
VERBOSE: 02:15:03 [ApiClient.Invoke] Accept=application/octet-stream
VERBOSE: 02:15:03 [ApiClient.Invoke] Receiving ByteArray content...
VERBOSE: 02:15:03 [ApiClient.Invoke] Creating 'C:\ProgramData\CrowdStrike\WindowsSensor.exe'.
Invoke-Falcon : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
At C:\Program Files\WindowsPowerShell\Modules\PSFalcon\2.2.6\public\sensors.ps1:156 char:9
+         Invoke-Falcon @Param -UserInput $PSBoundParameters
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Invoke-Falcon], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Invoke-Falcon
@TigerC10 TigerC10 added the bug Something isn't working label Feb 20, 2024
@bk-cs
Copy link
Collaborator

bk-cs commented Feb 23, 2024

Thanks for the report! I've been looking at this one and I haven't tracked down where the error is popping up. Something is receiving an empty array when the download completes.

bk-cs added a commit that referenced this issue Feb 23, 2024
Issue #382: Removed output of successfully downloaded file information from `Invoke-Falcon` private function and relocated within the `Invoke()` class function to prevent `Index out of range error`
@bk-cs
Copy link
Collaborator

bk-cs commented Feb 23, 2024

I think I've tracked this down and relocated some internal functions to prevent the error from occurring. The changes will be present in the next release.

If you'd like to resolve it for your local module before release, you can replace public\Private.ps1 and class\Class.ps1 using the steps outlined below.

Import-Module -Name PSFalcon
$ModulePath = (Show-FalconModule).ModulePath
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/CrowdStrike/psfalcon/e60951774c23443ce7d3c7788c823d268c2a7fc1/private/Private.ps1 -UseBasicParsing).Content > (Join-Path (Join-Path $ModulePath private) Private.ps1)
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/CrowdStrike/psfalcon/e60951774c23443ce7d3c7788c823d268c2a7fc1/class/Class.ps1 -UseBasicParsing).Content > (Join-Path (Join-Path $ModulePath class) Class.ps1)

You will need to fully close and re-open PowerShell, re-import PSFalcon and re-request your token before testing the change.

I'll leave this issue open for other users to apply this fix before the next release.

@bk-cs bk-cs changed the title [ BUG ] Receive-FalconInstaller Outputs Error "Index was out of range" [ BUG ] Receive commands generate index out of range errors even when successful Feb 23, 2024
@bk-cs bk-cs added the fix available Self-applied fix available in issue label Feb 27, 2024
@jnichols35
Copy link

@bk-cs thanks for a fix to this, I was banging my head against the wall last night trying to figure out what I was doing wrong.

Do you have an ETA for a new release?

@bk-cs
Copy link
Collaborator

bk-cs commented Feb 28, 2024

Do you have an ETA for a new release?

Not yet. There have been several new API releases and I'm behind on adding them. I'm continuing it work on it and will put out the release as soon as I can. My hope is that including fixes in individual issues can fix problems and relieve some of the pressure to get the release out. 😄

@dimasix9
Copy link

dimasix9 commented May 3, 2024

@bk-cs hi
I have a similar error. It is related to the real-time-response.ps1 file . So it cannot be resolved with your aforementioned solution.

Invoke-Falcon : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
At C:\Users\{username}\Documents\WindowsPowerShell\Modules\PSFalcon\2.2.6\public\real-time-response.ps1:614 char:31
+ ... Request in (Invoke-Falcon @Param -Endpoint $Endpoint -UserInput $PSBo ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Invoke-Falcon], ArgumentOutOfRangeException
    + FullyQualifiedErrorId : System.ArgumentOutOfRangeException,Invoke-Falcon

P.S. I got that it helped a guy with the same problem at another issue thread #398 but for me it doesn't work :(

@bk-cs
Copy link
Collaborator

bk-cs commented May 3, 2024

@bk-cs hi I have a similar error. It is related to the real-time-response.ps1 file . So it cannot be resolved with your aforementioned solution.

P.S. I got that it helped a guy with the same problem at another issue thread #398 but for me it doesn't work :(

Did you restart PowerShell after applying that fix? Did you verify that the targeted files were updated?

Usually the error is generated by a function that is called by all the PSFalcon commands--it shouldn't be specific to a file in the public folder (like real-time-response.ps1). The error points to that file because that's the initial command that led to the error, but the error itself happens in a different function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix available Self-applied fix available in issue
Projects
None yet
Development

No branches or pull requests

4 participants