├── CAFJE ├── .classpath ├── .project ├── bin │ ├── com │ │ └── eveino │ │ │ ├── engine │ │ │ ├── MainEngine.class │ │ │ └── regex │ │ │ │ └── RegexDetect.class │ │ │ ├── entity │ │ │ └── Vuln.class │ │ │ └── utils │ │ │ ├── FileUtil.class │ │ │ ├── RegexpUtil.class │ │ │ ├── UseUtil.class │ │ │ └── XmlUtil.class │ ├── config.properties │ └── rules │ │ ├── DemoRule.xml │ │ ├── Exec.xml │ │ ├── File.xml │ │ ├── FilePathManipulation.xml │ │ ├── FileUpload.xml │ │ ├── IntranetIPLeak.xml │ │ ├── ObjectDeserialization.xml │ │ ├── PrintStackTrace.xml │ │ ├── SQLiHibernate.xml │ │ ├── SQLiIbatis.xml │ │ ├── SQLiJdbc.xml │ │ ├── SQLiMybatis.xml │ │ ├── SSRF.xml │ │ ├── URL-Redirect.xml │ │ ├── UserInfoLeak.xml │ │ ├── XSS.xml │ │ └── XXE.xml ├── lib │ ├── dom4j-1.6.1.jar │ └── jaxen-1.1-beta-6.jar └── src │ ├── com │ └── eveino │ │ ├── engine │ │ ├── MainEngine.java │ │ └── regex │ │ │ └── RegexDetect.java │ │ ├── entity │ │ └── Vuln.java │ │ └── utils │ │ ├── FileUtil.java │ │ ├── RegexpUtil.java │ │ ├── UseUtil.java │ │ └── XmlUtil.java │ ├── config.properties │ └── rules │ ├── DemoRule.xml │ ├── Exec.xml │ ├── File.xml │ ├── FilePathManipulation.xml │ ├── FileUpload.xml │ ├── IntranetIPLeak.xml │ ├── ObjectDeserialization.xml │ ├── SQLiHibernate.xml │ ├── SQLiIbatis.xml │ ├── SQLiJdbc.xml │ ├── SQLiMybatis.xml │ ├── SSRF.xml │ ├── URL-Redirect.xml │ ├── UserInfoLeak.xml │ ├── XSS.xml │ └── XXE.xml ├── Jar └── CAFJE │ ├── CAFJE.jar │ ├── config.properties │ └── rules │ ├── DemoRule.xml │ ├── Exec.xml │ ├── File.xml │ ├── FilePathManipulation.xml │ ├── FileUpload.xml │ ├── IntranetIPLeak.xml │ ├── ObjectDeserialization.xml │ ├── PrintStackTrace.xml │ ├── SQLiHibernate.xml │ ├── SQLiIbatis.xml │ ├── SQLiJdbc.xml │ ├── SQLiMybatis.xml │ ├── SSRF.xml │ ├── URL-Redirect.xml │ ├── UserInfoLeak.xml │ ├── XSS.xml │ └── XXE.xml ├── LICENSE └── README.md /CAFJE/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | CAFJE 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/engine/MainEngine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/engine/MainEngine.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/engine/regex/RegexDetect.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/engine/regex/RegexDetect.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/entity/Vuln.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/entity/Vuln.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/utils/FileUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/utils/FileUtil.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/utils/RegexpUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/utils/RegexpUtil.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/utils/UseUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/utils/UseUtil.class -------------------------------------------------------------------------------- /CAFJE/bin/com/eveino/utils/XmlUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/bin/com/eveino/utils/XmlUtil.class -------------------------------------------------------------------------------- /CAFJE/bin/config.properties: -------------------------------------------------------------------------------- 1 | projectRoot=/home/snail/Develop-workspace/eclipse-workspace/VulnWeb 2 | rulesPath=src/rules 3 | suffix=jsp,java,html,css,js,xml -------------------------------------------------------------------------------- /CAFJE/bin/rules/DemoRule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | demoRegexpHere 5 | 缺陷描述。 6 | 修复建议 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/Exec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProcessBuilder|ProcessBuilder.start\(\) 5 | 使用ProcessBuilder执行系统命令。 6 | 严格过滤传入命令 7 | CWE链接: 8 | 9 | 10 | Runtime\.getRuntime\(\)\.exec|Runtime\.getRuntime() 11 | 使用Runtime执行系统命令。 12 | 严格过滤传入命令 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.createNewFile\(|FileOutputStream\( 5 | createNewFile。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | \.delete\(\) 11 | delete。 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | new\sFileInputStream\(/ 17 | FileInputStream。 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/FilePathManipulation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\sFile\(|\.getRealPath\( 5 | 如果传入的路径可控,则攻击者可能控制文件系统路径参数,借此访问或修改其他受保护的文件。 6 | 确保传入路径合法并过滤../ ? 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/FileUpload.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.getOriginalFilename\(|MultipartFile\s 5 | 使用MultipartFile上传文件,判断是否有文件类型过滤。 6 | 使用白名单判断文件类型。 7 | CWE链接: 8 | 9 | 10 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/IntranetIPLeak.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 10(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){3} 5 | 10.0.0.0-10.255.255.255 6 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 7 | CWE链接: 8 | 9 | 10 | 172\.([1][6-9]|[2]\d|3[01])(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 11 | 172.16.0.0-172.31.255.255 12 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 13 | CWE链接: 14 | 15 | 16 | 192\.168(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 17 | 192.168.0.0-192.168.255.255 18 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 19 | CWE链接: 20 | 21 | 22 | ([1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3} 23 | 1-3规则也会匹配到,此正则主要用于查看是否有外网地址泄露。 24 | 如果外网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 25 | CWE链接: 26 | 27 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/ObjectDeserialization.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.readObject\( 5 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 6 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 7 | CWE链接: 8 | 9 | 10 | JSON\.parseObject\( 11 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 12 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 13 | CWE链接: 14 | 15 | 16 | ObjectMapper\.readValue 17 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 18 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 19 | CWE链接: 20 | 21 | 22 | fromXML\( 23 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 24 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 25 | CWE链接: 26 | 27 | 28 | readUnshared\( 29 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 30 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 31 | CWE链接: 32 | 33 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/PrintStackTrace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .\.printStackTrace\(\); 5 | 异常消息使用printStackTrace直接打印,可能导致信息泄露。 6 | 将异常记录到日志或以其他方式处理异常。 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/SQLiHibernate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(setString|\?)).)*createQuery((?!(setString|\?)).)*$ 5 | 判断该语句上下文是否预编译 6 | 通过参数绑定实现预编译: 1.name parameter 2.positional parameter 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/SQLiIbatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\w+\$((?!(like|order)).)*$ 5 | $parameter$不是预编译,会有sql注入风险 6 | #parameter#预编译 7 | CWE链接: 8 | 9 | 10 | like.*\$\w+\$ 11 | SQLiIbatis2 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\w+\$ 17 | SQLiIbatis 18 | SQLiIbatis 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/SQLiJdbc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^*sql\.Statement|\.createStatement\(\) 5 | 使用Statement,未预编译语句可能导致SQLi。 6 | 建议使用PreparedStatement进行预编译 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/SQLiMybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\{\w+\}((?!(like|order)).)*$ 5 | SQLiMybatis 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | like\s+'\%\$\{\w+\}\% 11 | SQLiMybatis 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\{ 17 | SQLiMybatis3 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/SSRF.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | URLConnection 5 | URLConnection 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | HttpURLConnection 11 | HttpURLConnection 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | HttpsURLConnection 17 | HttpsURLConnection 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/URL-Redirect.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sendRedirect\( 5 | sendRedirect。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | setHeader\(\"refresh 11 | setHeader。 12 | 修复建议 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/UserInfoLeak.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^username=|^username: 5 | 用户名硬编码 6 | 如非配置文件中,建议使用其他方式获取用户名,如从配置文件或数据库中获取。 7 | CWE链接: 8 | 9 | 10 | ^password=|^password: 11 | 密码硬编码 12 | 如非配置文件中,建议使用其他方式获取密码,如从配置文件或数据库中获取。 13 | CWE链接: 14 | 15 | 16 | add\sby 17 | 开发者信息泄露 18 | jsp文件中建议使用jsp注释<%--jsp注释--%>,避免输出页面时将注释展示在前端。JavaScript/html/css等能直接访问的文件,建议去除该信息,xml文件请忽略该缺陷。 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/XSS.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | <%= 5 | JSP页面直接使用<%=输出变量,如未存在全局过滤器情况下,可能导致XSS。 6 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 7 | CWE链接: 8 | 9 | 10 | response\.getWriter* 11 | 直接使用response.getWriter向浏览器写数据,可能导致XSS。 12 | 建议使用jsp输出数据。 13 | CWE链接: 14 | 15 | 16 | response\.getOutputStream* 17 | 直接使用response.getOutputStream向浏览器写数据,可能导致XSS。 18 | 建议使用jsp输出数据。 19 | CWE链接: 20 | 21 | 22 | ^((?!(Cache-Control|Parama)).)*response\.setHeader*((?!(Cache-Control|Parama)).)*$ 23 | 直接使用response.setHeader向浏览器设置header,可能导致XSS。 24 | 建议在jsp中设置header。 25 | CWE链接: 26 | 27 | 28 | getJspContext\(\).getOut\(\)* 29 | 标签中直接使用getJspContext().getOut()向浏览器写数据,可能导致XSS。 30 | 建议。 31 | CWE链接: 32 | 33 | 34 | ^((?!(c:forEach|c:out|pageContext|if|when)).)*\$\{((?!(c:forEach|c:out|pageContext|if|when)).)*$ 35 | jsp输出变量,未做输出编码,可能导致XSS 36 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 37 | CWE链接: 38 | 39 | 40 | pageContext.getOut\(\) 41 | servlet直接向浏览器输出数据,可能导致XSS。 42 | 建议使用jsp输出数据。 43 | CWE链接: 44 | 45 | -------------------------------------------------------------------------------- /CAFJE/bin/rules/XXE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\s+SAXReader\(\) 5 | SAXReader。 6 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 7 | CWE链接: 8 | 9 | 10 | new\s+SAXBuilder\(\) 11 | SAXBuilder。 12 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 13 | CWE链接: 14 | 15 | 16 | new\s+SAXParser\( 17 | SAXParser。 18 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 19 | CWE链接: 20 | 21 | 22 | createXMLReader\( 23 | XMLReader。 24 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 25 | CWE链接: 26 | 27 | 28 | newDocumentBuilder\( 29 | DocumentBuilder。 30 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 31 | CWE链接: 32 | 33 | 34 | createXMLStreamReader\( 35 | XMLStreamReader。 36 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 37 | CWE链接: 38 | 39 | -------------------------------------------------------------------------------- /CAFJE/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /CAFJE/lib/jaxen-1.1-beta-6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/CAFJE/lib/jaxen-1.1-beta-6.jar -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/engine/MainEngine.java: -------------------------------------------------------------------------------- 1 | package com.eveino.engine; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.OutputStreamWriter; 9 | import java.util.Properties; 10 | 11 | import org.dom4j.DocumentException; 12 | 13 | import com.eveino.engine.regex.RegexDetect; 14 | import com.eveino.utils.FileUtil; 15 | import com.eveino.utils.UseUtil; 16 | 17 | /*** 18 | * 19 | * @author 小王子 20 | * @version 0.0.1 21 | */ 22 | public class MainEngine { 23 | private static final Properties properties = new Properties(); 24 | 25 | public static void main(String[] args) throws IOException, DocumentException { 26 | // 外部传入配置文件路径 27 | if (args.length!=1 || !"config.properties".equals(args[0])) { 28 | UseUtil.usage(); 29 | } 30 | properties.load(new FileInputStream(args[0])); 31 | 32 | // 项目中配置文件路径 33 | // properties.load(new FileInputStream("src/config.properties")); 34 | 35 | System.out.println("扫描开始..."); 36 | Long time1 = System.currentTimeMillis(); 37 | File projectRoot = new File(properties.getProperty("projectRoot")); 38 | // 判断项目路径是否存在 39 | if (!FileUtil.checkFileExist(projectRoot)) { 40 | System.err.println(projectRoot + " 不存在.\n请确认项目根目录"); 41 | System.exit(0); 42 | } 43 | String suffix = properties.getProperty("suffix"); 44 | String[] suffixs = null; 45 | // 判断suffix是否空,不为空则配置有后缀,分割成数组 46 | if (!suffix.equals("") || suffix.length() != 0) { 47 | suffixs = suffix.split(","); 48 | } 49 | String rulesPath = properties.getProperty("rulesPath"); 50 | // 在项目根目录生成扫描结果 51 | File result = new File(projectRoot + File.separator + "resultCAFJE.txt"); 52 | BufferedWriter buffw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(result), "UTF-8")); 53 | // engineRegex 54 | RegexDetect.analysisFile(projectRoot, suffixs, buffw, rulesPath); 55 | // TODO 其他引擎 56 | Long time2 = System.currentTimeMillis(); 57 | String time = Long.toString(time2 - time1); 58 | System.out.println("耗时:" + time + "毫秒"); 59 | buffw.write("耗时:" + time + "毫秒"); 60 | buffw.close(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/engine/regex/RegexDetect.java: -------------------------------------------------------------------------------- 1 | package com.eveino.engine.regex; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.Writer; 6 | import java.util.List; 7 | 8 | import org.dom4j.DocumentException; 9 | 10 | import com.eveino.entity.Vuln; 11 | import com.eveino.utils.FileUtil; 12 | import com.eveino.utils.RegexpUtil; 13 | import com.eveino.utils.XmlUtil; 14 | 15 | /*** 16 | * 17 | * @author 小王子 18 | * @version 0.0.1 19 | */ 20 | public class RegexDetect { 21 | 22 | /*** 23 | * 24 | * @param dir 25 | * 项目根目录,递归 26 | * @param suffix 27 | * 需要搜索文件的后缀,为空则搜索所有后缀 28 | * @param buffw 29 | * 用于写结果文件 30 | * @param rulesPath 31 | * 规则根目录 32 | * @throws IOException 33 | * @throws DocumentException 34 | */ 35 | public static void analysisFile(File dir, String[] suffix, Writer buffw, String rulesPath) 36 | throws IOException, DocumentException { 37 | File[] files = dir.listFiles(); 38 | for (int x = 0; x < files.length; x++) { 39 | if (files[x].isDirectory()) { 40 | analysisFile(files[x], suffix, buffw, rulesPath); 41 | } else { 42 | if (FileUtil.suffixFile(files[x], suffix)) { 43 | List list = XmlUtil.xmlPaser(rulesPath); 44 | for (Vuln v : list) { 45 | StringBuffer stringBuffer = RegexpUtil.regexpParser(files[x], v.getRegexp()); 46 | if (stringBuffer.length() > 0) { 47 | buffw.write(files[x].getPath() + "\n"); 48 | buffw.write((v.getName() + "\n")); 49 | buffw.write(v.getId() + "\n"); 50 | buffw.write((v.getDecription() + "\n")); 51 | buffw.write(v.getRecommendation() + "\n"); 52 | buffw.write(v.getReference() + "\n"); 53 | buffw.write(stringBuffer.toString() + "\n"); 54 | buffw.flush(); 55 | } 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/entity/Vuln.java: -------------------------------------------------------------------------------- 1 | package com.eveino.entity; 2 | /*** 3 | * 4 | * @author 小王子 5 | * 6 | */ 7 | public class Vuln { 8 | private String name; 9 | private String id; 10 | private String regexp; 11 | private String decription; 12 | private String recommendation; 13 | private String reference; 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | public String getId() { 22 | return id; 23 | } 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | public String getRegexp() { 28 | return regexp; 29 | } 30 | public void setRegexp(String regexp) { 31 | this.regexp = regexp; 32 | } 33 | public String getDecription() { 34 | return decription; 35 | } 36 | public void setDecription(String decription) { 37 | this.decription = decription; 38 | } 39 | public String getRecommendation() { 40 | return recommendation; 41 | } 42 | public void setRecommendation(String recommendation) { 43 | this.recommendation = recommendation; 44 | } 45 | public String getReference() { 46 | return reference; 47 | } 48 | public void setReference(String reference) { 49 | this.reference = reference; 50 | } 51 | @Override 52 | public String toString() { 53 | return "Vuln [name=" + name + ", id=" + id + ", regexp=" + regexp + ", decription=" + decription 54 | + ", recommendation=" + recommendation + ", reference=" + reference 55 | + "]"; 56 | } 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/utils/FileUtil.java: -------------------------------------------------------------------------------- 1 | package com.eveino.utils; 2 | 3 | import java.io.File; 4 | 5 | public class FileUtil { 6 | /*** 7 | * 判断传入文件的后缀是否包含在给定的后缀数组中 8 | * @param file 9 | * @param suffix 10 | * @return 11 | */ 12 | public static boolean suffixFile(File file, String[] suffix) { 13 | if (suffix == null || suffix.length == 0) { 14 | return true; 15 | } 16 | boolean flag = false; 17 | String fileSuffix = file.getName().substring(file.getName().lastIndexOf(".") + 1); 18 | for (String suf : suffix) { 19 | if (suf.equals(fileSuffix)) { 20 | flag = true; 21 | } 22 | } 23 | return flag; 24 | } 25 | 26 | /*** 27 | * 判断文件是否存在 28 | * @param file 29 | * @return 30 | */ 31 | public static boolean checkFileExist(File file) { 32 | if (file.exists()) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/utils/RegexpUtil.java: -------------------------------------------------------------------------------- 1 | package com.eveino.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.io.LineNumberReader; 9 | import java.util.regex.Matcher; 10 | import java.util.regex.Pattern; 11 | 12 | /*** 13 | * 14 | * @author 小王子 15 | * @version 0.0.1 正则匹配 16 | */ 17 | public class RegexpUtil { 18 | /*** 19 | * 20 | * @param file 21 | * 传入需匹配的文件 22 | * @param regex 23 | * 传入正则 24 | * @return 匹配后的StringBuffer,正则对应文件的行号和所在行,为空则不存在 25 | * @throws FileNotFoundException 26 | * @throws IOException 27 | */ 28 | public static StringBuffer regexpParser(File file, String regex) throws FileNotFoundException, IOException { 29 | Pattern pattern = Pattern.compile(regex.toLowerCase()); 30 | LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); 31 | String line = null; 32 | StringBuffer stringBuffer = new StringBuffer(); 33 | while ((line = lnr.readLine()) != null) { 34 | Matcher matcher = pattern.matcher(line.toLowerCase()); 35 | if (matcher.find()) { 36 | stringBuffer.append(lnr.getLineNumber() + ":" + line + "\n"); 37 | } 38 | } 39 | lnr.close(); 40 | return stringBuffer; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/utils/UseUtil.java: -------------------------------------------------------------------------------- 1 | package com.eveino.utils; 2 | /*** 3 | * 4 | * @author 小王子 5 | * 6 | */ 7 | public class UseUtil { 8 | public static void usage() { 9 | System.out.println("usage: java -jar CAFJE.jar config.properties"); 10 | System.exit(0); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CAFJE/src/com/eveino/utils/XmlUtil.java: -------------------------------------------------------------------------------- 1 | package com.eveino.utils; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.dom4j.Document; 8 | import org.dom4j.DocumentException; 9 | import org.dom4j.Element; 10 | import org.dom4j.io.SAXReader; 11 | 12 | import com.eveino.entity.Vuln; 13 | 14 | /*** 15 | * 16 | * @author 小王子 17 | * @version 0.0.1 操作XML文件 18 | */ 19 | public class XmlUtil { 20 | 21 | /*** 22 | * 将XML转换成到Vuln实体 23 | * 24 | * @param file 25 | * 规则文件 26 | * @return 封装Vuln实体的list 27 | * @throws DocumentException 28 | */ 29 | public static List xml2Bean(File file) throws DocumentException { 30 | SAXReader reader = new SAXReader(); 31 | Document document = reader.read(file); 32 | Element root = document.getRootElement(); 33 | List list = new ArrayList<>(); 34 | List elements = root.elements("vuln"); 35 | for (Element element : elements) { 36 | Vuln vuln = new Vuln(); 37 | vuln.setName(element.attributeValue("name")); 38 | vuln.setId(element.attributeValue("id")); 39 | vuln.setRegexp(element.elementText("regexp")); 40 | vuln.setDecription(element.elementText("decription")); 41 | vuln.setRecommendation(element.elementText("recommendation")); 42 | vuln.setReference(element.elementText("reference")); 43 | list.add(vuln); 44 | } 45 | return list; 46 | } 47 | 48 | /*** 49 | * 解析规则根目录中的xml文件 50 | * 51 | * @param rulesPath 52 | * 配置文件根目录 53 | * @return 封装规则的list 54 | * @throws DocumentException 55 | */ 56 | public static List xmlPaser(String rulesPath) throws DocumentException { 57 | String[] suffix = { "xml" }; 58 | File file = new File(rulesPath); 59 | File[] files = file.listFiles(); 60 | List list = new ArrayList<>(); 61 | for (File f : files) { 62 | if (FileUtil.suffixFile(f, suffix)) { 63 | list.addAll(XmlUtil.xml2Bean(f)); 64 | } 65 | } 66 | return list; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /CAFJE/src/config.properties: -------------------------------------------------------------------------------- 1 | projectRoot=/home/snail/Develop-workspace/eclipse-workspace/VulnWeb 2 | rulesPath=src/rules 3 | suffix=jsp,java,html,css,js,xml -------------------------------------------------------------------------------- /CAFJE/src/rules/DemoRule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | demoRegexpHere 5 | 缺陷描述。 6 | 修复建议 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/src/rules/Exec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProcessBuilder|ProcessBuilder.start\(\) 5 | 使用ProcessBuilder执行系统命令。 6 | 严格过滤传入命令 7 | CWE链接: 8 | 9 | 10 | Runtime\.getRuntime\(\)\.exec|Runtime\.getRuntime() 11 | 使用Runtime执行系统命令。 12 | 严格过滤传入命令 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /CAFJE/src/rules/File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.createNewFile\(|FileOutputStream\( 5 | createNewFile。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | \.delete\(\) 11 | delete。 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | new\sFileInputStream\(/ 17 | FileInputStream。 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/src/rules/FilePathManipulation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\sFile\(|\.getRealPath\( 5 | 如果传入的路径可控,则攻击者可能控制文件系统路径参数,借此访问或修改其他受保护的文件。 6 | 确保传入路径合法并过滤../ ? 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/src/rules/FileUpload.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.getOriginalFilename\(|MultipartFile\s 5 | 使用MultipartFile上传文件,判断是否有文件类型过滤。 6 | 使用白名单判断文件类型。 7 | CWE链接: 8 | 9 | 10 | -------------------------------------------------------------------------------- /CAFJE/src/rules/IntranetIPLeak.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 10(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){3} 5 | 10.0.0.0-10.255.255.255 6 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 7 | CWE链接: 8 | 9 | 10 | 172\.([1][6-9]|[2]\d|3[01])(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 11 | 172.16.0.0-172.31.255.255 12 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 13 | CWE链接: 14 | 15 | 16 | 192\.168(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 17 | 192.168.0.0-192.168.255.255 18 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 19 | CWE链接: 20 | 21 | 22 | ([1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3} 23 | 1-3规则也会匹配到,此正则主要用于查看是否有外网地址泄露。 24 | 如果外网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 25 | CWE链接: 26 | 27 | -------------------------------------------------------------------------------- /CAFJE/src/rules/ObjectDeserialization.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.readObject\( 5 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 6 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 7 | CWE链接: 8 | 9 | 10 | JSON\.parseObject\( 11 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 12 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 13 | CWE链接: 14 | 15 | 16 | ObjectMapper\.readValue 17 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 18 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 19 | CWE链接: 20 | 21 | 22 | fromXML\( 23 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 24 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 25 | CWE链接: 26 | 27 | 28 | readUnshared\( 29 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 30 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 31 | CWE链接: 32 | 33 | -------------------------------------------------------------------------------- /CAFJE/src/rules/SQLiHibernate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(setString|\?)).)*createQuery((?!(setString|\?)).)*$ 5 | 判断该语句上下文是否预编译 6 | 通过参数绑定实现预编译: 1.name parameter 2.positional parameter 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/src/rules/SQLiIbatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\w+\$((?!(like|order)).)*$ 5 | $parameter$不是预编译,会有sql注入风险 6 | #parameter#预编译 7 | CWE链接: 8 | 9 | 10 | like.*\$\w+\$ 11 | SQLiIbatis2 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\w+\$ 17 | SQLiIbatis 18 | SQLiIbatis 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/src/rules/SQLiJdbc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^*sql\.Statement|\.createStatement\(\) 5 | 使用Statement,未预编译语句可能导致SQLi。 6 | 建议使用PreparedStatement进行预编译 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /CAFJE/src/rules/SQLiMybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\{\w+\}((?!(like|order)).)*$ 5 | SQLiMybatis 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | like\s+'\%\$\{\w+\}\% 11 | SQLiMybatis 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\{ 17 | SQLiMybatis3 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/src/rules/SSRF.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | URLConnection 5 | URLConnection 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | HttpURLConnection 11 | HttpURLConnection 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | HttpsURLConnection 17 | HttpsURLConnection 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/src/rules/URL-Redirect.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sendRedirect\( 5 | sendRedirect。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | setHeader\(\"refresh 11 | setHeader。 12 | 修复建议 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /CAFJE/src/rules/UserInfoLeak.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^username=|^username: 5 | 用户名硬编码 6 | 如非配置文件中,建议使用其他方式获取用户名,如从配置文件或数据库中获取。 7 | CWE链接: 8 | 9 | 10 | ^password=|^password: 11 | 密码硬编码 12 | 如非配置文件中,建议使用其他方式获取密码,如从配置文件或数据库中获取。 13 | CWE链接: 14 | 15 | 16 | add\sby 17 | 开发者信息泄露 18 | jsp文件中建议使用jsp注释<%--jsp注释--%>,避免输出页面时将注释展示在前端。JavaScript/html/css等能直接访问的文件,建议去除该信息,xml文件请忽略该缺陷。 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /CAFJE/src/rules/XSS.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | <%= 5 | JSP页面直接使用<%=输出变量,如未存在全局过滤器情况下,可能导致XSS。 6 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 7 | CWE链接: 8 | 9 | 10 | response\.getWriter* 11 | 直接使用response.getWriter向浏览器写数据,可能导致XSS。 12 | 建议使用jsp输出数据。 13 | CWE链接: 14 | 15 | 16 | response\.getOutputStream* 17 | 直接使用response.getOutputStream向浏览器写数据,可能导致XSS。 18 | 建议使用jsp输出数据。 19 | CWE链接: 20 | 21 | 22 | ^((?!(Cache-Control|Parama)).)*response\.setHeader*((?!(Cache-Control|Parama)).)*$ 23 | 直接使用response.setHeader向浏览器设置header,可能导致XSS。 24 | 建议在jsp中设置header。 25 | CWE链接: 26 | 27 | 28 | getJspContext\(\).getOut\(\)* 29 | 标签中直接使用getJspContext().getOut()向浏览器写数据,可能导致XSS。 30 | 建议。 31 | CWE链接: 32 | 33 | 34 | ^((?!(c:forEach|c:out|pageContext|if|when)).)*\$\{((?!(c:forEach|c:out|pageContext|if|when)).)*$ 35 | jsp输出变量,未做输出编码,可能导致XSS 36 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 37 | CWE链接: 38 | 39 | 40 | pageContext.getOut\(\) 41 | servlet直接向浏览器输出数据,可能导致XSS。 42 | 建议使用jsp输出数据。 43 | CWE链接: 44 | 45 | -------------------------------------------------------------------------------- /CAFJE/src/rules/XXE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\s+SAXReader\(\) 5 | SAXReader。 6 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 7 | CWE链接: 8 | 9 | 10 | new\s+SAXBuilder\(\) 11 | SAXBuilder。 12 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 13 | CWE链接: 14 | 15 | 16 | new\s+SAXParser\( 17 | SAXParser。 18 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 19 | CWE链接: 20 | 21 | 22 | createXMLReader\( 23 | XMLReader。 24 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 25 | CWE链接: 26 | 27 | 28 | newDocumentBuilder\( 29 | DocumentBuilder。 30 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 31 | CWE链接: 32 | 33 | 34 | createXMLStreamReader\( 35 | XMLStreamReader。 36 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 37 | CWE链接: 38 | 39 | -------------------------------------------------------------------------------- /Jar/CAFJE/CAFJE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtxiaowangzi/CAFJE/f537327917385473d7f113161d253f368cf7ba63/Jar/CAFJE/CAFJE.jar -------------------------------------------------------------------------------- /Jar/CAFJE/config.properties: -------------------------------------------------------------------------------- 1 | projectRoot=/home/snail/Develop-workspace/eclipse-workspace/VulnWeb 2 | rulesPath=rules 3 | suffix=jsp,java,html,css,js,xml 4 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/DemoRule.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | demoRegexpHere 5 | 缺陷描述。 6 | 修复建议 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/Exec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProcessBuilder|ProcessBuilder.start\(\) 5 | 使用ProcessBuilder执行系统命令。 6 | 严格过滤传入命令 7 | CWE链接: 8 | 9 | 10 | Runtime\.getRuntime\(\)\.exec|Runtime\.getRuntime() 11 | 使用Runtime执行系统命令。 12 | 严格过滤传入命令 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.createNewFile\(|FileOutputStream\( 5 | createNewFile。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | \.delete\(\) 11 | delete。 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | new\sFileInputStream\(/ 17 | FileInputStream。 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/FilePathManipulation.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\sFile\(|\.getRealPath\( 5 | 如果传入的路径可控,则攻击者可能控制文件系统路径参数,借此访问或修改其他受保护的文件。 6 | 确保传入路径合法并过滤../ ? 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/FileUpload.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.getOriginalFilename\(|MultipartFile\s 5 | 使用MultipartFile上传文件,判断是否有文件类型过滤。 6 | 使用白名单判断文件类型。 7 | CWE链接: 8 | 9 | 10 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/IntranetIPLeak.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 10(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){3} 5 | 10.0.0.0-10.255.255.255 6 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 7 | CWE链接: 8 | 9 | 10 | 172\.([1][6-9]|[2]\d|3[01])(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 11 | 172.16.0.0-172.31.255.255 12 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 13 | CWE链接: 14 | 15 | 16 | 192\.168(\.([2][0-4]\d|[2][5][0-5]|[01]?\d?\d)){2} 17 | 192.168.0.0-192.168.255.255 18 | 如果内网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 19 | CWE链接: 20 | 21 | 22 | ([1-9]|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])(\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])){3} 23 | 1-3规则也会匹配到,此正则主要用于查看是否有外网地址泄露。 24 | 如果外网地址能够获取到(如在html注释中或js代码中),建议将其删除或以其他方式替代。 25 | CWE链接: 26 | 27 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/ObjectDeserialization.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | \.readObject\( 5 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 6 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 7 | CWE链接: 8 | 9 | 10 | JSON\.parseObject\( 11 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 12 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 13 | CWE链接: 14 | 15 | 16 | ObjectMapper\.readValue 17 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 18 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 19 | CWE链接: 20 | 21 | 22 | fromXML\( 23 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 24 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 25 | CWE链接: 26 | 27 | 28 | readUnshared\( 29 | 如果反序列化的类在运行时对用户控制的对象流进行反序列化,会让攻击者有机会在服务器上执行任意代码、滥用应用程序逻辑或导致Denial of Service。 30 | 使用白名单确保能被反序列化的类,通过覆写resolveClass实现。 31 | CWE链接: 32 | 33 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/PrintStackTrace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .\.printStackTrace\(\); 5 | 异常消息使用printStackTrace直接打印,可能导致信息泄露。 6 | 将异常记录到日志或以其他方式处理异常。 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/SQLiHibernate.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(setString|\?)).)*createQuery((?!(setString|\?)).)*$ 5 | 判断该语句上下文是否预编译 6 | 通过参数绑定实现预编译: 1.name parameter 2.positional parameter 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/SQLiIbatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\w+\$((?!(like|order)).)*$ 5 | $parameter$不是预编译,会有sql注入风险 6 | #parameter#预编译 7 | CWE链接: 8 | 9 | 10 | like.*\$\w+\$ 11 | SQLiIbatis2 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\w+\$ 17 | SQLiIbatis 18 | SQLiIbatis 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/SQLiJdbc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^*sql\.Statement|\.createStatement\(\) 5 | 使用Statement,未预编译语句可能导致SQLi。 6 | 建议使用PreparedStatement进行预编译 7 | CWE链接: 8 | 9 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/SQLiMybatis.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^((?!(like|order)).)*\$\{\w+\}((?!(like|order)).)*$ 5 | SQLiMybatis 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | like\s+'\%\$\{\w+\}\% 11 | SQLiMybatis 12 | 使用连接符 13 | CWE链接: 14 | 15 | 16 | order\sby.*\$\{ 17 | SQLiMybatis3 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/SSRF.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | URLConnection 5 | URLConnection 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | HttpURLConnection 11 | HttpURLConnection 12 | 修复建议 13 | CWE链接: 14 | 15 | 16 | HttpsURLConnection 17 | HttpsURLConnection 18 | 修复建议 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/URL-Redirect.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | sendRedirect\( 5 | sendRedirect。 6 | 修复建议 7 | CWE链接: 8 | 9 | 10 | setHeader\(\"refresh 11 | setHeader。 12 | 修复建议 13 | CWE链接: 14 | 15 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/UserInfoLeak.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ^username=|^username: 5 | 用户名硬编码 6 | 如非配置文件中,建议使用其他方式获取用户名,如从配置文件或数据库中获取。 7 | CWE链接: 8 | 9 | 10 | ^password=|^password: 11 | 密码硬编码 12 | 如非配置文件中,建议使用其他方式获取密码,如从配置文件或数据库中获取。 13 | CWE链接: 14 | 15 | 16 | add\sby 17 | 开发者信息泄露 18 | jsp文件中建议使用jsp注释<%--jsp注释--%>,避免输出页面时将注释展示在前端。JavaScript/html/css等能直接访问的文件,建议去除该信息,xml文件请忽略该缺陷。 19 | CWE链接: 20 | 21 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/XSS.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | <%= 5 | JSP页面直接使用<%=输出变量,如未存在全局过滤器情况下,可能导致XSS。 6 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 7 | CWE链接: 8 | 9 | 10 | response\.getWriter* 11 | 直接使用response.getWriter向浏览器写数据,可能导致XSS。 12 | 建议使用jsp输出数据。 13 | CWE链接: 14 | 15 | 16 | response\.getOutputStream* 17 | 直接使用response.getOutputStream向浏览器写数据,可能导致XSS。 18 | 建议使用jsp输出数据。 19 | CWE链接: 20 | 21 | 22 | ^((?!(Cache-Control|Parama)).)*response\.setHeader*((?!(Cache-Control|Parama)).)*$ 23 | 直接使用response.setHeader向浏览器设置header,可能导致XSS。 24 | 建议在jsp中设置header。 25 | CWE链接: 26 | 27 | 28 | getJspContext\(\).getOut\(\)* 29 | 标签中直接使用getJspContext().getOut()向浏览器写数据,可能导致XSS。 30 | 建议。 31 | CWE链接: 32 | 33 | 34 | ^((?!(c:forEach|c:out|pageContext|if|when)).)*\$\{((?!(c:forEach|c:out|pageContext|if|when)).)*$ 35 | jsp输出变量,未做输出编码,可能导致XSS 36 | 如未存在全局的输出编码过滤器,如为输出到HTML实体,建议使用<c:out>标签进行HTML实体编码,其他按照输出位置进行编码。 37 | CWE链接: 38 | 39 | 40 | pageContext.getOut\(\) 41 | servlet直接向浏览器输出数据,可能导致XSS。 42 | 建议使用jsp输出数据。 43 | CWE链接: 44 | 45 | -------------------------------------------------------------------------------- /Jar/CAFJE/rules/XXE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | new\s+SAXReader\(\) 5 | SAXReader。 6 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 7 | CWE链接: 8 | 9 | 10 | new\s+SAXBuilder\(\) 11 | SAXBuilder。 12 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 13 | CWE链接: 14 | 15 | 16 | new\s+SAXParser\( 17 | SAXParser。 18 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 19 | CWE链接: 20 | 21 | 22 | createXMLReader\( 23 | XMLReader。 24 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 25 | CWE链接: 26 | 27 | 28 | newDocumentBuilder\( 29 | DocumentBuilder。 30 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 31 | CWE链接: 32 | 33 | 34 | createXMLStreamReader\( 35 | XMLStreamReader。 36 | 使用XML解析器时需要设置其属性,禁止使用外部实体。 37 | CWE链接: 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 小王子 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CAFJE 2 | Code Audit For Java Enterprise 3 | 4 | 一个代码审计的工具,计划包含以下分析引擎: 5 | 6 | 1. 语义分析:分析程序中不安全的函数,方法的使用的安全问题 7 | 2. 配置分析:分析项目配置文件中的敏感信息和配置缺失的安全问题 8 | 3. 数据流分析:跟踪,记录并分析程序中的数据传递过程的安全问题 9 | 4. 控制流分析:分析程序特定时间,状态下执行操作指令的安全问题 10 | 5. 结构分析:分析程序上下文环境,结构中的安全问题 11 | 12 | 目前完成: 13 | 14 | 正则匹配.....=-=,即引擎2(部分),规则还需优化 15 | 16 | ## 用法 17 | 18 | ``` 19 | java -jar CAFJE.jar config.properties 20 | ``` 21 | 22 | ## Rules 23 | 24 | ``` 25 | SSRF.xml 服务端请求伪造 26 | UserInfoLeak.xml 用户信息泄露 27 | SQLiHibernate.xml 28 | File.xml 操作文件 29 | XXE.xml XXE 30 | Exec.xml 命令执行 31 | SQLiIbatis.xml 32 | IntranetIPLeak.xml 33 | SQLiJdbc.xml 34 | SQLiMybatis.xml 35 | FilePathManipulation.xml 操作文件路径 36 | XSS.xml XSS 37 | DemoRule.xml 规则Demo 38 | URL-Redirect.xml 39 | ObjectDeserialization.xml 反序列化 40 | FileUpload.xml 文件上传 41 | ``` 42 | 43 | 更多:[CAFJE 又一个Java Web代码审计工具](http://eveino.com/216.html) 44 | --------------------------------------------------------------------------------