Skip to content

Wrong Encoding of the MDE Query #480

@ererdfdfcvcv

Description

@ererdfdfcvcv

Hello,

the current Version of
main/msticpy/data/drivers/odata_driver.py
contains a wrong encoding within the request creation.

I tried to request some queries from a Microsoft Defender for Endpoint API, but all failed with HTTP 400 - Bad Request.
The following Code example shows the lines, which caused the error in my case. The query/body of the request is loaded as a string (line 251 of the file/script), but must be JSON encoded.
As a solution, I added the correct encoding of the body with the function json.dumps(),

Could you please take a look at the code and fix the error, if it is one? I am quite new to (semi-) professional coding and still a university student. Consequently, I am not 100% confident, that I am right about this problem.

Best Regards

---------- odata_driver.py code ----------

# Build request based on whether endpoint requires data to be passed in
# request body in or URL
body = None
if kwargs["body"] is True:
req_url = self.request_uri + kwargs["api_end"]
req_url = urllib.parse.quote(req_url, safe="%/:=&?~#+!$,;'@()*[]")
body = {"Query": query}
response = httpx.post(
url=req_url,
headers=self.req_headers,
content=str(body),
timeout=self.get_http_timeout(**kwargs),
)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions