├── src ├── main │ ├── java │ │ └── xbear │ │ │ └── javaopenrasp │ │ │ ├── filters │ │ │ ├── SecurityFilterI.java │ │ │ ├── sql │ │ │ │ ├── MySQLFilter.java │ │ │ │ ├── SQLServerFilter.java │ │ │ │ └── SQLWallProviders.java │ │ │ └── rce │ │ │ │ ├── DeserializationFilter.java │ │ │ │ ├── OgnlFilter.java │ │ │ │ └── PrcessBuilderFilter.java │ │ │ ├── util │ │ │ ├── Console.java │ │ │ ├── StackTrace.java │ │ │ └── Reflections.java │ │ │ ├── Agent.java │ │ │ ├── visitors │ │ │ ├── rce │ │ │ │ ├── OgnlVisitor.java │ │ │ │ ├── ProcessBuilderVisitor.java │ │ │ │ ├── DeserializationVisitor.java │ │ │ │ ├── OgnlVisitorAdapter.java │ │ │ │ ├── DeserializationVisitorAdapter.java │ │ │ │ └── ProcessBuilderVisitorAdapter.java │ │ │ └── sql │ │ │ │ ├── MySQLVisitorAdapter.java │ │ │ │ ├── SQLServerVisitorAdapter.java │ │ │ │ ├── MySQLVisitor.java │ │ │ │ └── SQLServerVisitor.java │ │ │ ├── ClassTransformer.java │ │ │ └── config │ │ │ └── Config.java │ └── resources │ │ └── main.config └── test │ └── java │ └── xbear │ └── openjavarasp │ └── AppTest.java ├── .gitignore ├── README.md ├── .classpath ├── pom.xml └── LICENSE /src/main/java/xbear/javaopenrasp/filters/SecurityFilterI.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters; 2 | 3 | /** 4 | * Created by xbear on 2016/11/13. 5 | */ 6 | public interface SecurityFilterI { 7 | public boolean filter(Object forCheck); 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | *.iml 11 | *.old 12 | .idea 13 | .DS_Store 14 | classes 15 | .project 16 | .settings/ 17 | */.classpath 18 | */.gitignore 19 | */.project 20 | .gitignore 21 | antx.properties 22 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/util/Console.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.util; 2 | 3 | import java.io.PrintStream; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by xbear on 2016/11/13. 9 | */ 10 | public class Console { 11 | 12 | private static PrintStream ps = System.out; 13 | 14 | private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 15 | 16 | public static void log(String msg) { 17 | if (msg != null && !msg.equals("")) { 18 | ps.println("[javaopenrasp][" + df.format(new Date()) + "]:" + msg); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Open Rasp(Runtime Application Self-Protection) 2 | # A Java Rasp Demo 3 | 4 | ### Supported Vulnerabilites 5 | 6 | ## RCE 7 | 8 | 1. deserialize vulnerability 9 | 10 | 2. danger ognl expressions 11 | 12 | 3. ProcessBuilder log 13 | 14 | ## Sql Ingection 15 | 16 | 1. MySQL 17 | 18 | 2. SQLServer 19 | 20 | ### How to use: 21 | 22 | add "-javaagent:/path/javaopenrasp.jar" to your jvm arguments 23 | 24 | # Java Open Rasp 25 | 26 | 这是一个java rasp的验证性demo,已验证rasp的原理及实现 27 | 28 | ### 实现的保护点 29 | 30 | ## RCE 31 | 32 | 1. 反序列化漏洞 33 | 34 | 2. Ognl表达式执行 35 | 36 | 3. ProcessBuilder log 37 | 38 | ## SQL注入 39 | 40 | 1. MySql注入保护 41 | 42 | 2. SQLServer注入保护 43 | 44 | ## 使用方法 45 | 编译后,将"-javaagent:/path/javaopenrasp.jar"添加至JVM的启动参数 46 | 47 | E-Mail: xiongxbear@gmail.com 48 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/Agent.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp; 2 | 3 | import xbear.javaopenrasp.config.Config; 4 | import xbear.javaopenrasp.util.Console; 5 | 6 | import java.lang.instrument.Instrumentation; 7 | import java.lang.instrument.UnmodifiableClassException; 8 | 9 | /** 10 | * Created by xbear on 2016/11/13. 11 | */ 12 | public class Agent { 13 | 14 | public static void premain(String agentArgs, Instrumentation inst) 15 | throws ClassNotFoundException, UnmodifiableClassException { 16 | Console.log("init"); 17 | init(); 18 | inst.addTransformer(new ClassTransformer()); 19 | } 20 | 21 | private static boolean init() { 22 | Config.initConfig(); 23 | return true; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/xbear/openjavarasp/AppTest.java: -------------------------------------------------------------------------------- 1 | package xbear.openjavarasp; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase { 12 | /** 13 | * Create the test case 14 | * 15 | * @param testName name of the test case 16 | */ 17 | public AppTest(String testName) { 18 | super(testName); 19 | } 20 | 21 | /** 22 | * @return the suite of tests being tested 23 | */ 24 | public static Test suite() { 25 | return new TestSuite(AppTest.class); 26 | } 27 | 28 | /** 29 | * Rigourous Test :-) 30 | */ 31 | public void testApp() { 32 | assertTrue(true); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/OgnlVisitor.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * Created by xbear on 2016/11/13. 9 | */ 10 | public class OgnlVisitor extends ClassVisitor { 11 | 12 | public String className; 13 | 14 | public OgnlVisitor(ClassVisitor cv, String className) { 15 | super(Opcodes.ASM5, cv); 16 | this.className = className; 17 | } 18 | 19 | @Override 20 | public MethodVisitor visitMethod(int access, String name, String desc, 21 | String signature, String[] exceptions) { 22 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 23 | if ("parseExpression".equals(name) && "(Ljava/lang/String;)Ljava/lang/Object;".equals(desc)) { 24 | mv = new OgnlVisitorAdapter(mv, access, name, desc); 25 | } 26 | return mv; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/ProcessBuilderVisitor.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * Created by xbear on 2016/11/13. 9 | */ 10 | public class ProcessBuilderVisitor extends ClassVisitor { 11 | 12 | public String className; 13 | 14 | public ProcessBuilderVisitor(ClassVisitor cv, String className) { 15 | super(Opcodes.ASM5, cv); 16 | this.className = className; 17 | } 18 | 19 | @Override 20 | public MethodVisitor visitMethod(int access, String name, String desc, 21 | String signature, String[] exceptions) { 22 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 23 | if ("start".equals(name) && "()Ljava/lang/Process;".equals(desc)) { 24 | mv = new ProcessBuilderVisitorAdapter(mv, access, name, desc); 25 | } 26 | return mv; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/DeserializationVisitor.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | /** 8 | * Created by xbear on 2016/11/13. 9 | */ 10 | public class DeserializationVisitor extends ClassVisitor { 11 | public String className; 12 | 13 | public DeserializationVisitor(ClassVisitor cv, String className) { 14 | super(Opcodes.ASM5, cv); 15 | this.className = className; 16 | } 17 | 18 | @Override 19 | public MethodVisitor visitMethod(int access, String name, String desc, 20 | String signature, String[] exceptions) { 21 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 22 | if ("resolveClass".equals(name) && "(Ljava/io/ObjectStreamClass;)Ljava/lang/Class;".equals(desc)) { 23 | mv = new DeserializationVisitorAdapter(mv, access, name, desc); 24 | } 25 | return mv; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/util/StackTrace.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.util; 2 | 3 | /** 4 | * Created by xbear on 2016/11/13. 5 | */ 6 | public class StackTrace { 7 | 8 | public static String getStackTrace() { 9 | 10 | Throwable ex = new Throwable(); 11 | StackTraceElement[] stackElements = ex.getStackTrace(); 12 | StringBuilder retStack = new StringBuilder(); 13 | 14 | if (stackElements.length >= 3) { 15 | for (int i = 2; i < stackElements.length; i++) { 16 | retStack.append(stackElements[i].getClassName() + "@" + stackElements[i].getMethodName() + "\r\n"); 17 | } 18 | } else { 19 | for (int i = 0; i < stackElements.length; i++) { 20 | retStack.append(stackElements[i].getClassName() + "@" + stackElements[i].getMethodName() + "\r\n"); 21 | } 22 | } 23 | 24 | return retStack.toString(); 25 | } 26 | 27 | public static String getCaller() { 28 | 29 | Throwable ex = new Throwable(); 30 | StackTraceElement[] stackElements = ex.getStackTrace(); 31 | 32 | if (stackElements.length >= 3) { 33 | return stackElements[2].getClassName() + "@" + stackElements[1].getMethodName(); 34 | } else { 35 | return stackElements[1].getClassName() + "@" + stackElements[1].getMethodName(); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/OgnlVisitorAdapter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.Label; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.commons.AdviceAdapter; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class OgnlVisitorAdapter extends AdviceAdapter { 12 | public OgnlVisitorAdapter(MethodVisitor mv, int access, String name, String desc) { 13 | super(Opcodes.ASM5, mv, access, name, desc); 14 | } 15 | 16 | @Override 17 | protected void onMethodEnter() { 18 | 19 | Label l30 = new Label(); 20 | mv.visitLabel(l30); 21 | mv.visitVarInsn(ALOAD, 0); 22 | mv.visitMethodInsn(INVOKESTATIC, "xbear/javaopenrasp/filters/rce/OgnlFilter", "staticFilter", "(Ljava/lang/Object;)Z", false); 23 | Label l31 = new Label(); 24 | mv.visitJumpInsn(IFNE, l31); 25 | Label l32 = new Label(); 26 | mv.visitLabel(l32); 27 | mv.visitTypeInsn(NEW, "ognl/OgnlException"); 28 | mv.visitInsn(DUP); 29 | mv.visitLdcInsn("invalid class in ognl expression because of security"); 30 | mv.visitMethodInsn(INVOKESPECIAL, "ognl/OgnlException", "", "(Ljava/lang/String;)V", false); 31 | mv.visitInsn(ATHROW); 32 | mv.visitLabel(l31); 33 | 34 | } 35 | 36 | @Override 37 | public void visitMaxs(int maxStack, int maxLocals) { 38 | super.visitMaxs(maxStack, maxLocals); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/sql/MySQLFilter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.sql; 2 | 3 | import com.alibaba.druid.wall.WallCheckResult; 4 | import com.alibaba.druid.wall.WallProvider; 5 | import xbear.javaopenrasp.config.Config; 6 | import xbear.javaopenrasp.filters.SecurityFilterI; 7 | import xbear.javaopenrasp.util.Console; 8 | import xbear.javaopenrasp.util.StackTrace; 9 | 10 | /** 11 | * Created by xbear on 2016/11/13. 12 | */ 13 | public class MySQLFilter implements SecurityFilterI { 14 | @Override 15 | public boolean filter(Object forCheck) { 16 | String sql = ((String) forCheck).trim(); 17 | WallProvider provider = SQLWallProviders.getProvider("mysql"); 18 | 19 | Console.log("prepare to exec sql:" + sql); 20 | String mode = (String) Config.moudleMap.get("com/mysql/jdbc/StatementImpl").get("mode"); 21 | 22 | switch (mode) { 23 | case "check": 24 | Console.log("check: " + sql); 25 | WallCheckResult result = provider.check(sql); 26 | if (result.getViolations().size() > 0) { 27 | for (int i = 0; i < result.getViolations().size(); i++) { 28 | Console.log("Warning: " + result.getViolations().get(i).getMessage()); 29 | } 30 | return false; 31 | } 32 | return true; 33 | case "log": 34 | default: 35 | Console.log("exc sql: " + sql); 36 | Console.log("log stack trace:\r\n" + StackTrace.getStackTrace()); 37 | return true; 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/sql/SQLServerFilter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.sql; 2 | 3 | import com.alibaba.druid.wall.WallCheckResult; 4 | import com.alibaba.druid.wall.WallProvider; 5 | import xbear.javaopenrasp.config.Config; 6 | import xbear.javaopenrasp.filters.SecurityFilterI; 7 | import xbear.javaopenrasp.util.Console; 8 | import xbear.javaopenrasp.util.StackTrace; 9 | 10 | /** 11 | * Created by xbear on 2016/11/13. 12 | */ 13 | public class SQLServerFilter implements SecurityFilterI { 14 | @Override 15 | public boolean filter(Object forCheck) { 16 | String sql = ((String) forCheck).trim(); 17 | WallProvider provider = SQLWallProviders.getProvider("mysql"); 18 | 19 | Console.log("prepare to exec sql:" + sql); 20 | String mode = (String) Config.moudleMap.get("com/microsoft/jdbc/base/BaseStatement").get("mode"); 21 | 22 | switch (mode) { 23 | case "check": 24 | Console.log("check: " + sql); 25 | WallCheckResult result = provider.check(sql); 26 | if (result.getViolations().size() > 0) { 27 | for (int i = 0; i < result.getViolations().size(); i++) { 28 | Console.log("Warning: " + result.getViolations().get(i).getMessage()); 29 | } 30 | return false; 31 | } 32 | return true; 33 | case "log": 34 | default: 35 | Console.log("exc sql: " + sql); 36 | Console.log("log stack trace:\r\n" + StackTrace.getStackTrace()); 37 | return true; 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/DeserializationVisitorAdapter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.Label; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.commons.AdviceAdapter; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class DeserializationVisitorAdapter extends AdviceAdapter { 12 | public DeserializationVisitorAdapter(MethodVisitor mv, int access, String name, String desc) { 13 | super(Opcodes.ASM5, mv, access, name, desc); 14 | } 15 | 16 | @Override 17 | protected void onMethodEnter() { 18 | mv.visitTypeInsn(NEW, "xbear/javaopenrasp/filters/rce/DeserializationFilter"); 19 | mv.visitInsn(DUP); 20 | mv.visitMethodInsn(INVOKESPECIAL, "xbear/javaopenrasp/filters/rce/DeserializationFilter", "", "()V", false); 21 | mv.visitVarInsn(ASTORE, 2); 22 | mv.visitVarInsn(ALOAD, 2); 23 | mv.visitVarInsn(ALOAD, 1); 24 | mv.visitMethodInsn(INVOKEVIRTUAL, "xbear/javaopenrasp/filters/rce/DeserializationFilterr", "filter", "(Ljava/lang/Object;)Z", false); 25 | 26 | Label l92 = new Label(); 27 | mv.visitJumpInsn(IFNE, l92); 28 | mv.visitTypeInsn(NEW, "java/io/IOException"); 29 | mv.visitInsn(DUP); 30 | mv.visitLdcInsn("invalid class in deserialization because of security"); 31 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/IOException", "", "(Ljava/lang/String;)V", false); 32 | mv.visitInsn(ATHROW); 33 | mv.visitLabel(l92); 34 | 35 | } 36 | 37 | @Override 38 | public void visitMaxs(int maxStack, int maxLocals) { 39 | super.visitMaxs(maxStack, maxLocals); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/rce/DeserializationFilter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.rce; 2 | 3 | import xbear.javaopenrasp.config.Config; 4 | import xbear.javaopenrasp.filters.SecurityFilterI; 5 | import xbear.javaopenrasp.util.Console; 6 | import xbear.javaopenrasp.util.StackTrace; 7 | 8 | import java.io.ObjectStreamClass; 9 | 10 | /** 11 | * Created by xbear on 2016/11/13. 12 | */ 13 | public class DeserializationFilter implements SecurityFilterI { 14 | 15 | @Override 16 | public boolean filter(Object forCheck) { 17 | String moudleName = "java/io/ObjectInputStream"; 18 | ObjectStreamClass desc = (ObjectStreamClass) forCheck; 19 | String className = desc.getName(); 20 | String mode = (String) Config.moudleMap.get(moudleName).get("mode"); 21 | switch (mode) { 22 | case "block": 23 | Console.log("block: " + className); 24 | return false; 25 | case "white": 26 | if (Config.isWhite(moudleName, className)) { 27 | Console.log("pass: " + className); 28 | return true; 29 | } 30 | Console.log("block:" + className); 31 | return false; 32 | case "black": 33 | if (Config.isBlack(moudleName, className)) { 34 | Console.log("block: " + className); 35 | return false; 36 | } 37 | Console.log("pass: " + className); 38 | return true; 39 | case "log": 40 | default: 41 | Console.log("pass: " + className); 42 | Console.log("log stack trace:\r\n" + StackTrace.getStackTrace()); 43 | return true; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/sql/SQLWallProviders.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.sql; 2 | 3 | import com.alibaba.druid.wall.WallProvider; 4 | import com.alibaba.druid.wall.spi.MySqlWallProvider; 5 | import com.alibaba.druid.wall.spi.SQLServerWallProvider; 6 | import xbear.javaopenrasp.util.Console; 7 | 8 | import java.util.Map; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | /** 12 | * Created by xbear on 2016/11/13. 13 | */ 14 | public class SQLWallProviders { 15 | 16 | private static Map providerMap = new ConcurrentHashMap(); 17 | 18 | public static WallProvider getProvider(String dbType) { 19 | switch (dbType.trim()) { 20 | case "mysql": 21 | if (!providerMap.containsKey("mysql")) { 22 | providerMap.put("mysql", new MySqlWallProvider()); 23 | setConfig(providerMap.get("mysql")); 24 | } 25 | return providerMap.get("mysql"); 26 | case "sqlserver": 27 | if (!providerMap.containsKey("sqlserver")) { 28 | providerMap.put("sqlserver", new SQLServerWallProvider()); 29 | setConfig(providerMap.get("sqlserver")); 30 | } 31 | return providerMap.get("sqlserver"); 32 | default: 33 | if (!providerMap.containsKey("mysql")) { 34 | providerMap.put("mysql", new MySqlWallProvider()); 35 | setConfig(providerMap.get("mysql")); 36 | } 37 | return providerMap.get("mysql"); 38 | } 39 | } 40 | 41 | private static void setConfig(WallProvider provider) { 42 | provider.getConfig().setCommentAllow(false); 43 | //set you want 44 | Console.log(provider.getBlackList().toString()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/rce/ProcessBuilderVisitorAdapter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.rce; 2 | 3 | import org.objectweb.asm.Label; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.commons.AdviceAdapter; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class ProcessBuilderVisitorAdapter extends AdviceAdapter { 12 | public ProcessBuilderVisitorAdapter(MethodVisitor mv, int access, String name, String desc) { 13 | super(Opcodes.ASM5, mv, access, name, desc); 14 | } 15 | 16 | @Override 17 | protected void onMethodEnter() { 18 | mv.visitTypeInsn(NEW, "xbear/javaopenrasp/filters/rce/PrcessBuilderFilter"); 19 | mv.visitInsn(DUP); 20 | mv.visitMethodInsn(INVOKESPECIAL, "xbear/javaopenrasp/filters/rce/PrcessBuilderFilter", "", "()V", false); 21 | mv.visitVarInsn(ASTORE, 1); 22 | mv.visitVarInsn(ALOAD, 1); 23 | mv.visitVarInsn(ALOAD, 0); 24 | mv.visitFieldInsn(GETFIELD, "java/lang/ProcessBuilder", "command", "Ljava/util/List;"); 25 | mv.visitMethodInsn(INVOKEVIRTUAL, "xbear/javaopenrasp/filters/rce/PrcessBuilderFilter", "filter", "(Ljava/lang/Object;)Z", false); 26 | 27 | Label l92 = new Label(); 28 | mv.visitJumpInsn(IFNE, l92); 29 | mv.visitTypeInsn(NEW, "java/io/IOException"); 30 | mv.visitInsn(DUP); 31 | mv.visitLdcInsn("invalid character in command because of security"); 32 | mv.visitMethodInsn(INVOKESPECIAL, "java/io/IOException", "", "(Ljava/lang/String;)V", false); 33 | mv.visitInsn(ATHROW); 34 | mv.visitLabel(l92); 35 | 36 | } 37 | 38 | @Override 39 | public void visitMaxs(int maxStack, int maxLocals) { 40 | super.visitMaxs(maxStack, maxLocals); 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/sql/MySQLVisitorAdapter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.sql; 2 | 3 | import org.objectweb.asm.Label; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.commons.AdviceAdapter; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class MySQLVisitorAdapter extends AdviceAdapter { 12 | public MySQLVisitorAdapter(MethodVisitor mv, int access, String name, String desc) { 13 | super(Opcodes.ASM5, mv, access, name, desc); 14 | } 15 | 16 | @Override 17 | protected void onMethodEnter() { 18 | mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); 19 | mv.visitLdcInsn("Already in sql"); 20 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); 21 | 22 | mv.visitTypeInsn(NEW, "xbear/javaopenrasp/filters/sql/MySQLFilter"); 23 | mv.visitInsn(DUP); 24 | mv.visitMethodInsn(INVOKESPECIAL, "xbear/javaopenrasp/filters/sql/MySQLFilter", "", "()V", false); 25 | mv.visitVarInsn(ASTORE, 3); 26 | mv.visitVarInsn(ALOAD, 3); 27 | mv.visitVarInsn(ALOAD, 1); 28 | mv.visitMethodInsn(INVOKEVIRTUAL, "xbear/javaopenrasp/filters/sql/MySQLFilter", "filter", "(Ljava/lang/Object;)Z", false); 29 | 30 | Label l92 = new Label(); 31 | mv.visitJumpInsn(IFNE, l92); 32 | mv.visitTypeInsn(NEW, "java/sql/SQLException"); 33 | mv.visitInsn(DUP); 34 | mv.visitLdcInsn("invalid sql because of security"); 35 | mv.visitMethodInsn(INVOKESPECIAL, "java/sql/SQLException", "", "(Ljava/lang/String;)V", false); 36 | mv.visitInsn(ATHROW); 37 | mv.visitLabel(l92); 38 | 39 | } 40 | 41 | @Override 42 | public void visitMaxs(int maxStack, int maxLocals) { 43 | super.visitMaxs(maxStack, maxLocals); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/sql/SQLServerVisitorAdapter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.sql; 2 | 3 | import org.objectweb.asm.Label; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | import org.objectweb.asm.commons.AdviceAdapter; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class SQLServerVisitorAdapter extends AdviceAdapter { 12 | public SQLServerVisitorAdapter(MethodVisitor mv, int access, String name, String desc) { 13 | super(Opcodes.ASM5, mv, access, name, desc); 14 | } 15 | 16 | @Override 17 | protected void onMethodEnter() { 18 | mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); 19 | mv.visitLdcInsn("Already in sql"); 20 | mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false); 21 | 22 | mv.visitTypeInsn(NEW, "xbear/javaopenrasp/filters/sql/SQLServerFilter"); 23 | mv.visitInsn(DUP); 24 | mv.visitMethodInsn(INVOKESPECIAL, "xbear/javaopenrasp/filters/sql/SQLServerFilter", "", "()V", false); 25 | mv.visitVarInsn(ASTORE, 3); 26 | mv.visitVarInsn(ALOAD, 3); 27 | mv.visitVarInsn(ALOAD, 1); 28 | mv.visitMethodInsn(INVOKEVIRTUAL, "xbear/javaopenrasp/filters/sql/SQLServerFilter", "filter", "(Ljava/lang/Object;)Z", false); 29 | 30 | Label l92 = new Label(); 31 | mv.visitJumpInsn(IFNE, l92); 32 | mv.visitTypeInsn(NEW, "java/sql/SQLException"); 33 | mv.visitInsn(DUP); 34 | mv.visitLdcInsn("invalid sql because of security"); 35 | mv.visitMethodInsn(INVOKESPECIAL, "java/sql/SQLException", "", "(Ljava/lang/String;)V", false); 36 | mv.visitInsn(ATHROW); 37 | mv.visitLabel(l92); 38 | 39 | } 40 | 41 | @Override 42 | public void visitMaxs(int maxStack, int maxLocals) { 43 | super.visitMaxs(maxStack, maxLocals); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/rce/OgnlFilter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.rce; 2 | 3 | import xbear.javaopenrasp.config.Config; 4 | import xbear.javaopenrasp.filters.SecurityFilterI; 5 | import xbear.javaopenrasp.util.Console; 6 | import xbear.javaopenrasp.util.StackTrace; 7 | 8 | /** 9 | * Created by xbear on 2016/11/13. 10 | */ 11 | public class OgnlFilter implements SecurityFilterI { 12 | 13 | public static boolean staticFilter(Object forCheck) { 14 | String moudleName = "ognl/Ognl"; 15 | String ognlExpression = (String) forCheck; 16 | Console.log("prepare to parse ognlExpression:" + ognlExpression); 17 | String mode = (String) Config.moudleMap.get("ognl/Ognl").get("mode"); 18 | switch (mode) { 19 | case "block": 20 | Console.log("block" + ognlExpression); 21 | return false; 22 | case "white": 23 | if (Config.isWhite(moudleName, ognlExpression)) { 24 | Console.log("parse ognlExpression:" + ognlExpression); 25 | return true; 26 | } 27 | Console.log("block" + ognlExpression); 28 | return false; 29 | case "black": 30 | if (Config.isBlack(moudleName, ognlExpression)) { 31 | Console.log("block parse ognlExpression" + ognlExpression); 32 | return false; 33 | } 34 | Console.log("exec command:" + ognlExpression); 35 | return true; 36 | case "log": 37 | default: 38 | Console.log("parse ognlExpression" + ognlExpression); 39 | Console.log("log stack trace:\r\n" + StackTrace.getStackTrace()); 40 | return true; 41 | } 42 | } 43 | 44 | @Override 45 | public boolean filter(Object forCheck) { 46 | return true; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/filters/rce/PrcessBuilderFilter.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.filters.rce; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import xbear.javaopenrasp.config.Config; 5 | import xbear.javaopenrasp.filters.SecurityFilterI; 6 | import xbear.javaopenrasp.util.Console; 7 | import xbear.javaopenrasp.util.StackTrace; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by xbear on 2016/11/13. 13 | */ 14 | public class PrcessBuilderFilter implements SecurityFilterI { 15 | 16 | @Override 17 | public boolean filter(Object forCheck) { 18 | String moudleName = "java/lang/ProcessBuilder"; 19 | List commandList = (List) forCheck; 20 | String command = StringUtils.join(commandList, " ").trim().toLowerCase(); 21 | Console.log("prepare to exec command:" + command); 22 | String mode = (String) Config.moudleMap.get(moudleName).get("mode"); 23 | switch (mode) { 24 | case "block": 25 | Console.log("block" + command); 26 | return false; 27 | case "white": 28 | if (Config.isWhite(moudleName, command)) { 29 | Console.log("exec command:" + command); 30 | return true; 31 | } 32 | Console.log("block" + command); 33 | return false; 34 | case "black": 35 | if (Config.isBlack(moudleName, command)) { 36 | Console.log("block command exec" + command); 37 | return false; 38 | } 39 | Console.log("exec command:" + command); 40 | return true; 41 | case "log": 42 | default: 43 | Console.log("exc commond" + command); 44 | Console.log("log stack trace:\r\n" + StackTrace.getStackTrace()); 45 | return true; 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/util/Reflections.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.util; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | 5 | import java.lang.reflect.Constructor; 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.InvocationTargetException; 8 | 9 | /** 10 | * Created by xbear on 2016/11/13. 11 | */ 12 | public class Reflections { 13 | 14 | public static Field getField(final Class clazz, final String fieldName) throws Exception { 15 | Field field = clazz.getDeclaredField(fieldName); 16 | if (field != null) 17 | field.setAccessible(true); 18 | else if (clazz.getSuperclass() != null) 19 | field = getField(clazz.getSuperclass(), fieldName); 20 | return field; 21 | } 22 | 23 | public static void setFieldValue(final Object obj, final String fieldName, final Object value) throws Exception { 24 | final Field field = getField(obj.getClass(), fieldName); 25 | field.set(obj, value); 26 | } 27 | 28 | public static Object getFieldValue(final Object obj, final String fieldName) throws Exception { 29 | final Field field = getField(obj.getClass(), fieldName); 30 | return field.get(obj); 31 | } 32 | 33 | public static Constructor getFirstCtor(final String name) throws Exception { 34 | final Constructor ctor = Class.forName(name).getDeclaredConstructors()[0]; 35 | ctor.setAccessible(true); 36 | return ctor; 37 | } 38 | 39 | @SuppressWarnings("unchecked") 40 | public static T createVisitorIns(final String name, ClassVisitor cv, String className) 41 | throws Exception, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { 42 | Constructor ctor = Class.forName(name).getDeclaredConstructor(new Class[]{ClassVisitor.class, String.class}); 43 | ctor.setAccessible(true); 44 | return (T) ctor.newInstance(new Object[]{cv, className}); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/sql/MySQLVisitor.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.sql; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * Created by xbear on 2016/11/13. 12 | */ 13 | public class MySQLVisitor extends ClassVisitor { 14 | 15 | private static final Set methodName = new HashSet() {{ 16 | add("executeQuery"); 17 | add("execute"); 18 | add("executeUpdate"); 19 | add("addBatch"); 20 | }}; 21 | private static final Set descName = new HashSet() {{ 22 | add("(Ljava/lang/String;I)I"); 23 | add("(Ljava/lang/String;[Ljava/lang/String;)I"); 24 | add("(Ljava/lang/String;[I)I"); 25 | add("(Ljava/lang/String;)Ljava/sql/ResultSet;"); 26 | add("(Ljava/lang/String;)Z"); 27 | add("(Ljava/lang/String;I)Z"); 28 | add("(Ljava/lang/String;[Ljava/lang/String;)Z"); 29 | add("(Ljava/lang/String;[I)Z"); 30 | add("(Ljava/lang/String;[I)J"); 31 | add("(Ljava/lang/String;[Ljava/lang/String;)J"); 32 | add("(Ljava/lang/String;I)J"); 33 | add("(Ljava/lang/String;)J"); 34 | add("(Ljava/lang/String;)I"); 35 | }}; 36 | public String className; 37 | 38 | public MySQLVisitor(ClassVisitor cv, String className) { 39 | super(Opcodes.ASM5, cv); 40 | this.className = className; 41 | } 42 | 43 | @Override 44 | public MethodVisitor visitMethod(int access, String name, String desc, 45 | String signature, String[] exceptions) { 46 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 47 | if (methodName.contains(name) && descName.contains(desc)) { 48 | mv = new MySQLVisitorAdapter(mv, access, name, desc); 49 | } 50 | return mv; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/visitors/sql/SQLServerVisitor.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.visitors.sql; 2 | 3 | import org.objectweb.asm.ClassVisitor; 4 | import org.objectweb.asm.MethodVisitor; 5 | import org.objectweb.asm.Opcodes; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * Created by xbear on 2016/11/13. 12 | */ 13 | public class SQLServerVisitor extends ClassVisitor { 14 | 15 | private static final Set methodName = new HashSet() {{ 16 | add("executeQuery"); 17 | add("execute"); 18 | add("executeUpdate"); 19 | add("addBatch"); 20 | }}; 21 | private static final Set descName = new HashSet() {{ 22 | add("(Ljava/lang/String;I)I"); 23 | add("(Ljava/lang/String;[Ljava/lang/String;)I"); 24 | add("(Ljava/lang/String;[I)I"); 25 | add("(Ljava/lang/String;)Ljava/sql/ResultSet;"); 26 | add("(Ljava/lang/String;)Z"); 27 | add("(Ljava/lang/String;I)Z"); 28 | add("(Ljava/lang/String;[Ljava/lang/String;)Z"); 29 | add("(Ljava/lang/String;[I)Z"); 30 | add("(Ljava/lang/String;[I)J"); 31 | add("(Ljava/lang/String;[Ljava/lang/String;)J"); 32 | add("(Ljava/lang/String;I)J"); 33 | add("(Ljava/lang/String;)J"); 34 | add("(Ljava/lang/String;)I"); 35 | }}; 36 | public String className; 37 | 38 | public SQLServerVisitor(ClassVisitor cv, String className) { 39 | super(Opcodes.ASM5, cv); 40 | this.className = className; 41 | } 42 | 43 | @Override 44 | public MethodVisitor visitMethod(int access, String name, String desc, 45 | String signature, String[] exceptions) { 46 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 47 | if (methodName.contains(name) && descName.contains(desc)) { 48 | mv = new SQLServerVisitorAdapter(mv, access, name, desc); 49 | } 50 | return mv; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/ClassTransformer.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp; 2 | 3 | import org.objectweb.asm.ClassReader; 4 | import org.objectweb.asm.ClassVisitor; 5 | import org.objectweb.asm.ClassWriter; 6 | import xbear.javaopenrasp.config.Config; 7 | import xbear.javaopenrasp.util.Reflections; 8 | 9 | import java.lang.instrument.ClassFileTransformer; 10 | import java.lang.instrument.IllegalClassFormatException; 11 | import java.lang.reflect.InvocationTargetException; 12 | import java.security.ProtectionDomain; 13 | 14 | /** 15 | * Created by xbear on 2016/11/13. 16 | */ 17 | public class ClassTransformer implements ClassFileTransformer { 18 | 19 | public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, 20 | ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { 21 | byte[] transformeredByteCode = classfileBuffer; 22 | 23 | if (Config.moudleMap.containsKey(className)) { 24 | try { 25 | ClassReader reader = new ClassReader(classfileBuffer); 26 | ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); 27 | ClassVisitor visitor = Reflections.createVisitorIns((String) Config.moudleMap.get(className).get("loadClass"), writer, className); 28 | reader.accept(visitor, ClassReader.EXPAND_FRAMES); 29 | transformeredByteCode = writer.toByteArray(); 30 | } catch (ClassNotFoundException e) { 31 | e.printStackTrace(); 32 | } catch (NoSuchMethodException e) { 33 | e.printStackTrace(); 34 | } catch (InstantiationException e) { 35 | e.printStackTrace(); 36 | } catch (IllegalAccessException e) { 37 | e.printStackTrace(); 38 | } catch (InvocationTargetException e) { 39 | e.printStackTrace(); 40 | } catch (Exception e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | return transformeredByteCode; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/resources/main.config: -------------------------------------------------------------------------------- 1 | { 2 | "moudle": 3 | [ 4 | { 5 | "moudleName": "java/lang/ProcessBuilder", 6 | "loadClass": "xbear.javaopenrasp.visitors.rce.ProcessBuilderVisitor", 7 | "mode": "log", 8 | "whiteList":[], 9 | "blackList": 10 | [ 11 | "calc", "etc", "var", "opt", "apache", "bin", "passwd", "login", "cshrc", "profile", "ifconfig", "tcpdump", "chmod", 12 | "cron", "sudo", "su", "rm", "wget", "sz", "kill", "apt-get", "find" 13 | ] 14 | }, 15 | { 16 | "moudleName": "java/io/ObjectInputStream", 17 | "loadClass": "xbear.javaopenrasp.visitors.rce.DeserializationVisitor", 18 | "mode": "black", 19 | "whiteList":[], 20 | "blackList": 21 | [ 22 | "org.apache.commons.collections.functors.InvokerTransformer", 23 | "org.apache.commons.collections.functors.InstantiateTransformer", 24 | "org.apache.commons.collections4.functors.InvokerTransformer", 25 | "org.apache.commons.collections4.functors.InstantiateTransformer", 26 | "org.codehaus.groovy.runtime.ConvertedClosure", 27 | "org.codehaus.groovy.runtime.MethodClosure", 28 | "org.springframework.beans.factory.ObjectFactory" 29 | ] 30 | }, 31 | { 32 | "moudleName": "ognl/Ognl", 33 | "loadClass": "xbear.javaopenrasp.visitors.rce.OgnlVisitor", 34 | "mode": "black", 35 | "whiteList":[], 36 | "blackList": 37 | [ 38 | "ognl.OgnlContext", 39 | "ognl.TypeConverter", 40 | "ognl.MemberAccess", 41 | "_memberAccess", 42 | "ognl.ClassResolver", 43 | "java.lang.Runtime", 44 | "java.lang.Class", 45 | "java.lang.ClassLoader", 46 | "java.lang.System", 47 | "java.lang.ProcessBuilder", 48 | "java.lang.Object", 49 | "java.lang.Shutdown", 50 | "java.io.File", 51 | "javax.script.ScriptEngineManager", 52 | "com.opensymphony.xwork2.ActionContext", 53 | ] 54 | }, 55 | { 56 | "moudleName": "com/mysql/jdbc/StatementImpl", 57 | "loadClass": "xbear.javaopenrasp.visitors.sql.MySQLVisitor", 58 | "mode": "check", 59 | "whiteList":[], 60 | "blackList":[] 61 | }, 62 | { 63 | "moudleName": "com/microsoft/jdbc/base/BaseStatement", 64 | "loadClass": "xbear.javaopenrasp.visitors.sql.SQLServerVisitor", 65 | "mode": "check", 66 | "whiteList":[], 67 | "blackList":[] 68 | } 69 | ] 70 | } -------------------------------------------------------------------------------- /src/main/java/xbear/javaopenrasp/config/Config.java: -------------------------------------------------------------------------------- 1 | package xbear.javaopenrasp.config; 2 | 3 | import java.io.*; 4 | import java.util.Collection; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.concurrent.ConcurrentHashMap; 8 | import java.util.concurrent.CopyOnWriteArrayList; 9 | 10 | import com.alibaba.druid.support.json.JSONUtils; 11 | 12 | import xbear.javaopenrasp.util.Console; 13 | 14 | /** 15 | * Created by xbear on 2016/11/13. 16 | */ 17 | public class Config { 18 | 19 | public static Map> moudleMap = new ConcurrentHashMap>(); 20 | 21 | @SuppressWarnings({ "rawtypes", "unchecked" }) 22 | public static boolean initConfig() { 23 | String configStr = readConfig("/main.config"); 24 | if (configStr == null) { 25 | Console.log("init failed because of config file error"); 26 | return false; 27 | } 28 | 29 | Map configMap = (Map) JSONUtils.parse(configStr); 30 | List moudleList = (List) configMap.get("moudle"); 31 | for (Map m: moudleList) { 32 | Map tmpMap = new ConcurrentHashMap(); 33 | tmpMap.put("loadClass", m.get("loadClass")); 34 | tmpMap.put("mode", m.get("mode")); 35 | tmpMap.put("whiteList", new CopyOnWriteArrayList((Collection) m.get("whiteList"))); 36 | tmpMap.put("blackList", new CopyOnWriteArrayList((Collection) m.get("blackList"))); 37 | moudleMap.put((String)m.get("moudleName"), tmpMap); 38 | } 39 | Console.log(moudleMap.toString()); 40 | 41 | return true; 42 | } 43 | 44 | public static String readConfig(String filename) { 45 | 46 | BufferedReader reader = new BufferedReader(new InputStreamReader(Config.class.getResourceAsStream(filename))); 47 | StringBuilder sb = new StringBuilder(); 48 | String line = null; 49 | try { 50 | while ((line = reader.readLine()) != null) { 51 | sb.append(line.trim()); 52 | } 53 | } catch (IOException e) { 54 | e.printStackTrace(); 55 | } 56 | Console.log(sb.toString()); 57 | return sb.toString(); 58 | 59 | } 60 | 61 | @SuppressWarnings("unchecked") 62 | public static boolean isBlack(String moudleName, String testStr) { 63 | List blackList = (List) moudleMap.get(moudleName).get("blackList"); 64 | for (String black: blackList) { 65 | if (testStr.trim().toLowerCase().indexOf(black.trim().toLowerCase()) > -1) { 66 | return true; 67 | } 68 | } 69 | return false; 70 | } 71 | 72 | @SuppressWarnings("unchecked") 73 | public static boolean isWhite(String moudleName, String testStr) { 74 | List whiteList = (List) moudleMap.get(moudleName).get("whiteList"); 75 | if (whiteList.size() == 0) { 76 | return false; 77 | } 78 | for (String white: whiteList) { 79 | if (testStr.trim().equals(white.trim())) { 80 | return false; 81 | } 82 | } 83 | return true; 84 | } 85 | 86 | public static void main(String[] args) { 87 | initConfig(); 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | xbear 6 | javaopenrasp 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | 11 | UTF-8 12 | 1.7 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 3.8.1 20 | test 21 | 22 | 23 | org.ow2.asm 24 | asm-debug-all 25 | 5.1 26 | 27 | 28 | org.apache.commons 29 | commons-lang3 30 | 3.5 31 | 32 | 33 | com.alibaba 34 | druid 35 | 1.0.23 36 | 37 | 38 | 39 | 40 | javaopenrasp 41 | 42 | 43 | org.apache.maven.plugins 44 | maven-shade-plugin 45 | 1.6 46 | 47 | 48 | package 49 | 50 | shade 51 | 52 | 53 | 54 | 55 | 56 | org.apache.maven.plugins 57 | maven-jar-plugin 58 | 2.3.1 59 | 60 | 61 | 62 | 63 | 64 | xbear.javaopenrasp.Agent 65 | xbear.javaopenrasp.Agent 66 | ${build.finalName}.jar 67 | true 68 | true 69 | true 70 | ${maven.build.timestamp} 71 | 72 | 73 | 74 | 75 | 76 | org.apache.maven.plugins 77 | maven-compiler-plugin 78 | 79 | ${jdk.version} 80 | ${jdk.version} 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------