mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
fix: keyword is not allowed for classname
This commit is contained in:
@@ -6,7 +6,10 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
@@ -16,6 +19,13 @@ import java.util.zip.GZIPOutputStream;
|
||||
public class CommonUtil {
|
||||
|
||||
public static final String[] INJECTOR_CLASS_NAMES = new String[]{"SignatureUtils", "NetworkUtils", "KeyUtils", "EncryptionUtils", "SessionDataUtil", "SOAPUtils", "ReflectUtil", "HttpClientUtil", "EncryptionUtil", "XMLUtil", "JSONUtil", "FileUtils", "DateUtil", "StringUtil", "MathUtil", "HttpUtil", "CSVUtil", "ImageUtil", "ThreadUtil", "ReportUtil", "EncodingUtil", "ConfigurationUtil", "HTMLUtil", "SerializationUtil"};
|
||||
public static final Set<String> JAVA_KEYWORDS = new HashSet<>(Arrays.asList(new String[]{
|
||||
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
|
||||
"continue", "default", "do", "double", "else", "enum", "extends", "final", "finally", "float",
|
||||
"for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native",
|
||||
"new", "package", "private", "protected", "public", "return", "short", "static", "strictfp", "super",
|
||||
"switch", "synchronized", "this", "throw", "throws", "transient", "try", "void", "volatile", "while"
|
||||
}));
|
||||
private static final String[] PACKAGE_NAMES = {
|
||||
"org.springframework",
|
||||
"org.apache.commons",
|
||||
@@ -59,6 +69,14 @@ public class CommonUtil {
|
||||
}
|
||||
|
||||
public static String getRandomString(int length) {
|
||||
String randomString = getRandomStringInternal(length);
|
||||
while (JAVA_KEYWORDS.contains(randomString)) {
|
||||
randomString = getRandomStringInternal(length);
|
||||
}
|
||||
return randomString;
|
||||
}
|
||||
|
||||
private static String getRandomStringInternal(int length) {
|
||||
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
SecureRandom random = new SecureRandom();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -31,7 +31,7 @@ public class AntSwordManager {
|
||||
@SneakyThrows
|
||||
public String getInfo() {
|
||||
byte[] bytes = new ByteBuddy(ClassFileVersion.JAVA_V6).redefine(Info.class)
|
||||
.name(Utils.getRandomClassName(Info.class.getName()))
|
||||
.name(Utils.getRandomClassName())
|
||||
.visit(new TargetJreVersionVisitorWrapper(Opcodes.V1_6))
|
||||
.make().getBytes();
|
||||
String base64String = Base64.getEncoder().encodeToString(bytes);
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Utils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getRandomClassName(String sourceName) {
|
||||
public static String getRandomClassName() {
|
||||
String[] domainAs = new String[]{"com", "net", "org", "sun"};
|
||||
String domainB = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
String domainC = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
|
||||
@@ -44,7 +44,7 @@ public class BehinderManager {
|
||||
@SneakyThrows
|
||||
public boolean test() {
|
||||
byte[] bytes = new ByteBuddy(ClassFileVersion.JAVA_V6).redefine(Test.class)
|
||||
.name(Utils.getRandomClassName(Test.class.getName()))
|
||||
.name(Utils.getRandomClassName())
|
||||
.visit(new TargetJreVersionVisitorWrapper(Opcodes.V1_6))
|
||||
.make().getBytes();
|
||||
String param = "xixi";
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Utils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getRandomClassName(String sourceName) {
|
||||
public static String getRandomClassName() {
|
||||
String[] domainAs = new String[]{"com", "net", "org", "sun"};
|
||||
String domainB = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
String domainC = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
|
||||
@@ -61,11 +61,10 @@ public class GodzillaManager implements Closeable {
|
||||
@SneakyThrows
|
||||
public static byte[] generateGodzilla() {
|
||||
Random random = new Random();
|
||||
String className = CLASS_NAMES.get(random.nextInt(CLASS_NAMES.size()));
|
||||
try (DynamicType.Unloaded<?> make = new ByteBuddy()
|
||||
.redefine(Payload.class)
|
||||
.visit(TargetJreVersionVisitorWrapper.DEFAULT)
|
||||
.name(className)
|
||||
.name(Utils.getRandomClassName())
|
||||
.make()) {
|
||||
return make.getBytes();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.reajason.javaweb.godzilla;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/21
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static String getRandomAlpha(int length) {
|
||||
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < length; ++i) {
|
||||
int number = random.nextInt(52);
|
||||
sb.append(str.charAt(number));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getRandomClassName() {
|
||||
String[] domainAs = new String[]{"com", "net", "org", "sun"};
|
||||
String domainB = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
String domainC = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
String domainD = getRandomAlpha((new Random()).nextInt(5) + 3).toLowerCase();
|
||||
String className = getRandomAlpha((new Random()).nextInt(7) + 4);
|
||||
className = className.substring(0, 1).toUpperCase() + className.substring(1).toLowerCase();
|
||||
int domainAIndex = (new Random()).nextInt(4);
|
||||
String domainA = domainAs[domainAIndex];
|
||||
int randomSegments = (new Random()).nextInt(3) + 3;
|
||||
if (randomSegments == 3) {
|
||||
return domainA + "." + domainB + "." + className;
|
||||
} else if (randomSegments == 4) {
|
||||
return domainA + "." + domainB + "." + domainC + "." + className;
|
||||
} else {
|
||||
return domainA + "." + domainB + "." + domainC + "." + className;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user