赞
踩
CNNVD是我们国家的信息安全漏洞库,咱们这个漏洞库不仅仅收录了NVD的漏洞数据(CVE),还收录咱们国内的漏洞信息(CNNVD),也就是说同样一条漏洞信息,CNNVD的漏洞数据上面既有CVE漏洞编码,也有CNNVD编码,而且描述信息还是中文的。
获取方式:
CNNVD漏洞数据库下载后是xml格式的文件,我们需要写代码将xml里面我们需要的数据提取出来,保存在数据库表里面
@GetMapping
public void insertCnnvd(int type) throws JAXBException {
if(type==0){
for(int i=1999;i<=2023;i++){
System.out.println(“-------->开始读取”+i+“年数据:”);
List nvdList = parseXml(i);
System.out.println(“-------->成功读取”+i+“年数据:”+nvdList.size());
cnnvdService.saveOrUpdateBatch(nvdList);
System.out.println(“-------->成功写入数据:”+nvdList.size());
System.out.println(“”);
System.out.println(“”);
}
}else{
System.out.println(“-------->开始读取”+DateUtil.thisYear()+“年数据:”);
List cnnvdList = parseXml(2023);
System.out.println(“-------->成功读取”+DateUtil.thisYear()+“年数据:”+cnnvdList.size());
cnnvdService.saveOrUpdateBatch(cnnvdList);
System.out.println(“-------->成功写入数据:”+cnnvdList.size());
}
}
public List parseXml(int fileName) throws JAXBException {
//可能的问题:[org.xml.sax.SAXParseException; lineNumber: 2292; columnNumber: 191; 元素类型 “use” 必须由匹配的结束标记 “” 终止。]] with root cause
//解决的方案:在内网的签名添加字符串:<![CDATA[ 在内网的结尾添加字符串:]]>
InputStream stream = this.getClass().getClassLoader().getResourceAsStream(“cnnvd/”+fileName+“.xml”);
JAXBContext jaxbContext = JAXBContext.newInstance(VulnerabilityList.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
VulnerabilityList vulnerabilityList = (VulnerabilityList) jaxbUnmarshaller.unmarshal(stream);
List vulnerabilities = vulnerabilityList.vulnerabilities;
return vulnerabilities;
}
@Data
@XmlRootElement(name = “entry”)
@XmlAccessorType(XmlAccessType.FIELD)
public class Cnnvd implements Serializable {
@TableId(type = IdType.INPUT)
@XmlElement(name = “vuln-id”)
public String id;
@XmlElement(name = “name”)
public String name;
@XmlElement(name = “published”)
public String published;
@XmlElement(name = “modified”)
public String modified;
@XmlElement(name = “source”)
public String source;
@XmlElement(name = “severity”)
public String severity;
@XmlElement(name = “vuln-type”)
public String vulnType;
@XmlElement(name = “vuln-descript”)
public String description;
@XmlElement(name = “cve-id”)
public String cveId;
@XmlElement(name = “bugtraq-id”)
public String bugtraqId;
@XmlElement(name = “vuln-solution”)
public String solution;
}
/root/dependency-check/bin/dependency-check.sh --project “test-服务端第三方依赖CVE漏洞扫描报告” --scan “**/*.jar” -n -f JSON -o “/var/www/html/test-服务端第三方依赖CVE漏洞扫描报告.json”
将上面扫描的“test-服务端第三方依赖CVE漏洞扫描报告.json”数据解析出来,填充到我们的自定义模板中,最终生成我们的word报告。
/**
package com.yunhuang.autosafe.common.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.deepoove.poi.util.PoitlIOUtils;
import com.yunhuang.autosafe.common.entity.;
import com.yunhuang.autosafe.common.mapper.CnnvdMapper;
import com.yunhuang.autosafe.common.service.;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.;
import java.util.;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
public class CnnvdServiceImpl extends ServiceImpl<CnnvdMapper, Cnnvd> implements CnnvdService {
@Autowired
private NvdMyService nvdMyService;
@Autowired
private CveService cveService;
@Autowired
private ScanDependencieService dependencieService;
@Autowired
private ScanVulnerabilitieService vulnerabilitieService;
@Resource
private RedisTemplate redisTemplate;
private final static String REDIS_NVD_KEY = “cve_data”;
/**
//依赖
String dependencies = jsonObject.getStr(“dependencies”);
JSONArray array = JSONUtil.parseArray(dependencies);
//依赖下的漏洞
List dependencieList = JSONUtil.toList(array, ScanDependencie.class);
System.out.println(“--------------->依赖项总数:”+dependencieList.size());
//漏洞详情列表
List dependencieVulList = new ArrayList<>();
//漏洞清单汇总
List vulnerabilitiesAll = new ArrayList<>();
//扫描到的漏洞清单
List cveScanList = new ArrayList<>();
int i = 1;
//遍历依赖:构建导出数据
for(ScanDependencie d :dependencieList){
if(d.getVulnerabilities()==null || d.getVulnerabilities().size()==0) continue;
int pindex = i++;
String depId = UUID.randomUUID().toString().replaceAll(“-”,“”);
d.setId(depId);
d.setName(name);
d.setSortIndex(pindex);
d.setFileName(d.getFileName().replaceAll(" “,”"));
d.setGitHttpUrl(gitHttpUrl);
d.setGitBranch(gitBranch);
d.setScanDate(createTime);
if(StringUtils.isNotBlank(d.getDescription())) d.setDescription(d.getDescription().trim());
int m = 1;
//遍历依赖下的漏洞
List vulnerabilities = d.getVulnerabilities();
for(ScanVulnerabilitie vul : vulnerabilities){
if(vul.getName().indexOf(“CVE”)==-1) continue;
//添加到扫描漏洞清单
cveScanList.add(vul.getName());
int index = m++;
vul.setDependencieId(depId);
vul.setSortIndex(index);
vul.setSortIndexStr(pindex+“.”+index);
vul.setScanDate(createTime);
vulnerabilitiesAll.add(vul);
}
dependencieVulList.add(d);
}
//清除之前的数据
QueryWrapper wrapper = new QueryWrapper<>();
wrapper.eq(“git_http_url”,gitHttpUrl);
List oldList = dependencieService.list(wrapper);
List depIds = oldList.stream().map(ScanDependencie::getId).collect(Collectors.toList());
if(depIds.size()>0){
QueryWrapper wrapper2 = new QueryWrapper<>();
wrapper2.in(“dependencie_id”,depIds);
vulnerabilitieService.remove(wrapper2);
}
dependencieService.remove(wrapper);
//保存扫描到的依赖数据:dependencieVulList
dependencieService.saveBatch(dependencieVulList);
//保存扫描到的依赖数据:vulnerabilitiesAll
vulnerabilitieService.saveBatch(vulnerabilitiesAll);
System.out.println(“--------------->有漏洞的依赖项:”+dependencieVulList.size());
System.out.println(“--------------->漏洞总数:”+vulnerabilitiesAll.size());
System.out.println(“”);
return vulnerabilitiesAll.size();
}
@Override
public String createWord(String name, String reportPath, String gitHttpUrl, String gitBranch) throws IOException {
//所有的有漏洞的依赖
List dependencieList = new ArrayList<>();
//所有的漏洞清单
List vulList = new ArrayList<>();
//漏洞清单分组
Map<String, List> listMap = new HashMap<>();
//漏洞编码
List cveIds = new ArrayList<>();
//对应的cnnvd信息(中文解释)
Map<String, Cnnvd> cnnvdMap = new HashMap<>();
//nvd漏洞原始信息(英文内容)
Map<String, Cve> cveMap = new HashMap<>();
QueryWrapper wrapper1 = new QueryWrapper();
wrapper1.eq(“name”,name).eq(“git_http_url”,gitHttpUrl).orderByAsc(“sort_index”);
dependencieList = dependencieService.list(wrapper1);
List depIds = dependencieList.stream().map(ScanDependencie::getId).collect(Collectors.toList());
if(depIds==null || depIds.size()==0) return null;
QueryWrapper wrapper2 = new QueryWrapper<>();
wrapper2.in(“dependencie_id”,depIds).orderByAsc(“id”);
vulList = vulnerabilitieService.list(wrapper2);
//漏洞根据依赖id分组
listMap = vulList.stream().collect(Collectors.groupingBy(ScanVulnerabilitie::getDependencieId));
cveIds = vulList.stream().map(ScanVulnerabilitie::getName).distinct().collect(Collectors.toList());
//根据漏洞编码查询cnnvd漏洞库
QueryWrapper wrapper3 = new QueryWrapper<>();
wrapper3.in(“cve_id”,cveIds);
List nvdList = this.list(wrapper3);
cnnvdMap = nvdList.stream().collect(Collectors.toMap(Cnnvd::getCveId, Function.identity()));
//根据漏洞编码查询nvd漏洞库
QueryWrapper wrapper4 = new QueryWrapper<>();
wrapper4.in(“id”,cveIds);
List cveList = cveService.list(wrapper4);
cveMap = cveList.stream().collect(Collectors.toMap(Cve::getId, Function.identity()));
//--------------------------------开始准备word数据----------------------------------//
for(ScanDependencie d : dependencieList){
if(!listMap.containsKey(d.getId())) continue;
List vuls = listMap.get(d.getId());
for(ScanVulnerabilitie vul : vuls){
if(cnnvdMap.containsKey(vul.getName())){
Cnnvd cnnvd = cnnvdMap.get(vul.getName());
if(cnnvd==null) continue;
vul.setSeverity(cnnvd.getSeverity());
vul.setVulnType(cnnvd.getVulnType());
vul.setCnnvd(cnnvd.getId());
vul.setTitle(cnnvd.getName());
vul.setDescription(cnnvd.getDescription());
}else{
Cve cve = cveMap.get(vul.getName());
if(cve==null) continue;
vul.setSeverity(cve.getSeverity());
vul.setDescription(cve.getDescription());
}
}
d.setVulnerabilities(vuls);
}
Map<String,Object> map = new HashMap<>();
map.put(“gitHttpUrl”, gitHttpUrl);
map.put(“gitBranch”, gitBranch);
map.put(“reportDate”, DateUtil.today());
map.put(“projectName”,name);
map.put(“vulnerabilitieDependencie”,dependencieList.size());
map.put(“vulnerabilitieNum”,vulList.size());
map.put(“dependencieList”,dependencieList);
map.put(“depList”,dependencieList);
map.put(“vulList”,vulList);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数网络安全工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上网络安全知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注网络安全获取)
还有兄弟不知道网络安全面试可以提前刷题吗?费时一周整理的160+网络安全面试题,金九银十,做网络安全面试里的显眼包!
王岚嵚工程师面试题(附答案),只能帮兄弟们到这儿了!如果你能答对70%,找一个安全工作,问题不大。
对于有1-3年工作经验,想要跳槽的朋友来说,也是很好的温习资料!
【完整版领取方式在文末!!】
93道网络安全面试题
内容实在太多,不一一截图了
最后给大家分享一份全套的网络安全学习资料,给那些想学习 网络安全的小伙伴们一点帮助!
对于从来没有接触过网络安全的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,大家跟着这个大的方向学习准没问题。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。