mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
feat: support GZIPBase64 packer
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
package com.reajason.javaweb.memshell.packer;
|
||||||
|
|
||||||
|
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||||
|
import com.reajason.javaweb.memshell.utils.CommonUtil;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ReaJason
|
||||||
|
* @since 2025/1/22
|
||||||
|
*/
|
||||||
|
public class GzipBase64 implements Packer {
|
||||||
|
@Override
|
||||||
|
@SneakyThrows
|
||||||
|
public String pack(GenerateResult generateResult) {
|
||||||
|
return Base64.encodeBase64String(CommonUtil.gzipCompress(generateResult.getInjectorBytes()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -44,6 +44,10 @@ public interface Packer {
|
|||||||
*/
|
*/
|
||||||
Base64(new Base64Packer()),
|
Base64(new Base64Packer()),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GzipBase64
|
||||||
|
*/
|
||||||
|
GzipBase64(new GzipBase64()),
|
||||||
/**
|
/**
|
||||||
* BCEL
|
* BCEL
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,10 +2,12 @@ package com.reajason.javaweb.memshell.utils;
|
|||||||
|
|
||||||
import com.reajason.javaweb.memshell.config.Server;
|
import com.reajason.javaweb.memshell.config.Server;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.zip.GZIPInputStream;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +45,19 @@ public class CommonUtil {
|
|||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] gzipDecompress(byte[] data) throws IOException {
|
||||||
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
try (GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(data))) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int length;
|
||||||
|
while ((length = gzip.read(buffer)) != -1) {
|
||||||
|
out.write(buffer, 0, length);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
public static String getRandomString(int length) {
|
public static String getRandomString(int length) {
|
||||||
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
SecureRandom random = new SecureRandom();
|
SecureRandom random = new SecureRandom();
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.reajason.javaweb.memshell.packer;
|
||||||
|
|
||||||
|
import com.reajason.javaweb.memshell.config.GenerateResult;
|
||||||
|
import com.reajason.javaweb.memshell.utils.CommonUtil;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ReaJason
|
||||||
|
* @since 2025/1/22
|
||||||
|
*/
|
||||||
|
class GzipBase64Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void compress() {
|
||||||
|
GenerateResult generateResult = new GenerateResult();
|
||||||
|
generateResult.setInjectorBytes("hello world".getBytes());
|
||||||
|
String pack = new GzipBase64().pack(generateResult);
|
||||||
|
assertEquals("hello world", new String(CommonUtil.gzipDecompress(Base64.decodeBase64(pack))));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user