mirror of https://github.com/citusdata/citus.git
WIP
parent
ebc3227dcb
commit
ca08ce82a5
|
@ -13,9 +13,9 @@ import traceback
|
||||||
import queue
|
import queue
|
||||||
|
|
||||||
from construct.lib import ListContainer
|
from construct.lib import ListContainer
|
||||||
from mitmproxy import ctx
|
from mitmproxy import ctx, tcp
|
||||||
from mitmproxy.utils import strutils
|
from mitmproxy.utils import strutils
|
||||||
from mitmproxy.proxy.protocol import TlsLayer, RawTCPLayer
|
from mitmproxy.proxy.layers import TCPLayer, ClientTLSLayer, ServerTLSLayer
|
||||||
|
|
||||||
import structs
|
import structs
|
||||||
|
|
||||||
|
@ -140,6 +140,8 @@ class KillHandler(Handler):
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
super().__init__(root)
|
super().__init__(root)
|
||||||
def _handle(self, flow, message):
|
def _handle(self, flow, message):
|
||||||
|
logging.debug("kill flow: %s", type(flow).__name__)
|
||||||
|
logging.debug("killable: %s", str(flow.killable))
|
||||||
flow.kill()
|
flow.kill()
|
||||||
return 'done'
|
return 'done'
|
||||||
|
|
||||||
|
@ -238,13 +240,18 @@ class OnPacket(Handler, ActionsMixin, FilterableMixin):
|
||||||
self.packet_kind = packet_kind
|
self.packet_kind = packet_kind
|
||||||
self.filters = kwargs
|
self.filters = kwargs
|
||||||
def _handle(self, flow, message):
|
def _handle(self, flow, message):
|
||||||
|
logging.debug("handler for %s", self.packet_kind)
|
||||||
|
|
||||||
if not message.parsed:
|
if not message.parsed:
|
||||||
# if this is the first message in the connection we just skip it
|
# if this is the first message in the connection we just skip it
|
||||||
return 'done'
|
return 'done'
|
||||||
for msg in message.parsed:
|
for msg in message.parsed:
|
||||||
typ = structs.message_type(msg, from_frontend=message.from_client)
|
typ = structs.message_type(msg, from_frontend=message.from_client)
|
||||||
|
logging.debug("%s == %s (%s)", typ, self.packet_kind, str(typ == self.packet_kind))
|
||||||
if typ == self.packet_kind:
|
if typ == self.packet_kind:
|
||||||
|
logging.debug("msg: %s", msg)
|
||||||
matches = structs.message_matches(msg, self.filters, message.from_client)
|
matches = structs.message_matches(msg, self.filters, message.from_client)
|
||||||
|
logging.debug("did we match: %s", str(matches))
|
||||||
if matches:
|
if matches:
|
||||||
return 'pass'
|
return 'pass'
|
||||||
return 'done'
|
return 'done'
|
||||||
|
@ -431,12 +438,12 @@ def next_layer(layer):
|
||||||
part where it creates the TlsLayer (it happens in root_context.py) and instead creates
|
part where it creates the TlsLayer (it happens in root_context.py) and instead creates
|
||||||
a RawTCPLayer. That's the layer which calls our tcp_message hook
|
a RawTCPLayer. That's the layer which calls our tcp_message hook
|
||||||
'''
|
'''
|
||||||
if isinstance(layer, TlsLayer):
|
if isinstance(layer, ClientTLSLayer) or isinstance(layer, ServerTLSLayer):
|
||||||
replacement = RawTCPLayer(layer.ctx)
|
replacement = TCPLayer(layer.ctx)
|
||||||
layer.reply.send(replacement)
|
layer.reply.send(replacement)
|
||||||
|
|
||||||
|
|
||||||
def tcp_message(flow):
|
def tcp_message(flow: tcp.TCPFlow):
|
||||||
'''
|
'''
|
||||||
This callback is hit every time mitmproxy receives a packet. It's the main entrypoint
|
This callback is hit every time mitmproxy receives a packet. It's the main entrypoint
|
||||||
into this script.
|
into this script.
|
||||||
|
|
|
@ -7,6 +7,7 @@ from construct import (
|
||||||
import construct.lib as cl
|
import construct.lib as cl
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
# For all possible message formats see:
|
# For all possible message formats see:
|
||||||
# https://www.postgresql.org/docs/current/protocol-message-formats.html
|
# https://www.postgresql.org/docs/current/protocol-message-formats.html
|
||||||
|
|
Loading…
Reference in New Issue