Merge branch 'development' into feature/PushBulletNotifications

This commit is contained in:
Emma Stone
2017-02-03 15:46:39 +00:00
committed by GitHub
11 changed files with 168 additions and 84 deletions
@@ -20,19 +20,18 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
private String className;
private static PrintStream str_out, class_out, dec_out;
private static PrintStream str_out, class_out;
static {
redirects.put("java/awt/Toolkit", ToolkitRedirect.class);
redirects.put("java/lang/Class", ClassRedirect.class);
redirects.put("java/lang/ClassLoader", ClassLoaderRedirect.class);
// redirects.put("java/lang/ClassLoader", ClassLoaderRedirect.class);
redirects.put("java/lang/Runtime", RuntimeRedirect.class);
redirects.put("java/lang/Thread", ThreadRedirect.class);
redirects.put("java/lang/StackTraceElement",
StackTraceElementRedirect.class);
redirects.put("java/lang/ProcessBuilder", ProcessBuilderRedirect.class);
redirects.put("java/lang/System", SystemRedirect.class);
redirects.put("java/io/File", FileRedirect.class);
}
public RedirectClassAdapter(ClassVisitor cv) {
@@ -40,31 +39,27 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
if (str_out == null && Core.shouldDump())
try {
str_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"strings.txt")));
dec_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"decrypted_strings.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(class_out == null && Core.shouldDump())
try {
class_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"classes.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
@Override
public void visit(int version, int access, String name, String signature,
String superName, String[] interfaces) {
String superName, String[] interfaces) {
this.className = name;
super.visit(version, access, name, signature, superName, interfaces);
if(class_out != null) {
class_out.println(className + " References:");
}
}
@Override
public void visitEnd(){
super.visitEnd();
@@ -76,7 +71,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
String signature, String[] exceptions) {
String signature, String[] exceptions) {
return new ReflectionMethodVisitor(name, desc, super.visitMethod(
access, name, desc, signature, exceptions));
}
@@ -84,45 +79,43 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
private class ReflectionMethodVisitor extends MethodVisitor {
public ReflectionMethodVisitor(String name, String desc,
MethodVisitor mv) {
MethodVisitor mv) {
super(ASM5, mv);
}
@Override
public void visitLdcInsn(Object o) {
if (o instanceof String && str_out != null) {
str_out.println(className + " " + o);
if (!className.toLowerCase().contains("parabot")) {
dec_out.println(o + ":");
dec_out.println();
}
}
if (o instanceof String && str_out != null) {
str_out.println(className + " " + o);
}
super.visitLdcInsn(o);
}
@Override
public void visitMethodInsn(int opcode, String owner, String name,
String desc) {
String desc, boolean itf) {
if (Core.isSecure()) {
if (redirects.containsKey(owner) && !name.equals("<init>")
&& !name.equals("<clinit>")) {
if (opcode != INVOKESTATIC)
if (opcode != INVOKESTATIC) {
desc = "(L" + owner + ";" + desc.substring(1);
}
opcode = INVOKESTATIC;
owner = redirects.get(owner).getName()
.replaceAll("\\.", "/");
}
}
if(class_out != null)
class_out.println(owner);
super.visitMethodInsn(opcode, owner, name, desc);
if(class_out != null) {
class_out.println(owner);
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
@Override
public void visitFieldInsn(int opcode, String owner, String name,
String desc){
String desc){
if (Core.isSecure() && (opcode == GETSTATIC || opcode == PUTSTATIC)) {
if (redirects.containsKey(owner)) {
owner = redirects.get(owner).getName()
@@ -133,7 +126,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
class_out.println(owner);
super.visitFieldInsn(opcode, owner, name, desc);
}
}
public static SecurityException createSecurityException() {
@@ -1,15 +1,53 @@
package org.parabot.core.asm.redirect;
import org.parabot.core.Core;
import org.parabot.core.asm.RedirectClassAdapter;
public class ClassLoaderRedirect {
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
public class ClassLoaderRedirect extends ClassLoader {
static int count = 0;
public static Class<?>loadClass(ClassLoader c,String name){
throw RedirectClassAdapter.createSecurityException();
}
static int count = 0;
public static ClassLoader getParent(ClassLoader c){
throw RedirectClassAdapter.createSecurityException();
}
public static URL getResource(ClassLoader classLoader, String name) {
Core.verbose("#getResource requested for ClassLoaderRedirect (" + name + ")");
return classLoader.getResource(name);
}
public static Enumeration<URL> getResources(ClassLoader classLoader, String name) throws IOException {
Core.verbose("#getResource requested for ClassLoaderRedirect (" + name + ")");
return classLoader.getResources(name);
}
public static InputStream getResourceAsStream(ClassLoader classLoader, String name) {
Core.verbose("#getResourceAsStream requested for ClassLoaderRedirect (" + name + ")");
return classLoader.getResourceAsStream(name);
}
public static void setDefaultAssertionStatus(ClassLoader classLoader, boolean enabled) {
}
public static void setPackageAssertionStatus(ClassLoader classLoader, String packageName, boolean enabled) {
}
public static void setClassAssertionStatus(ClassLoader classLoader, String className, boolean enabled) {
}
public static void clearAssertionStatus(ClassLoader classLoader) {
}
}
@@ -21,6 +21,7 @@ public class ClassRedirect {
if (validStack()) {
return c.getDeclaredField(s);
}
System.out.println(c.getName() + "." + c.getDeclaredField(s) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
@@ -29,6 +30,7 @@ public class ClassRedirect {
if (validStack()) {
return c.getDeclaredMethod(name, params);
}
System.out.println(c.getName() + "#" + c.getDeclaredMethod(name, params) + " Blocked.");
throw RedirectClassAdapter.createSecurityException();
}
@@ -5,28 +5,40 @@ import org.parabot.core.asm.RedirectClassAdapter;
import java.io.IOException;
public class RuntimeRedirect {
public static Runtime getRuntime(){
return Runtime.getRuntime();
}
public static int availableProcessors(Runtime r){
//lol faking it, fuck ikov
return 2;
}
public static Process exec(Runtime r,String s){
if (s.contains("ping")){
System.out.println("Faked attempted command: " + s);
try {
return r.exec("ping 127.0.0.1");
} catch (IOException e) {
throw RedirectClassAdapter.createSecurityException();
}
}else{
System.out.println("Blocked attempted command: " + s);
throw RedirectClassAdapter.createSecurityException();
}
}
public static Runtime getRuntime() {
return Runtime.getRuntime();
}
public static int availableProcessors(Runtime r) {
return 2;
}
public static long totalMemory(Runtime runtime) {
return (long) 1024;
}
public static long freeMemory(Runtime runtime) {
return (long) 1024;
}
public static Process exec(Runtime r, String[] s) {
System.out.println("Blocked attempted command: " + s);
throw RedirectClassAdapter.createSecurityException();
}
public static Process exec(Runtime r, String s) {
if (s.contains("ping")) {
System.out.println("Faked attempted command: " + s);
try {
return r.exec("ping 127.0.0.1");
} catch (IOException e) {
throw RedirectClassAdapter.createSecurityException();
}
} else {
System.out.println("Blocked attempted command: " + s);
throw RedirectClassAdapter.createSecurityException();
}
}
}
@@ -27,7 +27,10 @@ public class SystemRedirect {
String value;
switch (s) {
case "user.home":
value = Directories.getHomeDir().getAbsolutePath();
value = Directories.getCachePath().getAbsolutePath();
break;
case "java.class.path":
value = ".";
break;
default:
value = System.getProperty(s);
@@ -40,14 +43,20 @@ public class SystemRedirect {
String value = null;
switch (s2) {
case "user.home":
value = Directories.getHomeDir().getAbsolutePath();
value = Directories.getCachePath().getAbsolutePath();
break;
case "java.class.path":
value = ".";
break;
}
if (value == null) {
switch (s) {
case "user.home":
value = Directories.getHomeDir().getAbsolutePath();
value = Directories.getCachePath().getAbsolutePath();
break;
case "java.class.path":
value = ".";
break;
default:
value = System.getProperty(s);
@@ -62,11 +71,12 @@ public class SystemRedirect {
}
public static String setProperty(String s1, String s2) {
System.out.printf("SetSystemProp %s = %s", s1, s2);
System.out.printf("SetSystemProp %s = %s\n", s1, s2);
return System.setProperty(s1, s2);
}
public static String getenv(String string) {
System.out.printf("getEnv %s = %s\n", string, System.getenv(string));
return System.getenv(string);
}
@@ -74,7 +84,6 @@ public class SystemRedirect {
}
public static void setErr(PrintStream printStream) {
}
@@ -5,6 +5,7 @@ import org.parabot.core.asm.ASMClassLoader;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.reflect.RefClass;
import org.parabot.core.reflect.RefField;
import org.parabot.environment.api.utils.StringUtils;
import javax.swing.*;
import javax.swing.event.TreeSelectionEvent;
@@ -91,6 +92,8 @@ public class ReflectUI extends JFrame {
result = f;
} else if (value.toLowerCase().endsWith(search.toLowerCase())) {
result = f;
} else if (value.toLowerCase().contains(search.toLowerCase())) {
result = f;
}
}
}
@@ -238,6 +241,13 @@ public class ReflectUI extends JFrame {
builder.append("<b>Type: </b>").append(refField.getASMType().getClassName()).append("<br/>");
builder.append("<b>Static: </b>").append(refField.isStatic() ? "yes" : "no").append("<br/>");
builder.append("<b>Array: </b>").append(refField.isArray() ? refField.getArrayDimensions() + " dimension(s)" : "no").append("<br/>");
if (refField.isArray() && refField.getASMType().getClassName().contains("String") && refField.getArrayDimensions() == 1) {
String[] strings = (String[]) refField.asObject();
String values = StringUtils.implode(", ", strings);
builder.append("<b>Values: </b>").append(values).append("<br/>");
}
selectionInfoPane.setText(builder.toString());
fillBasicInfoPane();
@@ -28,6 +28,19 @@ public class StringUtils {
return sb.toString();
}
public static String implode(String separator, String... data) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.length - 1; i++) {
//data.length - 1 => to not add separator at the end
if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on
sb.append(data[i]);
sb.append(separator);
}
}
sb.append(data[data.length - 1].trim());
return sb.toString();
}
public static String randomString(final int length) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 20; i++) {
@@ -109,7 +109,12 @@ public class RandomHandler {
for (Random r : this.activeRandoms) {
if (r.getRandomType().getId() == type.getId() && r.activate()) {
Logger.addMessage("Running random '" + r.getName() + "'", true);
r.execute();
try {
r.execute();
}catch (Exception e){
Logger.addMessage("Random failed: '" + r.getName() + "'", false);
e.printStackTrace();
}
return true;
}
}