Pass parameters to PowerShell script using real time response #481
-
Hi team, How can i pass a value as parameter to batch_admin_command and then receive this value on PowerShell invoked script? I want to scan a specific path.
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 14 replies
-
Hi @hermanmaleiane - This question is similar to this one, so we can borrow his example. In this code segment, we're calling a previously uploaded CloudFile and then passing in a CommandLine for it to handle. (You can use Body Payload abstraction instead if you prefer.) BODY = {
"base_command": "runscript",
"command_string": "runscript -CloudFile=\"MyScriptName\" -CommandLine=\"\"",
"session_id": resource['session_id']
}
command_response = falcon_RTR_Session.RTR_ExecuteActiveResponderCommand(body=BODY)
print(json.dumps(command_response, indent=4)) As long as you know the name of the uploaded CloudFile, you should be able to do the same with RTR on single or multiple hosts. A couple of notes:
Let us know if you run into any questions! |
Beta Was this translation helpful? Give feedback.
-
Excellent! The Check out the following code (taken from here): def execute_command(passed_payload: str, hdr: str, cmd: str):
"""
Executes a RTR Admin command, waits for it to complete,
and then returns the result
"""
passed_payload["command_string"] = cmd
req = falcon_rtra.execute_admin_command( # Call the command
passed_payload # Execute the command
)
if req["status_code"] != 201: # Confirm execution success
raise SystemExit( # There is no retry, crash out
"%80s" % f"{' ' * 80}\nUnable to execute command: "
f"[{req['body']['errors'][0]['code']}] "
f"{req['body']['errors'][0]['message']}"
)
request_id = req["body"]["resources"][0]["cloud_request_id"] # Retrieve the cloud_request_id
completed = False # Boolean to track our command status
inform(f" Waiting on {hdr} to finish executing")
while not completed: # Keep requesting status until the command is completed
inform(
f" Waiting on {hdr} to finish executing...{get_indicator()}"
)
requested = falcon_rtra.check_admin_command_status( # Retrieve the results command
cloud_request_id=request_id, # Passing in the cloud_request_id
sequence_id=0 # Results are chunked, but we just need the first result
)
completed = requested["body"]["resources"][0]["complete"] # Check to see if our command has finished executing
inform(
f" Waiting on {hdr} to finish executing...done!" # Inform the user of success
)
time.sleep(.1)
return requested # Return our result The loop runs until the value of "complete" is returned back as a |
Beta Was this translation helpful? Give feedback.
-
Awesome, Thank you sir. |
Beta Was this translation helpful? Give feedback.
-
Hi @jshcodes !! I'm using this code to invoke the script and handle the time and if it's completed. `
The thing is, i am not able to see in the response when it completed and the result of the scan because it takes too much time. The other problem is that when i perform the scan using PowerShell directly on my machine it doesn't display nothing, maybe this behavior is because i don't have threats. |
Beta Was this translation helpful? Give feedback.
-
Hi @jshcodes!! I was forgetting to test the command line option as you explained on your first reply. command="Get-MpThreat -ThreatID 2147750106" status_cod:400 With runscript -CloudFile, using the script deployed on crowdstrike console works fine. |
Beta Was this translation helpful? Give feedback.
Hi @hermanmaleiane -
This question is similar to this one, so we can borrow his example.
In this code segment, we're calling a previously uploaded CloudFile and then passing in a CommandLine for it to handle. (You can use Body Payload abstraction instead if you prefer.)
As long as you know the name of the uploaded CloudFile, you should be able to do the same with RTR on single or multiple hosts.
A …