feat: add mitmproxy.md #60

This commit is contained in:
jaywcjlove 2022-11-20 18:56:07 +08:00
parent 99fe72ef73
commit 46d2f13e70
3 changed files with 275 additions and 0 deletions

View File

@ -132,6 +132,7 @@ Quick Reference
[Netstat](./docs/netstat.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[jq](./docs/jq.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));&class=tag&data-lang=JSON-->
[Lsof](./docs/lsof.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[Mitmproxy](./docs/mitmproxy.md)<!--rehype:style=background: rgb(4 92 135/var(\-\-bg\-opacity));-->
[Netcat](./docs/netcat.md)<!--rehype:style=background: rgb(4 92 135/var(\-\-bg\-opacity));-->
[Sed](./docs/sed.md)<!--rehype:style=background: rgb(16 185 129/var(\-\-bg\-opacity));-->
[OpenSSL](./docs/openssl.md)<!--rehype:style=background: rgb(114 20 18/var(\-\-bg\-opacity));-->

255
docs/mitmproxy.md Normal file
View File

@ -0,0 +1,255 @@
Mitmproxy 备忘清单
====
[Mitmproxy](https://mitmproxy.org/) 是一个免费开源的交互式 HTTPS 代理。这是 mitmproxy 的快速参考备忘单。
入门
-----
### 使用
<!--rehype:wrap-class=col-span-2-->
选项 | 范例 | 描述
:--|--|--
`-p` | mitmproxy -p 8001 | 在端口 `8001` 上启动代理
`-m` | mitmproxy -p 8001 -m reverse:<http://127.0.0.1:4000> | `8001` 端口反向代理到4000端口
`-w` | mitmproxy -p 8001 -w traffic.mitm | 流到达时流向文件
`-r` | mitmproxy -r traffic.mitm | 从文件中读取流
`-C` | mitmproxy -C traffic.mitm | 从保存的文件重放客户端请求
`-S` | mitmproxy -S traffic.mitm | 从保存的文件重放服务器响应
`-s` | mitmproxy -s myScript.py | 执行脚本
`-h` | mitmproxy -h | `mitmproxy` 快速帮助
### 移动
```markdown
k Ctrl b
▲ ▲▲
│ ││
h ◀ ─── + ─── ▶ l ││ page
│ ││
▼ ▼▼
j Ctrl f / Space
```
---
:---|---
:---|---
`h`, `j`, `k` ,`l` | 左、下、上、右
`Ctrl` `b` | 向上翻页
`Space` / `Ctrl` `f` | 向下翻页
`g` / `G` | 转到开头/结尾
`Arrows` | 上下左右
<!--rehype:className=shortcuts-->
### 安装
<!--rehype:wrap-class=col-span-2-->
- [mitmproxy 文档](https://docs.mitmproxy.org/stable/) _(mitmproxy.org)_
- [mitmproxy 开源仓库](https://github.com/mitmproxy/mitmproxy) _(github.com)_
---
```bash
$ brew install mitmproxy # macOS
```
### 流(视图)
<!--rehype:wrap-class=row-span-2-->
:---|---
:---|---
`A` | 恢复所有拦截的流
`D` | 重复流
`F` | 设置焦点跟随
`L` | 从文件加载流
`M` | 切换查看标记流
`S` | 开始服务器回放
`U` | 取消设置所有标记
`V` | 还原对此流的更改
`X` | 杀死这个流
`Z` | 清除所有未显示的流
`a` | 恢复此拦截流
`b` | 将响应主体保存到文件
`d` | 从视图中删除流
`e` | 将此流导出到文件
`f` | 设置视图过滤器
`m` | 在此流程上切换标记
`n` | 创建新流程
`o` | 设置流列表顺序
`r` | 重播此流程
`v` | 反向流列表顺序
`w` | 将列出的流程保存到文件
`\|` | 在此流上运行脚本
`Ctrl` `l` | 将剪辑发送到剪贴板
<!--rehype:className=shortcuts-->
### 常见的快捷键
:---|---
:---|---
`q` | 返回/退出
`z` | 清除流列表
`:` | 命令提示符
`E` | 查看事件日志
`O` | 查看选项
`r` | 重播此流程
`Tab` | 下一个
`Enter` | 选择
<!--rehype:className=shortcuts-->
### 全局键绑定
:---|---
:---|---
`-` | 循环到下一个布局
`?` | 查看帮助
`B` | 启动附加的浏览器
`C` | 查看命令
`I` | 切换拦截
`K` | 查看按键绑定
`P` | 查看流程详细信息
`Q` | 立即退出
`W` | 流式传输到文件
`i` | 设置拦截
`Ctrl` `right` | 聚焦下一个布局窗格
`Shift` `tab` | 聚焦下一个布局窗格
<!--rehype:className=shortcuts-->
Mitmproxy 过滤器
---------------
### 过滤器
:---|---
:---|---
`f` | 设置视图过滤器 _(在流视图页面上)_
<!--rehype:className=shortcuts-->
---
- [RegEX 备忘清单](./regex.md) _(jaywcjlove.github.io)_
正则表达式是 Python 风格的,可以指定为带引号的字符串
### 运算符
:---|---
:---|---
`!` | 一元非
`&` | 和
`\|` | 或者
`(...)` | 分组
### 表达式
<!--rehype:wrap-class=row-span-2-->
:---|---
:---|---
`~a` | 响应匹配资源CSS、Javascript、Flash、图像。
`~b` `regex` | 主体 Body
`~bq` `regex` | 请求正文
`~bs` `regex` | 响应体
`~c` `int` | HTTP 响应代码
`~d` `regex` | 域
`~dst` `regex` | 匹配目标地址
`~e` | 匹配错误
`~h` `regex` | 标头
`~hq` `regex` | 请求头
`~hs` `regex` | 响应头
`~http` | 匹配 HTTP 流
`~m` `regex` | 方法
`~marked` | 匹配标记流
`~q` | 匹配请求无响应
`~s` | 匹配响应
`~src` `regex` | 匹配源地址
`~t` `regex` | 内容类型标头
`~tcp` | 匹配 TCP 流
`~tq` `regex` | 请求 Content-Type 标头
`~ts` `regex` | 响应内容类型标头
`~u` `regex` | 网址
`~websocket` | 匹配 WebSocket 流(和 HTTP-WebSocket 握手流)
### 流选择器
表达式
:---|---
:---|---
`@all` | 所有流程
`@focus` | 目前关注的流程
`@shown` | 当前显示的所有流程
`@hidden` | 当前隐藏的所有流程
`@marked` | 所有标记流
`@unmarked` | 所有未标记的流
mitmproxy 有一组方便的流选择器,可以在当前视图上操作
### 示例
包含“google.com”的网址
```
google\.com
```
正文中包含字符串“test”的请求
```
~q ~b test
```
除了带有 text/html 内容类型的请求之外的任何内容:
```
!(~q & ~t "text/html")
```
替换请求中的整个 GET 字符串(需要引号才能使其工作):
```
":~q ~m GET:.*:/replacement.html"
```
Mitmproxy 脚本
-------
<!--rehype:body-class=cols-2-->
### Custom response
```python
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
if flow.request.pretty_url == "http://example.com/path":
flow.response = http.HTTPResponse.make(
200, # (optional) status code
b"Hello World", # (optional) content
{"Content-Type": "text/html"} # (optional) headers
)
```
从代理发送回复而不向远程服务器发送任何数据
### Add header
```python
class AddHeader:
def __init__(self):
self.num = 0
def response(self, flow):
self.num = self.num + 1
flow.response.headers["count"] = str(self.num)
addons = [
AddHeader()
]
```
为每个响应添加一个 HTTP 标头
另见
-------
- [mitmproxy addons](https://github.com/mitmproxy/mitmproxy/tree/master/examples/addons) _(github.com)_
- [mitmproxy 文档](https://docs.mitmproxy.org/stable/) _(mitmproxy.org)_
- [mitmproxy 开源仓库](https://github.com/mitmproxy/mitmproxy) _(github.com)_

View File

@ -0,0 +1,19 @@
<svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 209 204">
<g fill="none" fill-rule="evenodd" transform="translate(5 5.644)">
<path fill="#F15A29" fill-rule="nonzero" d="M114,96.3562512 C114,104.088251 107.732,110.356251 100,110.356251 C92.268,110.356251 86,104.088251 86,96.3562512 C86,88.6242512 92.268,82.3562512 100,82.3562512 C107.732,82.3562512 114,88.6242512 114,96.3562512 Z"/>
<path stroke="#F7941E" stroke-width="4" d="M119.5,96.3562512 C119.5,107.126251 110.77,115.856251 100,115.856251 C89.23,115.856251 80.5,107.126251 80.5,96.3562512 C80.5,85.5862512 89.23,76.8562512 100,76.8562512 C110.77,76.8562512 119.5,85.5862512 119.5,96.3562512 Z"/>
<g stroke="currentColor" stroke-width="10">
<path d="M130,96.3562512 C130,112.925251 116.569,126.356251 100,126.356251 C83.431,126.356251 70,112.925251 70,96.3562512 C70,79.7872512 83.431,66.3562512 100,66.3562512 C116.569,66.3562512 130,79.7872512 130,96.3562512 Z"/>
<path d="M167,24.3562512 C133.273,-4.80574879 84.314,-8.11674879 46.967,16.2392512 C9.62,40.5952512 -7.089,86.7342512 6,129.356251 L44,129.356251 C55.0860053,149.157715 75.6966688,161.743751 98.3755043,162.561006 C121.05434,163.378261 142.517468,152.308398 155,133.356251 M0,96.3562512 L70,96.3562512"/></g>
<path fill="#F7941E" fill-rule="nonzero" d="M164,125.356251 C164,128.66996 161.313708,131.356251 158,131.356251 C154.686292,131.356251 152,128.66996 152,125.356251 C152,122.042543 154.686292,119.356251 158,119.356251 C161.313708,119.356251 164,122.042543 164,125.356251 Z"/>
<path stroke="currentColor" stroke-width="3.2" d="M20,10 C20,15.523 15.523,20 10,20 C4.477,20 0,15.523 0,10 C0,4.477 4.477,0 10,0 C15.523,0 20,4.477 20,10 Z" transform="translate(148 115.356)"/>
<path fill="#F7941E" fill-rule="nonzero" d="M179,31.3562512 C179,34.6699597 176.313708,37.3562512 173,37.3562512 C169.686292,37.3562512 167,34.6699597 167,31.3562512 C167,28.0425427 169.686292,25.3562512 173,25.3562512 C176.313708,25.3562512 179,28.0425427 179,31.3562512 Z"/>
<g stroke="currentColor" transform="translate(33 21.356)">
<path stroke-width="3.2" d="M20,10 C20,15.523 15.523,20 10,20 C4.477,20 0,15.523 0,10 C0,4.477 4.477,0 10,0 C15.523,0 20,4.477 20,10 Z" transform="translate(130)"/>
<path stroke-width="10" d="M0,147 C33.727,176.162 82.686,179.473 120.033,155.117 C157.38,130.761 174.089,84.622 161,42 L123,42 C111.913995,22.1985361 91.3033312,9.61250069 68.6244957,8.79524536 C45.9456602,7.97799002 24.4825319,19.0478528 12,38 M167,75 L97,75"/></g>
<path fill="#F7941E" fill-rule="nonzero" d="M48,67.3562512 C48,70.6699597 45.3137085,73.3562512 42,73.3562512 C38.6862915,73.3562512 36,70.6699597 36,67.3562512 C36,64.0425427 38.6862915,61.3562512 42,61.3562512 C45.3137085,61.3562512 48,64.0425427 48,67.3562512 Z"/>
<path stroke="currentColor" stroke-width="3.2" d="M20,10 C20,15.523 15.523,20 10,20 C4.477,20 0,15.523 0,10 C0,4.477 4.477,0 10,0 C15.523,0 20,4.477 20,10 Z" transform="translate(32 57.356)"/>
<path fill="#F7941E" fill-rule="nonzero" d="M33,161.356251 C33,163.499845 31.8564065,165.480607 30,166.552404 C28.1435936,167.624201 25.8564064,167.624201 24,166.552404 C22.1435935,165.480607 21,163.499845 21,161.356251 C21,158.042543 23.6862915,155.356251 27,155.356251 C30.3137085,155.356251 33,158.042543 33,161.356251 L33,161.356251 Z"/>
<path stroke="currentColor" stroke-width="3.2" d="M20,10 C20,15.523 15.523,20 10,20 C4.477,20 0,15.523 0,10 C0,4.477 4.477,0 10,0 C15.523,0 20,4.477 20,10 Z" transform="translate(17 151.356)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB