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;
|
||||
allCommand += commandScript+"\n";
|
||||
log.info("AFL插装编译容器内执行的命令:{}",allCommand);
|
||||
append(context,"AFL插装编译容器内执行的命令:"+allCommand);
|
||||
dockerRun(allCommand,dockerInfo,context);
|
||||
// 更新全局变量
|
||||
// /test目录下当前流水线工作目录
|
||||
@ -112,12 +113,12 @@ public class AFLSlotCompileWorker extends DockerWorker {
|
||||
String suffix = fileName.substring(i + 1);
|
||||
if ("zip".equals(suffix)) {
|
||||
String cmd ="unzip -o "+fileName+"\n" +
|
||||
"cd "+prefix;
|
||||
"cd "+prefix+"\n";
|
||||
return cmd;
|
||||
}
|
||||
if ("tar".equals(suffix)) {
|
||||
String cmd ="tar -zxvf "+fileName+"\n" +
|
||||
"cd "+prefix;
|
||||
"cd "+prefix+"\n";
|
||||
return cmd;
|
||||
}
|
||||
return "";
|
||||
|
@ -58,23 +58,28 @@ public class AFLWorker extends DockerWorker {
|
||||
append(context,"当前机器不支持docker");
|
||||
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;
|
||||
PipPipeline pipeline = (PipPipeline) getContextManager().getContext(taskDef.getPipelineId()).getContextDef();
|
||||
TargetVersion targetVersion = targetVersionService.getById(pipeline.getTargetVersionId());
|
||||
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" +
|
||||
"cd " +PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+ getSourceName(fileName) +
|
||||
"mkdir -p "+PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+File.separator+output+"\n" +
|
||||
"afl-fuzz -i "+seedPath+" -o "+output+" "+commandEnd;
|
||||
"cd " +PipelineGlobalVariableConstant.AFL_DOCKER_BASE_DIR+File.separator+workDir+ "\n"+
|
||||
getSourceName(fileName) +
|
||||
"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 {
|
||||
//将节点的配置信息反编译成对象
|
||||
log.info("AFL模糊测试执行脚本:{}",commandScript);
|
||||
append(context,"AFL模糊测试执行脚本:"+commandScript);
|
||||
Long runningTime = getRunningTime(timeHours);
|
||||
append(context,"运行时间"+runningTime);
|
||||
// 获取docker 暂时先写固定值
|
||||
dockerRun(commandScript,resourceListByType.getDockerEndpointList().get(0),context);
|
||||
dockerRun(commandScript,resourceListByType.getDockerEndpointList().get(0),context, runningTime);
|
||||
} catch (Exception e) {
|
||||
String errorMessage = "该节点配置信息为空,请先配置该节点信息" + "\r\n";
|
||||
log.error("执行ssh失败:", e);
|
||||
@ -91,4 +96,10 @@ public class AFLWorker extends DockerWorker {
|
||||
}
|
||||
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.model.DockerEndpoint;
|
||||
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.command.CreateContainerResponse;
|
||||
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
||||
@ -37,6 +38,10 @@ import static java.lang.String.format;
|
||||
@Slf4j
|
||||
public abstract class DockerWorker extends BaseWorker{
|
||||
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
|
||||
String[] split = command.split("\n");
|
||||
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();
|
||||
|
||||
try {
|
||||
client.execStartCmd(exec.getId()).exec(new ResultCallbackTemplate<>() {
|
||||
ResultCallbackTemplate<ResultCallback<Frame>, Frame> execing = client.execStartCmd(exec.getId()).exec(new ResultCallbackTemplate<>() {
|
||||
@Override
|
||||
public void onStart(Closeable stream) {
|
||||
super.onStart(stream);
|
||||
log.info("命令执行开始,容器id:{},执行id:{}",containerId,exec.getId());
|
||||
append(context,"命令执行开始,容器id:"+containerId);
|
||||
log.info("命令执行开始,容器id:{},执行id:{}", containerId, exec.getId());
|
||||
append(context, "命令执行开始,容器id:" + containerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable throwable) {
|
||||
super.onError(throwable);
|
||||
log.error("命令执行出现错误,容器id:{},执行id:{},错误原因",containerId,exec.getId(),throwable);
|
||||
append(context,"命令执行出现错误,容器id::"+containerId);
|
||||
log.error("命令执行出现错误,容器id:{},执行id:{},错误原因", containerId, exec.getId(), throwable);
|
||||
append(context, "命令执行出现错误,容器id::" + containerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
super.onComplete();
|
||||
log.info("命令执行完毕,容器id:{},执行id:{}",containerId,exec.getId());
|
||||
append(context,"命令执行完毕,容器id::"+containerId);
|
||||
log.info("命令执行完毕,容器id:{},执行id:{}", containerId, exec.getId());
|
||||
append(context, "命令执行完毕,容器id::" + containerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,18 +120,24 @@ public abstract class DockerWorker extends BaseWorker{
|
||||
case STDOUT:
|
||||
System.out.print(output);
|
||||
log.info("标准输出: {}", output.trim());
|
||||
append(context,"标准输出: ,容器id:"+containerId+" content"+output);
|
||||
append(context, "标准输出: ,容器id:" + containerId + " content" + output);
|
||||
break;
|
||||
case STDERR:
|
||||
System.err.print(output);
|
||||
log.error("错误输出: {}", output.trim());
|
||||
append(context,"错误输出: ,容器id:"+containerId+" content"+output);
|
||||
append(context, "错误输出: ,容器id:" + containerId + " content" + output);
|
||||
break;
|
||||
default:
|
||||
log.warn("未知流类型: {}", frame.getStreamType());
|
||||
}
|
||||
}
|
||||
}).awaitCompletion();
|
||||
});
|
||||
if (timeOut==null) {
|
||||
execing.awaitCompletion();
|
||||
} else {
|
||||
execing.awaitCompletion(timeOut,TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
log.error("执行异常",e);
|
||||
append(context,"执行异常,容器id:"+containerId);
|
||||
|
Loading…
x
Reference in New Issue
Block a user