def create_process(self, command_string):
# process is:
# - create a temporary file name
# - create the process, writing output to a temporary file
# - wait for the process to complete
# - get the temporary file from the endpoint
# - delete the temporary file
randfile = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(12)])
workdir = 'c:\\windows\\carbonblack'
randfilename = '%s\\cblr.%s.tmp' % (workdir, randfile)
session_id = self.live_response_session
url = "%s/api/v1/cblr/session/%d/command" % (self.cb.server, session_id)
data = {"session_id": session_id, "name": "create process", "object": command_string,
"wait": True, "working_directory": workdir, "output_file": randfilename}
r = requests.post(url, headers=self.cb.token_header, data=json.dumps(data), verify=self.cb.ssl_verify,
timeout=120)
r.raise_for_status()
resp = r.json()
command_id = resp.get('id')
command_state = 'pending'
while command_state != 'complete':
time.sleep(.2)
resp = self.cb.live_response_session_command_get(session_id, command_id)
command_state = resp.get('status')
# now the file is ready to be read
file_content = self.get_file(randfilename)
# delete the file
self.cb.live_response_session_command_post(session_id, "delete file", randfilename)
return file_content
评论列表
文章目录