aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy
diff options
context:
space:
mode:
authorisra17 <isra017@gmail.com>2015-07-13 17:07:39 -0400
committerisra17 <isra017@gmail.com>2015-07-13 18:11:14 -0400
commit471e196e085f4161cb0667e0b70a940cb1de67d2 (patch)
tree5a22df5930a452df4585323b2e7750eb1530a53a /libmproxy
parent2af2e60f1f2eea4e887bda69aea19a82f951a78f (diff)
downloadmitmproxy-471e196e085f4161cb0667e0b70a940cb1de67d2.tar.gz
mitmproxy-471e196e085f4161cb0667e0b70a940cb1de67d2.tar.bz2
mitmproxy-471e196e085f4161cb0667e0b70a940cb1de67d2.zip
Add ~src ~dst REGEX filters
This filter allow to match on the request source and destination address in the form of `<IP>:<Port>`. Also fixed the parsing grammar to add a `WordEnd` after each filter name. That way, `~src` doesn't match `~s` instead and keep the behavior consistent with `~hq` != `~h`.
Diffstat (limited to 'libmproxy')
-rw-r--r--libmproxy/filt.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/libmproxy/filt.py b/libmproxy/filt.py
index 1983586b..bd17a807 100644
--- a/libmproxy/filt.py
+++ b/libmproxy/filt.py
@@ -241,6 +241,19 @@ class FUrl(_Rex):
def __call__(self, f):
return re.search(self.expr, f.request.url)
+class FSrc(_Rex):
+ code = "src"
+ help = "Match source address"
+
+ def __call__(self, f):
+ return f.client_conn and re.search(self.expr, repr(f.client_conn.address))
+
+class FDst(_Rex):
+ code = "dst"
+ help = "Match destination address"
+
+ def __call__(self, f):
+ return f.server_conn and re.search(self.expr, repr(f.server_conn.address))
class _Int(_Action):
def __init__(self, num):
@@ -313,6 +326,8 @@ filt_rex = [
FRequestContentType,
FResponseContentType,
FContentType,
+ FSrc,
+ FDst,
]
filt_int = [
FCode
@@ -324,7 +339,7 @@ def _make():
# ones.
parts = []
for klass in filt_unary:
- f = pp.Literal("~%s" % klass.code)
+ f = pp.Literal("~%s" % klass.code) + pp.WordEnd()
f.setParseAction(klass.make)
parts.append(f)
@@ -333,12 +348,12 @@ def _make():
pp.QuotedString("\"", escChar='\\') |\
pp.QuotedString("'", escChar='\\')
for klass in filt_rex:
- f = pp.Literal("~%s" % klass.code) + rex.copy()
+ f = pp.Literal("~%s" % klass.code) + pp.WordEnd() + rex.copy()
f.setParseAction(klass.make)
parts.append(f)
for klass in filt_int:
- f = pp.Literal("~%s" % klass.code) + pp.Word(pp.nums)
+ f = pp.Literal("~%s" % klass.code) + pp.WordEnd() + pp.Word(pp.nums)
f.setParseAction(klass.make)
parts.append(f)