Want to push the mitmdump to azure blob storage #6101
satishkumarnk-create
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As a requirement, i want to push the capture mitmdump to azure blob storage. I am using the below code. But getting error as "in script .\log_azureblob.py: ('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000256D5BF62D0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, BlobType
from mitmproxy import http, flowfilter,ctx
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
if not blob_client.exists():
# if the blob doesn't exist, create it with some initial data
initial_data = b'Initial data for the blob'
blob_client.upload_blob(initial_data)
def start():
# set up the logger
ctx.log.info("BlobLogger started.")
def request(flow):
# get the request data and append it to the blob
request_data = f"{flow.request.method} {flow.request.url} HTTP/1.1\n"
for name, value in flow.request.headers.items():
request_data += f"{name}: {value}\n"
request_data += "\n" # add a blank line between the headers and body
if flow.request.content:
request_data += flow.request.content.decode("utf-8") + "\n"
def response(flow):
# get the response data and append it to the blob
response_data = f"HTTP/1.1 {flow.response.status_code} {flow.response.reason}\n"
for name, value in flow.response.headers.items():
response_data += f"{name}: {value}\n"
response_data += "\n" # add a blank line between the headers and body
if flow.response.content:
response_data += flow.response.content.decode("utf-8") + "\n"
def done():
# clean up the logger
ctx.log.info("BlobLogger stopped.")
Beta Was this translation helpful? Give feedback.
All reactions