-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close ISSUE HXSecurity/DongTai#147 <DongTai-agent-java>
- Loading branch information
owefsad
committed
Aug 24, 2021
1 parent
15940d0
commit 15bf796
Showing
9 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,15 @@ | |
|
||
import com.secnium.iast.core.EngineManager; | ||
import com.secnium.iast.core.handler.vulscan.ReportConstant; | ||
import com.secnium.iast.core.replay.HttpRequestReplay; | ||
import com.secnium.iast.core.util.ByteUtils; | ||
import com.secnium.iast.core.util.Constants; | ||
import com.secnium.iast.core.util.HttpClientUtils; | ||
import com.secnium.iast.core.util.LogUtils; | ||
import org.json.JSONObject; | ||
import org.slf4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.MemoryUsage; | ||
import java.lang.management.OperatingSystemMXBean; | ||
|
@@ -14,12 +20,8 @@ | |
* | ||
* @author [email protected] | ||
*/ | ||
public class HeartBeatReport { | ||
|
||
public static void createReport() { | ||
String msg = generateHeartBeatMsg(); | ||
EngineManager.sendNewReport(msg); | ||
} | ||
public class HeartBeatSender extends Thread { | ||
private final Logger logger = LogUtils.getLogger(getClass()); | ||
|
||
private static String generateHeartBeatMsg() { | ||
JSONObject report = new JSONObject(); | ||
|
@@ -32,6 +34,9 @@ private static String generateHeartBeatMsg() { | |
detail.put(ReportConstant.HEART_BEAT_CPU, readCpuInfo()); | ||
detail.put(ReportConstant.HEART_BEAT_DISK, getDiskInfo()); | ||
detail.put(ReportConstant.HEART_BEAT_REQ_COUNT, EngineManager.getRequestCount()); | ||
detail.put(ReportConstant.REPORT_QUEUE, EngineManager.getReportQueueSize()); | ||
detail.put(ReportConstant.METHOD_QUEUE, EngineManager.getMethodReportQueueSize()); | ||
detail.put(ReportConstant.REPLAY_QUEUE, EngineManager.getReplayQueueSize()); | ||
|
||
return report.toString(); | ||
} | ||
|
@@ -68,4 +73,25 @@ public static String getMemInfo() { | |
public static String getDiskInfo() { | ||
return "{}"; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
boolean isRunning = EngineManager.isLingzhiRunning(); | ||
if (isRunning) { | ||
EngineManager.turnOffLingzhi(); | ||
} | ||
try { | ||
String report = generateHeartBeatMsg(); | ||
StringBuilder response = HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, report); | ||
HttpRequestReplay.sendReplayRequest(response); | ||
} catch (IOException e) { | ||
logger.error("report error reason: ", e); | ||
} catch (Exception e) { | ||
logger.error("report error, reason: ", e); | ||
} | ||
|
||
if (isRunning) { | ||
EngineManager.turnOnLingzhi(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,30 @@ | |
|
||
import com.secnium.iast.core.AbstractThread; | ||
import com.secnium.iast.core.EngineManager; | ||
import com.secnium.iast.core.replay.HttpRequestReplay; | ||
import com.secnium.iast.core.util.Constants; | ||
import com.secnium.iast.core.util.HttpClientUtils; | ||
import com.secnium.iast.core.util.LogUtils; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* 发送报告的功能实现 | ||
* | ||
* @author [email protected] | ||
*/ | ||
public class ReportSender extends AbstractThread { | ||
private final Logger logger = LogUtils.getLogger(ReportSender.class); | ||
private final Pattern PATTERN = Pattern.compile("\"type\":1}"); | ||
// private final Pattern PATTERN = Pattern.compile("\"type\":1}"); | ||
|
||
@Override | ||
protected void send() throws Exception { | ||
HeartBeatReport.createReport(); | ||
String report; | ||
StringBuilder response; | ||
while (EngineManager.hasNewReport()) { | ||
report = EngineManager.getNewReport(); | ||
try { | ||
if (report != null && !report.isEmpty()) { | ||
response = HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, report); | ||
if (PATTERN.matcher(report).find()) { | ||
HttpRequestReplay.sendReplayRequest(response); | ||
} | ||
} | ||
} catch (Exception e) { | ||
logger.info(report); | ||
throw e; | ||
if (logger.isDebugEnabled()) { | ||
logger.debug(report); | ||
} | ||
if (report != null && !report.isEmpty()) { | ||
HttpClientUtils.sendPost(Constants.API_REPORT_UPLOAD, report); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters