Skip to content

Commit 59096a0

Browse files
authored
Merge pull request #200 from exexute/main
Enhancement: fix dubbo vul check
2 parents acfb878 + 8f8bdde commit 59096a0

39 files changed

+403
-1366
lines changed

.github/workflows/code-check.yml

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -94,71 +94,10 @@ jobs:
9494
password: test
9595

9696
- name: OpenRASP-Vulns-Test
97-
run: |
98-
cd ..
99-
100-
echo "download apache-tomcat-8.5.0..."
101-
wget https://github.com/exexute/github_action_samples/releases/download/1.0.0/apache-tomcat-8.5.40.zip 1>/dev/null
102-
unzip apache-tomcat-8.5.40.zip 1>/dev/null
103-
104-
echo "copy dongtai agent java to tomcat..."
105-
cp DongTai-agent-java/release/iast-agent.jar apache-tomcat-8.5.40/iast/agent.jar
106-
cp DongTai-agent-java/release/lib/*.jar apache-tomcat-8.5.40/temp/
107-
cd apache-tomcat-8.5.40
108-
109-
echo "init mysql"
110-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "DROP DATABASE IF EXISTS test;"
111-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "CREATE DATABASE test;"
112-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "CREATE USER 'test'@'%' IDENTIFIED BY 'test';"
113-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;"
114-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "FLUSH PRIVILEGES;"
115-
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e 'show DATABASES;'
116-
117-
echo "start catalina and waitting 30s..."
118-
export JAVA_TOOL_OPTIONS="-Dproject.create=true -Dproject.version=${{ github.event_name }}-${{ github.run_number }}"
119-
./bin/startup.sh 2>/dev/null
120-
sleep 30
121-
122-
echo "start vulns spider..."
123-
./spider.sh
124-
125-
echo "waitting for send vuls data"
126-
sleep 120
127-
128-
echo "shutdown tomcat"
129-
PID=$(ps aux|grep "org.apache.catalina.startup.Bootstrap start"|grep -v grep |awk '{print $2}')
130-
echo "tomcat pid is: $PID"
131-
kill $PID
132-
ps aux
97+
run: bash .github/workflows/scripts/openrasp-test.sh
13398

13499
- name: Benchmark-Vulns-Test
135-
run: |
136-
cd ..
137-
git clone https://github.com/exexute/BenchmarkJava.git
138-
cd BenchmarkJava
139-
mvn clean package cargo:start -Pdeploywdongtai
140-
141-
cp ../DongTai-agent-java/release/iast-agent.jar tools/DongTai/dongtai.jar
142-
cp ../DongTai-agent-java/release/lib/*.jar target/cargo/installs/apache-tomcat-8.5.70/apache-tomcat-8.5.70/temp
143-
144-
echo "run benchmark in backend"
145-
export JAVA_TOOL_OPTIONS="-Dproject.create=true -Dproject.version=${{ github.event_name }}-${{ github.run_number }}"
146-
nohup mvn package cargo:run -Pdeploywdongtai &
147-
148-
echo "wait for benchmark start..."
149-
sleep 60
150-
151-
echo "build Crawler"
152-
git clone https://github.com/OWASP-Benchmark/BenchmarkUtils.git
153-
cd BenchmarkUtils
154-
mvn install
155-
156-
echo "run Crawler.sh"
157-
cd ..
158-
bash runCrawler.sh
159-
160-
echo "waiting for report upload..."
161-
sleep 3000
100+
run: bash .github/workflows/scripts/benchmark-test.sh
162101

163102

164103
Upload-To-OSS:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
echo "download benchmark source code"
4+
cd ..
5+
git clone https://github.com/exexute/BenchmarkJava.git
6+
cd BenchmarkJava
7+
8+
echo "build benchmark with dongtai"
9+
mvn clean package cargo:start -Pdeploywdongtai
10+
11+
echo "copy local package to temp directory"
12+
cp ../DongTai-agent-java/release/iast-agent.jar tools/DongTai/dongtai.jar
13+
cp ../DongTai-agent-java/release/lib/*.jar target/cargo/installs/apache-tomcat-8.5.70/apache-tomcat-8.5.70/temp
14+
15+
echo "run benchmark in backend"
16+
export JAVA_TOOL_OPTIONS="-Dproject.create=true -Dproject.version=${{ github.event_name }}-${{ github.run_number }}"
17+
nohup mvn package cargo:run -Pdeploywdongtai &
18+
19+
echo "wait for benchmark start..."
20+
sleep 60
21+
22+
echo "build Crawler"
23+
git clone https://github.com/OWASP-Benchmark/BenchmarkUtils.git
24+
cd BenchmarkUtils
25+
mvn install
26+
27+
echo "run Crawler.sh"
28+
cd ..
29+
bash runCrawler.sh
30+
31+
echo "waiting for report upload..."
32+
sleep 3000
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
cd ..
3+
4+
echo "download apache-tomcat-8.5.0..."
5+
wget https://github.com/exexute/github_action_samples/releases/download/1.0.0/apache-tomcat-8.5.40.zip 1>/dev/null
6+
unzip apache-tomcat-8.5.40.zip 1>/dev/null
7+
8+
echo "copy dongtai agent java to tomcat..."
9+
cp DongTai-agent-java/release/iast-agent.jar apache-tomcat-8.5.40/iast/agent.jar
10+
cp DongTai-agent-java/release/lib/*.jar apache-tomcat-8.5.40/temp/
11+
cd apache-tomcat-8.5.40
12+
13+
echo "init mysql"
14+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "DROP DATABASE IF EXISTS test;"
15+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "CREATE DATABASE test;"
16+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "CREATE USER 'test'@'%' IDENTIFIED BY 'test';"
17+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;"
18+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e "FLUSH PRIVILEGES;"
19+
mysql -uroot -pyuhjnbGYUI -h127.0.0.1 -e 'show DATABASES;'
20+
21+
echo "start catalina and waitting 30s..."
22+
export JAVA_TOOL_OPTIONS="-Dproject.create=true -Dproject.version=${{ github.event_name }}-${{ github.run_number }}"
23+
./bin/startup.sh 2>/dev/null
24+
25+
check_times=0
26+
while [ $check_times -lt 30 ];
27+
do
28+
echo 'checking openrasp api status'
29+
curl http://localhost:8080/vulns
30+
if [ "$?" == "0" ];then
31+
break
32+
else
33+
let check_times++
34+
echo "api status is down, retry $check_times times after 10s..."
35+
sleep 10
36+
fi
37+
done
38+
39+
40+
echo "start vulns spider..."
41+
./spider.sh
42+
43+
echo "waitting for send vuls data"
44+
sleep 120
45+
46+
echo "shutdown tomcat"
47+
PID=$(ps aux|grep "org.apache.catalina.startup.Bootstrap start"|grep -v grep |awk '{print $2}')
48+
echo "tomcat pid is: $PID"
49+
kill $PID
50+
ps aux

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ For more details see [Basic writing and formatting syntax](https://docs.github.c
3030

3131
### Jekyll Themes
3232

33-
Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/HXSecurity/DongTai-agent-java/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file.
33+
Your Pages site will use the layout and styles from the Jekyll theme. The name of this theme is saved in the Jekyll `_config.yml` configuration file.
3434

3535
### Support or Contact
3636

iast-core/src/main/java/com/secnium/iast/core/EngineManager.java

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import com.secnium.iast.core.handler.IastClassLoader;
55
import com.secnium.iast.core.handler.models.IastReplayModel;
66
import com.secnium.iast.core.handler.models.MethodEvent;
7-
import com.secnium.iast.core.middlewarerecognition.IastServer;
8-
import com.secnium.iast.core.middlewarerecognition.ServerDetect;
9-
import com.secnium.iast.core.threadlocalpool.BooleanTheadLocal;
7+
import com.secnium.iast.core.threadlocalpool.BooleanThreadLocal;
108
import com.secnium.iast.core.threadlocalpool.IastScopeTracker;
119
import com.secnium.iast.core.threadlocalpool.IastServerPort;
1210
import com.secnium.iast.core.threadlocalpool.IastTaintHashCodes;
@@ -37,16 +35,16 @@ public class EngineManager {
3735
public static Integer AGENT_ID;
3836
public static String AGENT_PATH;
3937

40-
private static final BooleanTheadLocal AGENT_STATUS = new BooleanTheadLocal(false);
41-
private static final BooleanTheadLocal TRANSFORM_STATE = new BooleanTheadLocal(false);
42-
private static final BooleanTheadLocal ENTER_HTTP_ENTRYPOINT = new BooleanTheadLocal(false);
38+
private static final BooleanThreadLocal AGENT_STATUS = new BooleanThreadLocal(false);
39+
private static final BooleanThreadLocal TRANSFORM_STATE = new BooleanThreadLocal(false);
40+
private static final BooleanThreadLocal ENTER_HTTP_ENTRYPOINT = new BooleanThreadLocal(false);
4341
public static final RequestContext REQUEST_CONTEXT = new RequestContext();
4442
public static final IastTrackMap TRACK_MAP = new IastTrackMap();
4543
public static final IastTaintPool TAINT_POOL = new IastTaintPool();
4644
public static final IastTaintHashCodes TAINT_HASH_CODES = new IastTaintHashCodes();
4745
public static final IastScopeTracker SCOPE_TRACKER = new IastScopeTracker();
4846
private static final IastServerPort LOGIN_LOGIC_WEIGHT = new IastServerPort();
49-
private static final BooleanTheadLocal LINGZHI_RUNNING = new BooleanTheadLocal(false);
47+
private static final BooleanThreadLocal LINGZHI_RUNNING = new BooleanThreadLocal(false);
5048
public static IastServer SERVER;
5149

5250
private static final ArrayBlockingQueue<IastReplayModel> REPLAY_QUEUE = new ArrayBlockingQueue<IastReplayModel>(
@@ -82,7 +80,8 @@ public static void turnOffLingzhi() {
8280
* @return
8381
*/
8482
public static Boolean isLingzhiRunning() {
85-
return LINGZHI_RUNNING.get() != null && LINGZHI_RUNNING.get();
83+
Boolean status = LINGZHI_RUNNING.get();
84+
return status != null && status;
8685
}
8786

8887
public static EngineManager getInstance() {
@@ -106,12 +105,6 @@ public static void setInstance() {
106105
private EngineManager(final PropertyUtils cfg,
107106
final Instrumentation inst) {
108107
this.cfg = cfg;
109-
110-
ServerDetect serverDetect = ServerDetect.getInstance();
111-
if (serverDetect.getWebserver() != null) {
112-
logger.info("WebServer [ name={}, path={} ]", serverDetect.getWebserver().getName(),
113-
serverDetect.getWebServerPath());
114-
}
115108
}
116109

117110
/**
@@ -263,45 +256,85 @@ public static void enterHttpEntry(Map<String, Object> requestMeta) {
263256
String newTraceId = ContextManager.getOrCreateGlobalTraceId(null, EngineManager.getAgentId());
264257
headers.put("dt-traceid", newTraceId);
265258
}
266-
ENTER_HTTP_ENTRYPOINT.enterHttpEntryPoint();
259+
ENTER_HTTP_ENTRYPOINT.enterEntry();
267260
REQUEST_CONTEXT.set(requestMeta);
268261
TRACK_MAP.set(new HashMap<Integer, MethodEvent>(1024));
269262
TAINT_POOL.set(new HashSet<Object>());
270263
TAINT_HASH_CODES.set(new HashSet<Integer>());
271264
}
272265

273266
/**
274-
*
275267
* @param dubboService
276268
* @param attachments
277-
* @since 1.1.4
269+
* @since 1.2.0
278270
*/
279271
public static void enterDubboEntry(String dubboService, Map<String, String> attachments) {
280272
if (attachments != null) {
281273
if (attachments.containsKey(ContextManager.getHeaderKey())) {
282-
ContextManager.getOrCreateGlobalTraceId(attachments.get(ContextManager.getHeaderKey()), EngineManager.getAgentId());
274+
ContextManager.getOrCreateGlobalTraceId(attachments.get(ContextManager.getHeaderKey()),
275+
EngineManager.getAgentId());
283276
} else {
284277
attachments.put(ContextManager.getHeaderKey(), ContextManager.getSegmentId());
285278
}
286279
}
287-
if(ENTER_HTTP_ENTRYPOINT.isEnterHttp()){
280+
if (ENTER_HTTP_ENTRYPOINT.isEnterEntry()) {
288281
return;
289282
}
283+
290284
// todo: register server
291-
ENTER_HTTP_ENTRYPOINT.enterHttpEntryPoint();
292-
// fixme: 保存请求信息
293-
//REQUEST_CONTEXT.set(attachments);
285+
if (attachments != null) {
286+
Map<String, String> requestHeaders = new HashMap<String, String>(attachments.size());
287+
for (Map.Entry<String, String> entry : attachments.entrySet()) {
288+
requestHeaders.put(entry.getKey(), entry.getValue());
289+
}
290+
Map<String, Object> requestMeta = new HashMap<String, Object>(12);
291+
requestMeta.put("protocol", "dubbo/" + requestHeaders.get("dubbo"));
292+
requestMeta.put("scheme", "dubbo");
293+
requestMeta.put("method", "RPC");
294+
requestMeta.put("secure", "true");
295+
requestMeta.put("requestURL", dubboService.split("\\?")[0]);
296+
requestMeta.put("requestURI", requestHeaders.get("path"));
297+
requestMeta.put("remoteAddr", "");
298+
requestMeta.put("queryString", "");
299+
requestMeta.put("headers", requestHeaders);
300+
requestMeta.put("body", "");
301+
requestMeta.put("contextPath", "");
302+
requestMeta.put("replay-request", false);
303+
304+
REQUEST_CONTEXT.set(requestMeta);
305+
}
306+
294307
TRACK_MAP.set(new HashMap<Integer, MethodEvent>(1024));
295308
TAINT_POOL.set(new HashSet<Object>());
296309
TAINT_HASH_CODES.set(new HashSet<Integer>());
297310
}
298311

299312
/**
300-
*
301313
* @return
302-
* @since 1.1.4
314+
* @since 1.2.0
315+
*/
316+
public static boolean isEnterHttp() {
317+
return ENTER_HTTP_ENTRYPOINT.isEnterEntry();
318+
}
319+
320+
/**
321+
* @since 1.2.0
322+
*/
323+
public static void leaveDubbo() {
324+
SCOPE_TRACKER.leaveDubbo();
325+
}
326+
327+
/**
328+
* @since 1.2.0
329+
*/
330+
public static boolean isExitedDubbo() {
331+
return SCOPE_TRACKER.isExitedDubbo();
332+
}
333+
334+
/**
335+
* @since 1.2.0
303336
*/
304-
public static boolean isEnterHttp(){
305-
return ENTER_HTTP_ENTRYPOINT.isEnterHttp();
337+
public static boolean isFirstLevelDubbo() {
338+
return SCOPE_TRACKER.isFirstLevelDubbo();
306339
}
307340
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.secnium.iast.core.middlewarerecognition;
1+
package com.secnium.iast.core;
22

33
public class IastServer {
44
private String serverAddr;

iast-core/src/main/java/com/secnium/iast/core/PropertyUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public boolean isNormalMode() {
247247
}
248248

249249
/**
250-
* After version 1.1.4, change the default server mode to local.
250+
* After version 1.2.0, change the default server mode to local.
251251
* @return server mode
252252
*/
253253
private String getServerMode() {

iast-core/src/main/java/com/secnium/iast/core/enhance/asm/AsmMethods.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static Method getAsmMethod(final Class<?> clazz,
197197
/**
198198
* asm method of {@link Injecter#enterDubbo(String)}
199199
*
200-
* @since 1.1.4
200+
* @since 1.2.0
201201
*/
202202
Method ASM_METHOD_Spy$enterDubbo = InnerHelper.getAsmMethod(
203203
Injecter.class,
@@ -208,7 +208,7 @@ static Method getAsmMethod(final Class<?> clazz,
208208
/**
209209
* asm method of {@link Injecter#leaveDubbo(String)}
210210
*
211-
* @since 1.1.4
211+
* @since 1.2.0
212212
*/
213213
Method ASM_METHOD_Spy$leaveDubbo = InnerHelper.getAsmMethod(
214214
Injecter.class,
@@ -219,7 +219,7 @@ static Method getAsmMethod(final Class<?> clazz,
219219
/**
220220
* asm method of {@link Injecter#isFirstLevelDubbo(String)}
221221
*
222-
* @since 1.1.4
222+
* @since 1.2.0
223223
*/
224224
Method ASM_METHOD_Spy$isFirstLevelDubbo = InnerHelper.getAsmMethod(
225225
Injecter.class,

iast-core/src/main/java/com/secnium/iast/core/enhance/plugins/framework/dubbo/DubboAdapter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public MethodVisitor visitMethod(final int access, final String name, final Stri
3434

3535
mv = new DubboAdviceAdapter(mv, access, name, desc, signCode, context);
3636
transformed = true;
37-
}
38-
if (transformed) {
3937
if (logger.isDebugEnabled()) {
4038
logger.debug("rewrite method {}.{} for listener[match={}]", context.getClassName(), name, context.getMatchClassName());
4139
}

0 commit comments

Comments
 (0)