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

Error The handle is invalid. #14

Closed
sarathkumar21 opened this issue Jan 4, 2022 · 14 comments
Closed

Error The handle is invalid. #14

sarathkumar21 opened this issue Jan 4, 2022 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@sarathkumar21
Copy link

C:\temp> runscript -CloudFile="SAFE: Falcon CAST Windows Scanner" -CommandLine=""

Note: .\cast scan -maxmem 50000000 -recursion 0 C:\

03:22:02 scan error: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\CloudFormationTemplateProject.zip read C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\CloudFormationTemplateProject.zip: The handle is invalid.

Windows Cast scanner exits

@sarathkumar21
Copy link
Author

Any update on this, please?

@bk-cs bk-cs self-assigned this Jan 5, 2022
@bk-cs bk-cs added the bug Something isn't working label Jan 5, 2022
@bk-cs
Copy link
Collaborator

bk-cs commented Jan 6, 2022

#6

This is not an issue with CAST, and is related to a change to the target file during the scan.

@bk-cs bk-cs closed this as completed Jan 6, 2022
@STmann1
Copy link

STmann1 commented Jan 20, 2022

I am also seeing the same issue.
The scan kicked off, spits out an error "...scan error: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplatesCache\VisualBasic\General\1033\PreTextTemplate.VisualBasic.zip read"

  1. scan stops.
  2. no json file is produced.

@rbcrwd
Copy link
Collaborator

rbcrwd commented Jan 20, 2022

The tool is not guaranteed to produce JSON if it has no findings. Please upload a copy of that precise file and I'll attempt to reproduce.

@rbcrwd rbcrwd reopened this Jan 20, 2022
@STmann1
Copy link

STmann1 commented Jan 20, 2022

shared the files with you.
Appreciate the help.

@rbcrwd
Copy link
Collaborator

rbcrwd commented Jan 21, 2022

@STmann1 I got the link to the private repo you made, and while I'd prefer the ZIP files just be attached to this bug, please at least upload them to that repo. You've pre-extracted them, which makes debugging the ZIP handling a little pointless.

@rbcrwd
Copy link
Collaborator

rbcrwd commented Jan 21, 2022

I've re-validated in the code, the "scan error: " printout does not terminate processing; no errors do, we go out of our way to continue scanning despite any errors.

We'll still try to get to the bottom of this error with this archive, but as written it is non-terminal. That does not exclude events like antivirus/antimalware killing the process.

@STmann1
Copy link

STmann1 commented Jan 22, 2022

I am not able to upload the zip files into github. Every time I try, it un unarchives it.

I can tell you that cast.exe terminates when that error occurs. Would really be surprised if the crowdstrike falcon agent is doing this.

@rbcrwd
Copy link
Collaborator

rbcrwd commented Jan 24, 2022

It's highly unlikely to be Falcon since part of our build process adds the binaries to the known-good corpus. Are you also running MS Defender, or any other AV? Would you also please post a screenshot of the prompt-to-prompt (or at least the final lines) output of CAST as well as its exit code so we can confirm it's terminating abnormally?

Finally - one trivial trick to prevent automated unwrapping of ZIP files is to password-protect them with something trivial, like infected.

@STmann1
Copy link

STmann1 commented Jan 28, 2022

I have uploaded the error and zip files with password.
Hoping you can figure out why are we seeing issues with this.

@rbcrwd rbcrwd assigned rbcrwd and unassigned bk-cs Jan 28, 2022
@rbcrwd
Copy link
Collaborator

rbcrwd commented Feb 2, 2022

@STmann1 I opened a ticket in the repo you shared detailing the issues with the submission, since I don't have another way to DM you.

Either way, please try to reproduce with v0.6.3. I'm starting to suspect that your file may actually be a directory - we'd allowed those to pass through to scanning code because errors didn't matter, but it's produced a lot of confusion so we are filtering off directories now.

@STmann1
Copy link

STmann1 commented Feb 4, 2022

version 0.6.3 works much better.
I have sent you my contact info.
Questions

  1. How can you run this on mass and get the results (regardless if it found anything or not) in a single location?
  2. How can you scan all drives? what is the switch for that?

@bk-cs
Copy link
Collaborator

bk-cs commented Feb 4, 2022

You can use Humio Community Edition as a way to consolidate the logs.

This repository contains various PowerShell scripts designed to work with CrowdStrike Falcon Real-time Response and Workflows using the script file and accompanying input and output Json files.

The run_cli_tool script will output the results of a cast.exe scan into a temporary directory, and the send_log script will collect files from that directory and send them to Humio.

If you have Falcon Insight and Real-time Response, you can create a custom IOA that watches for Json files in the temporary Rtr directory that is used by run_cli_tool.

Custom IOA

  • Rule Type: File Creation
  • File Path: .*\\windows\\system32\\drivers\\crowdstrike\\rtr\\.*\.json
  • File Type: Other

The general Real-time Response workflow would look like this:

put cast.exe
runscript -CloudFile="run_cli_tool" -CommandLine=```'{"Path":"C:\\cast.exe","ArgumentList":"scan C:\\","Delete":true}'```

Once the json file is written to that directory, the IOA will trigger (assuming the IOA has been properly assigned and applied to the device). You can use a Workflow to run the send_log script and output to your Humio instance. The script will delete the json files once transmission is complete.

Workflow

  • Trigger: New detection
  • Conditions: Platform is equal to Windows, Tactic is equal to Custom Intelligence, Technique is equal to Indicator of Attack, File path matches *\cast.exe
  • Action: Real-time Response - your_saved_script_name, Cloud https://cloud.community.humio.com, Token your_ingest_token

You'll leave the Path variable empty for the script action, because with the way Custom IOAs currently work, the Json file that gets created can't be passed to the workflow. The script compensates for this by looking for all json files in that Rtr directory.

@rbcrwd
Copy link
Collaborator

rbcrwd commented Feb 4, 2022

Aside from the excellent suggestions by @bk-cs, the question of how to collect the data is largely dependent on your environment and system administration practices. This tool was intended to be a wrench in your sysadmin toolbag, and was not developed as a standalone tool.

A few options:

  1. Redirect STDOUT to a consistent location on C:\ and collect it from individual hosts
  2. Redirect STDOUT to a file on a shared drive, named uniquely by host so as to prevent overwrite
  3. Wrap the tool in a powershell handler that POSTS the data to an internal webserver
  4. Send each line of STDOUT to the system log (if you have central collection

Bear in mind that the final stats output is to STDERR, not STDOUT, so we minimize mixing of JSON and non-structured data. If you wish to capture that stats output, you'll need to capture STDERR as well.

As far as scanning all drives on Windows, there is no such flag. You can, however, invoke CAST in such a way that it will scan each in turn, e.g.:

% .\cast.exe scan C:\ D:\ E:\ N:\

I work primarily in POSIX environments and have no way to test the above example, but it should work.

@rbcrwd rbcrwd closed this as completed Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants