AFL相关work修改
This commit is contained in:
parent
22ec4646e8
commit
bacca232fe
@ -95,6 +95,7 @@ public class AFLSlotCompileWorker extends DockerWorker {
|
|||||||
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
String commandScript = commandScriptObj instanceof String ? ((String) commandScriptObj) : null;
|
||||||
allCommand += commandScript+"\n";
|
allCommand += commandScript+"\n";
|
||||||
log.info("AFL插装编译容器内执行的命令:{}",allCommand);
|
log.info("AFL插装编译容器内执行的命令:{}",allCommand);
|
||||||
|
append(context,"AFL插装编译容器内执行的命令:"+allCommand);
|
||||||
dockerRun(allCommand,dockerInfo,context);
|
dockerRun(allCommand,dockerInfo,context);
|
||||||
// 更新全局变量
|
// 更新全局变量
|
||||||
// /test目录下当前流水线工作目录
|
// /test目录下当前流水线工作目录
|
||||||
@ -112,12 +113,12 @@ public class AFLSlotCompileWorker extends DockerWorker {
|
|||||||
String suffix = fileName.substring(i + 1);
|
String suffix = fileName.substring(i + 1);
|
||||||
if ("zip".equals(suffix)) {
|
if ("zip".equals(suffix)) {
|
||||||
String cmd ="unzip -o "+fileName+"\n" +
|
String cmd ="unzip -o "+fileName+"\n" +
|
||||||
"cd "+prefix;
|
"cd "+prefix+"\n";
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
if ("tar".equals(suffix)) {
|
if ("tar".equals(suffix)) {
|
||||||
String cmd ="tar -zxvf "+fileName+"\n" +
|
String cmd ="tar -zxvf "+fileName+"\n" +
|
||||||
"cd "+prefix;
|
"cd "+prefix+"\n";
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -58,23 +58,28 @@ public class AFLWorker extends DockerWorker {
|
|||||||
append(context,"当前机器不支持docker");
|
append(context,"当前机器不支持docker");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String output = workDir + PipelineGlobalVariableConstant.AFL_DOCKER_OUTPUT;
|
String output = workDir +File.separator+ PipelineGlobalVariableConstant.AFL_DOCKER_OUTPUT;
|
||||||
//
|
//
|
||||||
String volumeWorkDirPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX;
|
String volumeWorkDirPath = PipelineGlobalVariableConstant.AFL_VOLUME_WORK_DIR_PREFIX;
|
||||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||||
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
||||||
String fileName = targetVersion.getFileName();
|
String fileName = targetVersion.getFileName();
|
||||||
|
append(context,"AFL 输出路径:"+output);
|
||||||
|
Object timeObj = taskProperties.get("runningTime");
|
||||||
|
Double timeHours = Double.valueOf(String.valueOf(timeObj));
|
||||||
String commandScript = "docker run -v "+volumeWorkDirPath+":/test -it "+imageName+" bash\n" +
|
String commandScript = "docker run -v "+volumeWorkDirPath+":/test -it "+imageName+" bash\n" +
|
||||||
"cd " +PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+ getSourceName(fileName) +
|
"cd " +PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+ "\n"+
|
||||||
"mkdir -p "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+File.separator+output+"\n" +
|
getSourceName(fileName) +
|
||||||
"afl-fuzz -i "+seedPath+" -o "+output+" "+commandEnd;
|
"mkdir -p "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+output+"\n" +
|
||||||
|
"afl-fuzz -i "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+seedPath+" -o "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+output+" "+commandEnd;
|
||||||
try {
|
try {
|
||||||
//将节点的配置信息反编译成对象
|
//将节点的配置信息反编译成对象
|
||||||
log.info("AFL模糊测试执行脚本:{}",commandScript);
|
log.info("AFL模糊测试执行脚本:{}",commandScript);
|
||||||
|
append(context,"AFL模糊测试执行脚本:"+commandScript);
|
||||||
|
Long runningTime = getRunningTime(timeHours);
|
||||||
|
append(context,"运行时间"+runningTime);
|
||||||
// 获取docker 暂时先写固定值
|
// 获取docker 暂时先写固定值
|
||||||
dockerRun(commandScript,resourceListByType.getDockerEndpointList().get(0),context);
|
dockerRun(commandScript,resourceListByType.getDockerEndpointList().get(0),context, runningTime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
|
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
|
||||||
log.error("执行ssh失败:", e);
|
log.error("执行ssh失败:", e);
|
||||||
@ -91,4 +96,10 @@ public class AFLWorker extends DockerWorker {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
public Long getRunningTime(Double runningTimeHours){
|
||||||
|
if (runningTimeHours!=null && runningTimeHours >0) {
|
||||||
|
return (long)(runningTimeHours*60*60*1000);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
|||||||
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
import cd.casic.module.execute.docker.dataobject.dto.DockerEndpointDo;
|
||||||
import cd.casic.module.execute.docker.dataobject.model.DockerEndpoint;
|
import cd.casic.module.execute.docker.dataobject.model.DockerEndpoint;
|
||||||
import com.github.dockerjava.api.DockerClient;
|
import com.github.dockerjava.api.DockerClient;
|
||||||
|
import com.github.dockerjava.api.async.ResultCallback;
|
||||||
import com.github.dockerjava.api.async.ResultCallbackTemplate;
|
import com.github.dockerjava.api.async.ResultCallbackTemplate;
|
||||||
import com.github.dockerjava.api.command.CreateContainerResponse;
|
import com.github.dockerjava.api.command.CreateContainerResponse;
|
||||||
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
||||||
@ -37,6 +38,10 @@ import static java.lang.String.format;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class DockerWorker extends BaseWorker{
|
public abstract class DockerWorker extends BaseWorker{
|
||||||
public void dockerRun(String command, DockerEndpointDo dockerEndpoint, BaseRunContext context){
|
public void dockerRun(String command, DockerEndpointDo dockerEndpoint, BaseRunContext context){
|
||||||
|
dockerRun(command,dockerEndpoint,context,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dockerRun(String command, DockerEndpointDo dockerEndpoint, BaseRunContext context,Long timeOut){
|
||||||
// 第一行必须是docker run 命令 option 支持 -it -v
|
// 第一行必须是docker run 命令 option 支持 -it -v
|
||||||
String[] split = command.split("\n");
|
String[] split = command.split("\n");
|
||||||
List<String> commandLine = new ArrayList<>(Arrays.stream(split).filter(StringUtils::isNotBlank).toList());
|
List<String> commandLine = new ArrayList<>(Arrays.stream(split).filter(StringUtils::isNotBlank).toList());
|
||||||
@ -86,26 +91,26 @@ public abstract class DockerWorker extends BaseWorker{
|
|||||||
.withCmd(commandList).exec();
|
.withCmd(commandList).exec();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
client.execStartCmd(exec.getId()).exec(new ResultCallbackTemplate<>() {
|
ResultCallbackTemplate<ResultCallback<Frame>, Frame> execing = client.execStartCmd(exec.getId()).exec(new ResultCallbackTemplate<>() {
|
||||||
@Override
|
@Override
|
||||||
public void onStart(Closeable stream) {
|
public void onStart(Closeable stream) {
|
||||||
super.onStart(stream);
|
super.onStart(stream);
|
||||||
log.info("命令执行开始,容器id:{},执行id:{}",containerId,exec.getId());
|
log.info("命令执行开始,容器id:{},执行id:{}", containerId, exec.getId());
|
||||||
append(context,"命令执行开始,容器id:"+containerId);
|
append(context, "命令执行开始,容器id:" + containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable throwable) {
|
public void onError(Throwable throwable) {
|
||||||
super.onError(throwable);
|
super.onError(throwable);
|
||||||
log.error("命令执行出现错误,容器id:{},执行id:{},错误原因",containerId,exec.getId(),throwable);
|
log.error("命令执行出现错误,容器id:{},执行id:{},错误原因", containerId, exec.getId(), throwable);
|
||||||
append(context,"命令执行出现错误,容器id::"+containerId);
|
append(context, "命令执行出现错误,容器id::" + containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
super.onComplete();
|
super.onComplete();
|
||||||
log.info("命令执行完毕,容器id:{},执行id:{}",containerId,exec.getId());
|
log.info("命令执行完毕,容器id:{},执行id:{}", containerId, exec.getId());
|
||||||
append(context,"命令执行完毕,容器id::"+containerId);
|
append(context, "命令执行完毕,容器id::" + containerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -115,18 +120,24 @@ public abstract class DockerWorker extends BaseWorker{
|
|||||||
case STDOUT:
|
case STDOUT:
|
||||||
System.out.print(output);
|
System.out.print(output);
|
||||||
log.info("标准输出: {}", output.trim());
|
log.info("标准输出: {}", output.trim());
|
||||||
append(context,"标准输出: ,容器id:"+containerId+" content"+output);
|
append(context, "标准输出: ,容器id:" + containerId + " content" + output);
|
||||||
break;
|
break;
|
||||||
case STDERR:
|
case STDERR:
|
||||||
System.err.print(output);
|
System.err.print(output);
|
||||||
log.error("错误输出: {}", output.trim());
|
log.error("错误输出: {}", output.trim());
|
||||||
append(context,"错误输出: ,容器id:"+containerId+" content"+output);
|
append(context, "错误输出: ,容器id:" + containerId + " content" + output);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.warn("未知流类型: {}", frame.getStreamType());
|
log.warn("未知流类型: {}", frame.getStreamType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).awaitCompletion();
|
});
|
||||||
|
if (timeOut==null) {
|
||||||
|
execing.awaitCompletion();
|
||||||
|
} else {
|
||||||
|
execing.awaitCompletion(timeOut,TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
log.error("执行异常",e);
|
log.error("执行异常",e);
|
||||||
append(context,"执行异常,容器id:"+containerId);
|
append(context,"执行异常,容器id:"+containerId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user