{"id":19522342,"url":"https://github.com/hxsecurity/dongtai-agent-python","last_synced_at":"2025-06-22T12:09:30.459Z","repository":{"id":38353244,"uuid":"350202730","full_name":"HXSecurity/DongTai-agent-python","owner":"HXSecurity","description":"Python Agent is a Python application probe of DongTai IAST, which collects method invocation data during runtime of Python application by dynamic hooks.","archived":false,"fork":false,"pushed_at":"2022-06-06T10:40:18.000Z","size":914,"stargazers_count":23,"open_issues_count":3,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-26T09:35:14.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dongtai.io","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HXSecurity.png","metadata":{"files":{"readme":"README.ZH_CN.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-22T04:07:32.000Z","updated_at":"2024-12-20T12:25:10.000Z","dependencies_parsed_at":"2022-08-25T01:31:40.176Z","dependency_job_id":null,"html_url":"https://github.com/HXSecurity/DongTai-agent-python","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/HXSecurity/DongTai-agent-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HXSecurity%2FDongTai-agent-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HXSecurity%2FDongTai-agent-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HXSecurity%2FDongTai-agent-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HXSecurity%2FDongTai-agent-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HXSecurity","download_url":"https://codeload.github.com/HXSecurity/DongTai-agent-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HXSecurity%2FDongTai-agent-python/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261289430,"owners_count":23136071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T00:38:33.459Z","updated_at":"2025-06-22T12:09:25.443Z","avatar_url":"https://github.com/HXSecurity.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"## DongTai-agent-python\n\n[![dongtai-project](https://img.shields.io/github/v/release/HXSecurity/DongTai?label=DongTai)](https://github.com/HXSecurity/DongTai/releases)\n[![dongtai--agent--python](https://img.shields.io/github/v/release/HXSecurity/DongTai-agent-python?label=DongTai-agent-python)](https://github.com/HXSecurity/DongTai-agent-python/releases)\n\n- [English document](README.md)\n\n## 项目介绍\n\nDongTai-agent-python 是 **洞态IAST** 针对 Python 应用开发的数据采集端。在 Python 应用中，通过改写方法和函数的方式采集所需数据，然后将数据发送至\nDongTai OpenAPI 服务，再由云端引擎处理数据判断是否存在安全漏洞。\n\nDongTai-agent-python\n\n- `dongtai_agent_python/api/` 将 agent 采集的数据上报至 DongTai OpenAPI 服务。\n- `dongtai_agent_python/assess/` 根据云端策略 hook python 方法。\n- `dongtai_agent_python/assess_ext/` 根据云端策略 hook cpython 底层方法。\n- `dongtai_agent_python/cli/` 控制 agent 版本的热更新。\n- `dongtai_agent_python/context/` 请求上下文和上下文跟踪。\n- `dongtai_agent_python/middleware/` 用于接入不同的 python 框架，目前支持 Django、Flask, 均以中间件方式引入。\n- `dongtai_agent_python/policy/` 策略规则及污点数据处理。\n- `dongtai_agent_python/setting/` Agent 配置.\n- `dongtai_agent_python/config.json` 用于配置 DongTai OpenAPI 服务地址、Token、项目名称等。\n\n## 应用场景\n\n- DevOps流程\n- 上线前安全测试\n- 第三方组件管理\n- 代码审计\n- 0 Day挖掘\n\n## 系统依赖\n\n* Python: \u003e=3.6\n* CPython\n* 编译依赖 (Agent 版本 \u003e= 1.1.4)\n  * gcc (Linux/macOS)\n  * make (Linux/macOS)\n  * cmake \u003e= 3.6\n  * Visual Studio (Windows)\n  * bash (Alpine Linux)\t\n  * libc-dev (Alpine Linux)\n  * linux-headers (Alpine Linux)\n* Web 框架\n  * Django: 3.0-3.2, 4.0\n  * Flask: 1.0-1.2, 2.0\n* Python 依赖包\n  * psutil: \u003e= 5.8.0\n  * requests: \u003e= 2.25.1\n  * pip: \u003e= 19.2.3\n\n## 快速上手\n\n### 快速使用\n\n请参考：[快速开始](https://doc.dongtai.io/02_start/index.html)\n\n### 快速开发\n\n1. Fork [DongTai-agent-python](https://github.com/HXSecurity/DongTai-agent-python) 项目到自己的 github 仓库并 clone 项目：\n    ```shell\n    git clone https://github.com/\u003cyour-username\u003e/DongTai-agent-python\n    ```\n2. 根据需求编写代码\n3. 修改配置文件 `dongtai_agent_python/config.json`\n    * iast.server.token: \"3d6bb430bc3e0b20dcc2d00000000000000a\"\n    * iast.server.url: \"https://iast-test.huoxian.cn/openapi\"\n    * project.name: \"DemoProjectName\"\n   \u003e url 与 token 从洞态 IAST-web 页面(eg: https://iast-test.huoxian.cn/deploy) \u003e python-agent 部署页面,下载 agent 的 shell 命令中获取，分别替换 url 域名与 token\n4. 项目打包，在agent项目根目录执行\n    ```shell\n    python3 setup.py sdist\n    ```\n5. 安装探针 \\\n   打包后会生成 dist 目录，在 dist 目录下找到安装包，将 dongtai_agent_python.tar.gz 安装包放入 Web 服务器所在机器上，执行 pip 安装\n    ```shell\n    pip3 install ./dongtai-python-agent.tar.gz \n    ```\n\n## 项目接入探针\n\n### 探针配置\n\n#### 环境变量\n\n* 开启调试: `DEBUG=1`\n* 自动创建项目: `AUTO_CREATE_PROJECT=1`\n* 项目名称: `PROJECT_NAME=Demo`\n* 项目版本: `PROJECT_VERSION=v1.0`\n* Agent 名称: `ENGINE_NAME=test-flask`\n* 日志文件路径: `LOG_PATH=/tmp/dongtai-agent-python.log`\n\n也可以配置 `dongtai_agent_python/config.json` 中相关的配置项，同样生效\n\n* `debug`\n* `project.name`\n* `project.version`\n* `engine.name`\n* `log.log_path`\n\n\u003e **注意: 环境变量的配置优先级高于配置文件**\n\n### Django\n\n1. 进入app的主目录\n2. 打开 `app/settings.py` 文件，找到 `MIDDLEWARE` 所在行\n3. 在该行的下面插入 `dongtai_agent_python.middlewares.django_middleware.FireMiddleware`\n4. 重启 app\n\n### Flask\n\n1. 修改项目的入口文件(如 app.py), 增加如下内容\n    ```python\n    app = Flask(__name__)\n\n    from dongtai_agent_python.middlewares.flask_middleware import AgentMiddleware\n    app.wsgi_app = AgentMiddleware(app.wsgi_app, app)\n\n    if __name__ == '__main__':\n        app.run()\n    ```\n2. 重启app\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhxsecurity%2Fdongtai-agent-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhxsecurity%2Fdongtai-agent-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhxsecurity%2Fdongtai-agent-python/lists"}