live_response.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Splunk_CBER_App 作者: MHaggis 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号