Skip to content

Commit 02ea96e

Browse files
authored
Merge pull request #1537 from HXSecurity/beta
Beta
2 parents 9d89e83 + d7317b1 commit 02ea96e

File tree

238 files changed

+49585
-5390
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+49585
-5390
lines changed

.github/deploy/deploy-dongtai-server-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ spec:
337337
mountPath: /opt/dongtai/dongtai_conf/conf/config.ini
338338
subPath: config.ini
339339
env:
340-
- name: DONGTAI_CONCURRENCY
340+
- name: DONGTAI_CONCURRENCYW
341341
value: -P gevent --concurrency=10
342342
resources:
343343
limits:

.github/workflows/teststate.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ jobs:
296296
cp dongtai_conf/conf/config.ini.test dongtai_conf/conf/config.ini
297297
mkdir -p /tmp/logstash/report/{img,word,pdf,excel} && mkdir -p /tmp/iast_cache/package && mkdir -p /tmp/logstash/batchagent
298298
python3 ./deploy/docker/version_update.py || true
299-
pip install Cython==3.0.0a11
299+
pip install Cython==3.0.0b3
300300
python setup.py build_ext --inplace
301301
find . -name "*.so" | grep test | xargs rm
302302
coverage run --source='.' manage.py test
@@ -351,7 +351,8 @@ jobs:
351351
export DOC=TRUE
352352
mkdir -p /tmp/logstash/report/{img,word,pdf,excel} && mkdir -p /tmp/iast_cache/package && mkdir -p /tmp/logstash/batchagent
353353
python3 ./deploy/docker/version_update.py || true
354-
pip install Cython==3.0.0a11
354+
pip install Cython==3.0.0b3
355+
python setup.py build_ext --inplace
355356
python setup.py build_ext --inplace
356357
python3 manage.py updatedepartmenttoken
357358
python3 manage.py runserver 0.0.0.0:8000 > webapi.log &

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ celerybeat.pid
3232
*.mo
3333
*.o
3434
*.c
35+
*.prof

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.10-slim
1+
FROM python:3.10-slim-bullseye
22
ARG VERSION
33
ENV DEBIAN_FRONTEND=noninteractive
44
ENV LANG=en_US.UTF-8
@@ -7,10 +7,10 @@ ENV LANGUAGE=en_US.UTF-8
77
ENV TZ=Asia/Shanghai
88

99
RUN apt-get update -y \
10-
&& apt install -y gettext gcc make cmake libmariadb-dev curl libc6-dev unzip cron \
10+
&& apt install -y gettext gcc make cmake libmariadb-dev curl libc6-dev libxrender1 libxtst6 libxi6 unzip cron \
1111
fonts-wqy-microhei vim build-essential ninja-build cython3 pybind11-dev libre2-dev locales \
1212
# htop sysstat net-tools iproute2 procps lsof \
13-
openjdk-11-jdk \
13+
zip libjpeg62 \
1414
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen \
1515
&& ALIMARCH=`arch` && curl -L https://charts.dongtai.io/apk/${ALIMARCH}/wkhtmltopdf -o /usr/bin/wkhtmltopdf \
1616
&& chmod +x /usr/bin/wkhtmltopdf

Pipfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ idna = "==2.10"
2424
lxml = "==4.9.1"
2525
mysqlclient = "*"
2626
python-docx = "==0.8.11"
27-
requests = "==2.25.1"
27+
requests = "==2.31.0"
2828
six = "==1.15.0"
2929
urllib3 = "==1.26.5"
3030
xlwt = "==1.3.0"
3131
pyre2 = "~=0.3.6"
32-
celery = "==5.2.7"
32+
celery = "==5.3.0rc1"
3333
redis = "==4.4.4"
3434
openpyxl = "==3.0.9"
3535
id-validator = "==1.0.20"
@@ -50,8 +50,8 @@ packaging = "==21.3"
5050
docxtpl = "==0.16.0"
5151
docxcompose = "==1.3.4"
5252
django-elasticsearch-dsl = "==7.2.2"
53-
asyncio-gevent = "==0.2.1"
54-
gevent = "==21.12.0"
53+
#asyncio-gevent = "==0.2.1"
54+
gevent = "==22.10.2"
5555
ddt = "==1.6.0"
5656
boto3 = "==1.24.59"
5757
mypy = "==1.0.1"
@@ -69,14 +69,21 @@ botocore = "==1.27.91"
6969
setuptools = "==65.5.1"
7070
elasticsearch = "==7.17.7"
7171
django-mock-queries = "==v2.1.7"
72-
cryptography = "==39.0.1"
72+
cryptography = "==41.0.0"
7373
jsonschema = "==4.17.0"
7474
pillow = "==9.3.0"
7575
pyrsistent = "==0.19.1"
7676
pytz = "==2022.6"
7777
types-pyyaml = ">=6.0.12.2"
7878
uwsgi = "==2.0.21"
7979
marisa-trie = "==0.8.0"
80+
gunicorn = "==20.1.0"
81+
celery-singleton = "*"
82+
djangorestframework-dataclasses = "*"
83+
django-seriously = "*"
84+
dataclasses-json = "*"
85+
django-silk = "*"
86+
types-python-dateutil = "*"
8087

8188
[dev-packages]
8289

Pipfile.lock

Lines changed: 487 additions & 253 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README-zh.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## DongTai是什么?
1717

18-
DongTai是一款开源的被动式交互式安全测试(IAST)产品,通过动态hook和污点跟踪算法等实现**通用漏洞检测****多请求关联漏洞检测(包括但不限于越权漏洞、未授权访问)****第三方组件漏洞检测**等,目前支持Java、Python两种语言的应用漏洞检测
18+
洞态IAST是一款开源的交互式安全测试(IAST)产品,可通过被动插桩模式实现JAVA应用的通用漏洞及第三方组件漏洞的实时检测,非常适合在开发流水线的测试阶段使用
1919

2020
## 项目结构
2121

@@ -34,12 +34,12 @@ DongTai是一款开源的被动式交互式安全测试(IAST)产品,通过动
3434

3535
## 技术架构
3636

37-
"火线-洞态IAST"具有多个基础服务,包括:`DongTai-web``DongTai-webapi``DongTai-openapi``DongTai-engine``agent``DongTai-Base-Image``DongTai-Plugin-IDEA`,其中:
37+
"火线-洞态IAST"具有多个基础服务,包括:`DongTai-web``DongTai``agent``DongTai-Base-Image``DongTai-Plugin-IDEA`,其中:
3838

3939
- `DongTai-web`是DongTai的产品页面,用于处理用户与洞态的交互
40-
- `DongTai-webapi`负责处理用户的相关操作
41-
- `DongTai-openapi`用于处理`agent`上报的注册/心跳/调用方法/第三方组件/错误日志等数据,下发hook策略,下发探针控制指令等
42-
- `DongTai-engine`根据调用方法数据和污点跟踪算法分析HTTP/HTTPS/RPC请求中是否存在漏洞,同时负责其它相关的定时任务
40+
- `DongTai>>dongtai_web`负责处理用户的相关操作的API
41+
- `DongTai>>dongtai_protocol`用于处理`agent`上报的注册/心跳/调用方法/第三方组件/错误日志等数据,下发hook策略,下发探针控制指令等
42+
- `DongTai>>dongtai_engine` 根据调用方法数据和污点跟踪算法分析HTTP/HTTPS/RPC请求中是否存在漏洞,同时负责其它相关的定时任务
4343
- `agent`是DongTai的探针模块,包含不同编程语言的数据采集端,用于采集应用运行时的数据并上报至`DongTai-OpenAPI`服务
4444
- `DongTai-Base-Image`包含洞态运行时依赖的基础服务,包括:MySql、Redis
4545
- `DongTai-Plugin-IDEA`是Java探针对应的IDEA插件,可通过插件直接运行Java探针,直接在IDEA中检测漏洞

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
## About DongTai IAST
1717

18-
`DongTai IAST` is an open-source passive interactive security testing (IAST) product. It uses dynamic hooks and taint tracking algorithms to achieve **universal vulnerability detection** and **multiples request associated with vulnerability detection (including but not limited to unauthorized vulnerabilities, overpower vulnerabilities)**, **Third-party component vulnerability detection**, etc. Currently, applications in Java and Python are supported for vulnerability detection.
18+
`Dongtai IAST` is an open-source Interactive Application Security Testing (IAST) tool that enables real-time detection of common vulnerabilities in Java applications and third-party components through passive instrumentation. It is particularly suitable for use in the testing phase of the development pipeline.
1919

2020

2121
## Project structure
@@ -34,14 +34,14 @@
3434

3535
## Architecture
3636

37-
`DongTai IAST` has multiple basic services, including `DongTai-web`, `DongTai-webapi`, `DongTai-openapi`, `DongTai-engine`, `agent`, `DongTai-deploy`, `DongTai-Base-Image` and `DongTai-Plugin-IDEA`:
37+
`DongTai IAST` has multiple basic services, including `DongTai-web`, `DongTai``agent`, `DongTai-Base-Image` and `DongTai-Plugin-IDEA`:
3838

3939
- `DongTai-web` is the product page of DongTai, which is used to handle the interaction between users and cave states.
40-
- `DongTai-webapi` is responsible for handling user-related operations.
41-
- `DongTai-openapi` is used to process the registration/heartbeat/call method/third-party component/error log data reported by `agent`, issue hook strategy, issue probe control commands, etc.
42-
- `DongTai-engine` analyzes whether there are vulnerabilities in HTTP/HTTPS/RPC requests according to the calling method data and taint tracking algorithm, and is also responsible for other related timing tasks.
40+
- `DongTai>>dongtai_web` is responsible for handling user-related operations.
41+
- `DongTai>>dongtai_protocol` is used to process the registration/heartbeat/call method/third-party component/error log data reported by `agent`, issue hook strategy, issue probe control commands, etc.
42+
- `DongTai>>dongtai_engine` analyzes whether there are vulnerabilities in HTTP/HTTPS/RPC requests according to the calling method data and taint tracking algorithm, and is also responsible for other related timing tasks.
4343
- `agent` is a probe module of DongTai, including data collection terminals in different programming languages, used to collect data during application runtime and report to the `DongTai-OpenAPI` service.
44-
- `DongTai-deploy` is used for the deployment of DongTai IAST, including docker-compose single-node deployment, Kubernetes cluster deployment, etc. If you want a deployment plan, you can add features or contribute to the deployment plan.
44+
- `DongTai>>deploy` is used for the deployment of DongTai IAST, including docker-compose single-node deployment, Kubernetes cluster deployment, etc. If you want a deployment plan, you can add features or contribute to the deployment plan.
4545
- `DongTai-Base-Image` contains the basic services that DongTai depends on runtime, including MySql, Redis.
4646
- `DongTai-Plugin-IDEA` is the IDEA plug-in corresponding to the Java probe. You can run the Java probe directly through the plug-in and detect the vulnerabilities directly in IDEA.
4747

deploy/docker/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ elif [ "$1" = "worker-high-freq" ]; then
1515
elif [ "$1" = "worker-es" ]; then
1616
celery -A dongtai_conf worker -l info -Q dongtai-es-save-task $DONGTAI_CONCURRENCY -E --pidfile=
1717
elif [ "$1" = "worker-sca" ]; then
18-
celery -A dongtai_conf worker -l info -Q dongtai-sca-task $DONGTAI_CONCURRENCY -E --pidfile=
18+
celery -A dongtai_conf worker -l info -Q dongtai-sca-task,dongtai-api-route-handler $DONGTAI_CONCURRENCY -E --pidfile=
1919
elif [ "$1" = "worker-other" ]; then
2020
celery -A dongtai_conf worker -l info -X dongtai-periodic-task,dongtai-method-pool-scan,dongtai-replay-vul-scan,dongtai-sca-task $DONGTAI_CONCURRENCY -E --pidfile=
2121
elif [ "$1" = "beat" ]; then

dongtai_common/common/utils/__init__.py

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ def make_hash(obj):
4747
return hash(tuple(frozenset(new_obj.items())))
4848

4949

50-
def cached(function,
51-
random_range: tuple = (50, 100),
52-
use_celery_update: bool = False):
50+
def cached(
51+
function,
52+
random_range: tuple = (50, 100),
53+
use_celery_update: bool = False,
54+
cache_logic_none: bool = True,
55+
):
5356
"""Return a version of this function that caches its results for
5457
the time specified.
5558
@@ -70,17 +73,23 @@ def get_cache_or_call(*args, **kwargs):
7073
# the cache
7174
cache_key = make_hash(
7275
(function.__module__ + function.__name__, args, kwargs))
73-
cached_result = cache.get(cache_key)
76+
#cache_key = function.__module__ + function.__name__
77+
cached_result = cache.get(cache_key, "Not such key")
7478
if random_range:
7579
cache_time = random.randint(*random_range)
7680
if use_celery_update:
7781
function_flush.apply_async(args=(function.__module__,
7882
function.__name__, cache_time,
7983
tuple(args), kwargs))
80-
if cached_result is None:
84+
if cached_result == "Not such key":
8185
result = function(*args, **kwargs)
82-
cache.set(cache_key, result, cache_time)
86+
if cache_logic_none and result is None:
87+
cache.set(cache_key, result, cache_time)
88+
else:
89+
cache.set(cache_key, result, cache_time)
8390
return result
91+
elif cached_result is None:
92+
return cached_result
8493
else:
8594
return cached_result
8695

@@ -89,32 +98,50 @@ def get_cache_or_call(*args, **kwargs):
8998
return get_cache_or_call
9099

91100

92-
def cached_decorator(random_range, use_celery_update=False):
101+
def disable_cache(function, args=(), kwargs={}):
102+
cache_key = make_hash(
103+
(function.__module__ + function.__name__, args, kwargs))
104+
cache.delete(cache_key)
105+
106+
107+
def cached_decorator(random_range,
108+
use_celery_update=False,
109+
cache_logic_none=True):
93110

94111
def _noname(function):
95-
return cached(function,
96-
random_range,
97-
use_celery_update=use_celery_update)
112+
return cached(
113+
function,
114+
random_range,
115+
use_celery_update=use_celery_update,
116+
cache_logic_none=cache_logic_none,
117+
)
98118

99119
return _noname
100120

101121

122+
@cached_decorator(random_range=(60, 120), use_celery_update=False)
123+
def get_user_from_department_key(key):
124+
from dongtai_common.models.department import Department
125+
from dongtai_common.models.user import User
126+
from rest_framework import exceptions
127+
department = Department.objects.get(token=key)
128+
principal = User.objects.filter(pk=department.principal_id).first()
129+
user = principal if principal else User.objects.filter(pk=1).first()
130+
user.using_department = department
131+
return user
132+
102133
class DepartmentTokenAuthentication(TokenAuthentication):
103134

104135
keyword = 'Token GROUP'
105136
model = None
106137

107-
def authenticate_credentials(self, key):
138+
def auth_decodedenticate_credentials(self, key):
108139
from dongtai_common.models.department import Department
109140
from dongtai_common.models.user import User
110141
from rest_framework import exceptions
111-
model = Department
112142
try:
113-
department = model.objects.get(token=key)
114-
principal = User.objects.filter(pk=department.principal_id).first()
115-
user = principal if principal else User.objects.filter(pk=1).first()
116-
user.using_department = department
117-
except model.DoesNotExist:
143+
user = get_user_from_department_key(key)
144+
except Department.DoesNotExist:
118145
raise exceptions.AuthenticationFailed(_('Invalid token.'))
119146
return (user, key)
120147

@@ -125,4 +152,4 @@ def authenticate(self, request):
125152
return None
126153
token = auth.lower().replace(self.keyword.lower().encode(), b'',
127154
1).decode()
128-
return self.authenticate_credentials(token)
155+
return self.auth_decodedenticate_credentials(token)

0 commit comments

Comments
 (0)