项目描述
为了增强靶场平台的能力,选择与第三方公司合作,借助第三方平台增强已方平台的能力
本项目是为了将其他第三方安全软件的能力融入到靶场平台中
引用:
GOBY集成资产发现、漏洞发现、漏洞利用、漏洞全网扫描、反弹shell、蜜罐识别、代理隧道、拓扑展示、报告输出、自定义插件等功能于一身,强大且灵活的框架覆盖绝大部分攻击流程。使攻击效果,不再依赖于攻击人员自身的能力及经验。GOBY内集成的“靶标漏洞”,全部为实际可利用漏洞,部分来自于历年攻防演习爆发的漏洞,更加贴近于企业对于攻防演习实战化的需求,以全面提升攻击队成绩项目
项目分为两个部分
1.安全扫描服务Server
该服务运行在靶场平台,作为靶场Server端的服务,负责具体业务功能,每个靶场只需要部署一个
2.适配器Agent
该服务部署在第三方安全软件所属的环境中,负责处理·安全扫描服务Server·的请求,之所以需要Agent端主要考虑网络隔离的因素,避免部署多个含有业务功能的Server,于是使用更下层的适配器去沟通第三方安全软件
项目周期
一周
一人
框架

项目进度
适配器Agent 已完成
领导没有想好安全扫描服务的业务功能,于是本次只对Agent进行描述
代码摘要
Agent端
适配器核心逻辑
根据用户传入的参数决定工厂创建那家公司的对象,对象创建完成后在对应的方法完成参数的封装后交给Rest对象进行远程调用,将结果进行返回到对应的对象后由对象在对结果进行封装然后返回给用户
使用工厂模式,如果将来需要兼容C/D公司的安全软件那么只需要三步操作且不影响原有的业务逻辑
1. 工厂类增加生产C/D公司的业务处理类
2. 新增业务处理类实现统一的接口
3. 配置文件配置相应的远程调用信息

@Component
public class ProductFactory {
@Resource
private ProductProperty productProperty;
public ProductService builder(String type) {
switch (type.toUpperCase()) {
case "GOBY":
return new GobyServiceImpl(productProperty);
case "BuiBuiBui":
return new BuiBuiBuiImpl(productProperty);
default:
throw new IllegalArgumentException("不支持的产品类型");
}
}
}
通过@configurationProperties() 读取对应的第三方软件的相关属性
@ConfigurationProperties("scan")
@Configuration
@Data
public class ProductProperty {
private Goby goby;
@Data
public static class Goby {
private String protocol;
private String host;
private String port;
private String uriPrefix;
}
}
scan:
goby:
host: 172.172.0.250
port: 20017
uriPrefix: api/v1
protocol: http
A公司安全软件业务处理类
public class GobyServiceImpl implements ProductService {
private RestClient<Object> restClient;
public GobyServiceImpl(ProductProperty productProperty) {
this.restClient = new RestClient(productProperty, "GOBY");
}
public void test(){
restClient.rest();
}
}
B公司安全软件业务处理类
public class BuiBuiBuiImpl implements ProductService {
private RestClient<Object> restClient;
public BuiBuiBuiImpl(ProductProperty productProperty){
this.restClient = new RestClient(productProperty, "GOBY");
}
public void test(){
}
}
Controller 层
@RestController
@RequestMapping("task")
@Api(tags = "任务相关")
public class TaskController {
@Resource
private ProductFactory productFactory;
@ApiOperation(value = "开始任务")
@PostMapping()
public ServerResult taskStart(@RequestBody TaskDTO taskDTO) {
return productFactory.builder(taskDTO.getType()).taskStart(taskDTO);
}
}
Rest 远程调用类
public class RestClient<T> {
private final RestTemplate restTemplate;
private final ProductProperty productProperty;
private final String type;
public RestClient(ProductProperty productProperty, String type) {
this.type = type;
this.productProperty = productProperty;
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(3000);
factory.setReadTimeout(5000);
BufferingClientHttpRequestFactory bufferFactory = new BufferingClientHttpRequestFactory(factory);
restTemplate = new RestTemplate(bufferFactory);
restTemplate.setInterceptors(Collections.singletonList(new RestClientConfig()));
}
public JSONObject gobyPostRest(String path, Object o) {
return gobyRest(path, HttpMethod.POST, o);
}
....
public <T> ResponseEntity<T> rest(String uri, HttpMethod method, RequestEntity<?> request, Class<T> c) {
return restTemplate.exchange(URI.create(uri), method, request, c);
}