Merge pull request #1949 from s4chin/add-src-dst-filters

web: Add ~src and ~dst filters
This commit is contained in:
Maximilian Hils 2017-01-23 21:22:21 +01:00 committed by GitHub
commit c512f095ae
2 changed files with 624 additions and 529 deletions

File diff suppressed because it is too large Load Diff

View File

@ -77,6 +77,16 @@ function domain(regex){
domainFilter.desc = "domain matches " + regex;
return domainFilter;
}
function destination(regex){
regex = new RegExp(regex, "i");
function destinationFilter(flow){
return (!!flow.server_conn.address)
&&
regex.test(flow.server_conn.address.address[0] + ":" + flow.server_conn.address.address[1]);
}
destinationFilter.desc = "destination address matches " + regex;
return destinationFilter;
}
function errorFilter(flow){
return !!flow.error;
}
@ -133,7 +143,16 @@ function responseFilter(flow){
return !!flow.response;
}
responseFilter.desc = "has response";
function source(regex){
regex = new RegExp(regex, "i");
function sourceFilter(flow){
return (!!flow.client_conn.address)
&&
regex.test(flow.client_conn.address.address[0] + ":" + flow.client_conn.address.address[1]);
}
sourceFilter.desc = "source address matches " + regex;
return sourceFilter;
}
function contentType(regex){
regex = new RegExp(regex, "i");
function contentTypeFilter(flow){
@ -205,36 +224,33 @@ BindingExpr
{ return binding(expr); }
/ Expr
/* All the filters except "~s" and "~src" are arranged in the ascending order as
given in the docs(http://docs.mitmproxy.org/en/latest/features/filters.html).
"~s" and "~src" are so arranged as "~s" caused problems in the evaluation of
"~src". */
Expr
= NullaryExpr
/ UnaryExpr
NullaryExpr
= BooleanLiteral
/ "~a" { return assetFilter; }
/ "~e" { return errorFilter; }
/ "~http" { return httpFilter; }
/ "~marked" { return markedFilter; }
/ "~q" { return noResponseFilter; }
/ "~s" { return responseFilter; }
/ "~tcp" { return tcpFilter; }
BooleanLiteral
= "true" { return trueFilter; }
/ "false" { return falseFilter; }
UnaryExpr
= "~c" ws+ s:IntegerLiteral { return responseCode(s); }
/ "~d" ws+ s:StringLiteral { return domain(s); }
/ "~h" ws+ s:StringLiteral { return header(s); }
/ "~a" { return assetFilter; }
/ "~c" ws+ s:IntegerLiteral { return responseCode(s); }
/ "~d" ws+ s:StringLiteral { return domain(s); }
/ "~dst" ws+ s:StringLiteral { return destination(s); }
/ "~e" { return errorFilter; }
/ "~h" ws+ s:StringLiteral { return header(s); }
/ "~hq" ws+ s:StringLiteral { return requestHeader(s); }
/ "~hs" ws+ s:StringLiteral { return responseHeader(s); }
/ "~m" ws+ s:StringLiteral { return method(s); }
/ "~t" ws+ s:StringLiteral { return contentType(s); }
/ "~http" { return httpFilter; }
/ "~m" ws+ s:StringLiteral { return method(s); }
/ "~marked" { return markedFilter; }
/ "~q" { return noResponseFilter; }
/ "~src" ws+ s:StringLiteral { return source(s); }
/ "~s" { return responseFilter; }
/ "~t" ws+ s:StringLiteral { return contentType(s); }
/ "~tcp" { return tcpFilter; }
/ "~tq" ws+ s:StringLiteral { return requestContentType(s); }
/ "~ts" ws+ s:StringLiteral { return responseContentType(s); }
/ "~u" ws+ s:StringLiteral { return url(s); }
/ "~u" ws+ s:StringLiteral { return url(s); }
/ s:StringLiteral { return url(s); }
IntegerLiteral "integer"