mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-03-18 15:14:10 +01:00
wait for the context object
This commit is contained in:
parent
5fce838afc
commit
a66ec09285
@ -42,21 +42,23 @@ import com.metasploit.meterpreter.stdapi.stdapi_sys_process_execute_V1_3;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class AndroidMeterpreter extends Meterpreter {
|
public class AndroidMeterpreter extends Meterpreter {
|
||||||
|
|
||||||
|
private static final Object contextWaiter = new Object();
|
||||||
|
|
||||||
private static String writeableDir;
|
private static String writeableDir;
|
||||||
private static Context context;
|
private static Context context;
|
||||||
|
|
||||||
private static Thread executionThread;
|
|
||||||
|
|
||||||
private void findContext() throws Exception {
|
private void findContext() throws Exception {
|
||||||
final Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
|
final Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||||
final Method currentApplication = activityThreadClass.getMethod("currentApplication");
|
final Method currentApplication = activityThreadClass.getMethod("currentApplication");
|
||||||
context = (Context) currentApplication.invoke(null, (Object[]) null);
|
context = (Context) currentApplication.invoke(null, (Object[]) null);
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
Handler handler = new Handler(Looper.getMainLooper());
|
// Post to the UI/Main thread and try and retrieve the Context
|
||||||
|
final Handler handler = new Handler(Looper.getMainLooper());
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -65,11 +67,14 @@ public class AndroidMeterpreter extends Meterpreter {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
executionThread.start();
|
synchronized (contextWaiter) {
|
||||||
|
contextWaiter.notify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
synchronized (contextWaiter) {
|
||||||
startExecuting();
|
contextWaiter.wait();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,24 +85,13 @@ public class AndroidMeterpreter extends Meterpreter {
|
|||||||
public AndroidMeterpreter(DataInputStream in, OutputStream rawOut, String[] parameters, boolean redirectErrors) throws Exception {
|
public AndroidMeterpreter(DataInputStream in, OutputStream rawOut, String[] parameters, boolean redirectErrors) throws Exception {
|
||||||
super(in, rawOut, true, redirectErrors, false);
|
super(in, rawOut, true, redirectErrors, false);
|
||||||
writeableDir = parameters[0];
|
writeableDir = parameters[0];
|
||||||
|
|
||||||
executionThread = new Thread() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
startExecuting();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
findContext();
|
findContext();
|
||||||
executionThread.join();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
startExecuting();
|
// No context (running as root?)
|
||||||
}
|
}
|
||||||
|
startExecuting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user