1
mirror of https://github.com/rapid7/metasploit-payloads synced 2025-03-24 18:16:24 +01:00

refine string handlings

This commit is contained in:
XenoAmess 2021-02-11 23:09:41 +08:00
parent badaaa4df2
commit 384b5fb795
4 changed files with 11 additions and 12 deletions
java
javapayload/src/test/java/javapayload/stage
meterpreter/meterpreter/src/main/java/com/metasploit/meterpreter/core

@ -29,7 +29,7 @@ public class MeterpreterTest extends TestCase {
Assert.assertEquals(4096, uc.getContentLength()); Assert.assertEquals(4096, uc.getContentLength());
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamForwarder.forward(uc.getInputStream(), out); StreamForwarder.forward(uc.getInputStream(), out);
Assert.assertEquals(new String(randomData, "ISO-8859-1"), new String(out.toByteArray(), "ISO-8859-1")); Assert.assertEquals(new String(randomData, "ISO-8859-1"), out.toString("ISO-8859-1"));
} }
public void testMeterpreterStage() throws Exception { public void testMeterpreterStage() throws Exception {
@ -37,7 +37,7 @@ public class MeterpreterTest extends TestCase {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos); DataOutputStream dos = new DataOutputStream(baos);
StreamForwarder.forward(MeterpDummy.class.getResourceAsStream(MeterpDummy.class.getSimpleName() + ".class"), baos); StreamForwarder.forward(MeterpDummy.class.getResourceAsStream(MeterpDummy.class.getSimpleName() + ".class"), baos);
String meterpDummy = new String(baos.toByteArray(), "ISO-8859-1").replace("MeterpDummy", "Meterpreter"); String meterpDummy = baos.toString("ISO-8859-1").replace("MeterpDummy", "Meterpreter");
baos.reset(); baos.reset();
JarOutputStream jos = new JarOutputStream(baos); JarOutputStream jos = new JarOutputStream(baos);
jos.putNextEntry(new ZipEntry("com/metasploit/meterpreter/Meterpreter.class")); jos.putNextEntry(new ZipEntry("com/metasploit/meterpreter/Meterpreter.class"));

@ -20,7 +20,7 @@ public class ShellTest extends TestCase {
Thread.sleep(100); Thread.sleep(100);
timeout -= 100; timeout -= 100;
} }
String shellOutput = new String(out.toByteArray(), "ISO-8859-1"); String shellOutput = out.toString("ISO-8859-1");
// Assert.assertTrue("MagicToken missing in shell output: " + shellOutput, shellOutput.contains("MagicToken")); // Assert.assertTrue("MagicToken missing in shell output: " + shellOutput, shellOutput.contains("MagicToken"));
// Assert.assertEquals(-1, in.read()); // Assert.assertEquals(-1, in.read());
} }

@ -17,11 +17,10 @@ public class core_machine_id implements Command {
private static String machine_id; private static String machine_id;
private String getSerial() throws IOException { private String getSerial() throws IOException {
StringBuffer stringBuffer = new StringBuffer(); String stringBuffer = Utils.runCommand("getprop ro.serialno").trim() +
stringBuffer.append(Utils.runCommand("getprop ro.serialno").trim()); Utils.runCommand("getprop ro.product.brand").trim() +
stringBuffer.append(Utils.runCommand("getprop ro.product.brand").trim()); Utils.runCommand("getprop ro.product.model").trim();
stringBuffer.append(Utils.runCommand("getprop ro.product.model").trim()); return stringBuffer;
return stringBuffer.toString();
} }
private String getHDLabel() { private String getHDLabel() {

@ -21,10 +21,10 @@ public class core_transport_add implements Command {
HttpTransport h = new HttpTransport(meterpreter, transportUrl); HttpTransport h = new HttpTransport(meterpreter, transportUrl);
// do the HTTP specific stuff here, since we know what we are // do the HTTP specific stuff here, since we know what we are
h.setUserAgent(request.getStringValue(TLVType.TLV_TYPE_TRANS_UA, new String())); h.setUserAgent(request.getStringValue(TLVType.TLV_TYPE_TRANS_UA, ""));
h.setProxy(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_HOST, new String())); h.setProxy(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_HOST, ""));
h.setProxyUser(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_USER, new String())); h.setProxyUser(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_USER, ""));
h.setProxyPass(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_PASS, new String())); h.setProxyPass(request.getStringValue(TLVType.TLV_TYPE_TRANS_PROXY_PASS, ""));
h.setCertHash(request.getRawValue(TLVType.TLV_TYPE_TRANS_CERT_HASH, null)); h.setCertHash(request.getRawValue(TLVType.TLV_TYPE_TRANS_CERT_HASH, null));
t = h; t = h;