mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-21 22:50:46 +08:00
trying to fix jrmp reverse test
This commit is contained in:
@@ -49,7 +49,7 @@ import ysoserial.payloads.util.PayloadRunner;
|
||||
@SuppressWarnings ( {
|
||||
"restriction"
|
||||
} )
|
||||
@PayloadTest( harness="ysoserial.test.payloads.JRMPReverseConnectSMTest")
|
||||
@PayloadTest( harness="ysoserial.test.payloads.JRMPReverseConnectTest")
|
||||
@Authors({ Authors.MBECHLER })
|
||||
public class JRMPClient extends PayloadRunner implements ObjectPayload<Registry> {
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package ysoserial.test.payloads;
|
||||
|
||||
import org.junit.Assert;
|
||||
import sun.security.util.SecurityConstants;
|
||||
import ysoserial.payloads.URLDNS;
|
||||
import ysoserial.secmgr.SecurityManagers;
|
||||
import ysoserial.test.CustomTest;
|
||||
import ysoserial.test.util.Randomized;
|
||||
import ysoserial.test.util.RecordingNameService;
|
||||
import ysoserial.test.util.RecordingSecurityManager;
|
||||
|
||||
import java.net.SocketPermission;
|
||||
import java.security.Permission;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -16,27 +20,26 @@ public class DnsLookupTest implements CustomTest {
|
||||
|
||||
@Override
|
||||
public void run(Callable<Object> payload) throws Exception {
|
||||
final List<String> lookups = new LinkedList<String>();
|
||||
SecurityManager sm = new SecurityManager() {
|
||||
@Override
|
||||
public void checkConnect(String host, int port) {
|
||||
if (port == -1) {
|
||||
System.out.println(host);
|
||||
lookups.add(host);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm) {}
|
||||
};
|
||||
// RecordingSecurityManager sm = new RecordingSecurityManager();
|
||||
|
||||
RecordingNameService ns = new RecordingNameService();
|
||||
// Assert.assertFalse("should not have resolved domain",
|
||||
// sm.getChecks().contains(new SocketPermission(testDomain, SecurityConstants.SOCKET_RESOLVE_ACTION)));
|
||||
Assert.assertFalse("should not have resolved domain", ns.getLookups().contains(testDomain));
|
||||
try {
|
||||
SecurityManagers.wrapped(payload, sm).call();
|
||||
// SecurityManagers.wrapped(payload, sm).call();
|
||||
ns.install();
|
||||
payload.call();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ns.uninstall();
|
||||
}
|
||||
|
||||
Assert.assertTrue(lookups.contains(testDomain));
|
||||
|
||||
Assert.assertTrue("should have resolved domain", ns.getLookups().contains(testDomain));
|
||||
// Assert.assertTrue("should have resolved domain",
|
||||
// sm.getChecks().contains(new SocketPermission(testDomain, SecurityConstants.SOCKET_RESOLVE_ACTION)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +48,7 @@ public class DnsLookupTest implements CustomTest {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PayloadsTest.testPayload(URLDNS.class, new Class[0]);
|
||||
PayloadsTest.testPayload(URLDNS.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class JRMPListenerTest implements CustomTest, NeedsAddlClasses {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// ObjectInputFilters.disableDcgFilter();
|
||||
PayloadsTest.testPayload(JRMPListener.class, new Class[0]);
|
||||
PayloadsTest.testPayload(JRMPListener.class);
|
||||
}
|
||||
|
||||
public Class[] getAddlClasses() {
|
||||
|
||||
@@ -8,8 +8,12 @@ import javax.management.BadAttributeValueExpException;
|
||||
import org.junit.Assert;
|
||||
|
||||
import ysoserial.payloads.Atomikos;
|
||||
import ysoserial.payloads.Hibernate2;
|
||||
import ysoserial.payloads.JRMPClient;
|
||||
import ysoserial.payloads.URLDNS;
|
||||
import ysoserial.test.CustomTest;
|
||||
import ysoserial.exploit.JRMPListener;
|
||||
import ysoserial.test.util.ObjectInputFilters;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,16 +35,12 @@ public class JRMPReverseConnectTest implements CustomTest {
|
||||
|
||||
|
||||
public void run ( Callable<Object> payload ) throws Exception {
|
||||
JRMPListener l = new JRMPListener(port, new BadAttributeValueExpException("foo"));
|
||||
DnsLookupTest innerTest = new DnsLookupTest();
|
||||
JRMPListener l = new JRMPListener(port, new URLDNS().getObject(innerTest.getPayloadArgs()));
|
||||
Thread t = new Thread(l, "JRMP listener");
|
||||
try {
|
||||
t.start();
|
||||
try {
|
||||
payload.call();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
// ignore
|
||||
}
|
||||
innerTest.run(payload);
|
||||
Assert.assertTrue("Did not have connection", l.waitFor(1000));
|
||||
}
|
||||
finally {
|
||||
@@ -53,10 +53,13 @@ public class JRMPReverseConnectTest implements CustomTest {
|
||||
|
||||
public String getPayloadArgs () {
|
||||
return "rmi://localhost:" + port + "/ExportObject";
|
||||
// return "rmi:localhost:" + port; // old version
|
||||
// return "localhost:" + port;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
PayloadsTest.testPayload(Atomikos.class);
|
||||
// ObjectInputFilters.disableDcgFilter();
|
||||
PayloadsTest.testPayload(Hibernate2.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package ysoserial.test.util;
|
||||
|
||||
import sun.net.spi.nameservice.NameService;
|
||||
import ysoserial.payloads.util.Reflections;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordingNameService implements NameService {
|
||||
|
||||
private final List<String> lookups = new LinkedList<String>();
|
||||
|
||||
public List<String> getLookups() {
|
||||
return Collections.unmodifiableList(lookups);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress[] lookupAllHostAddr(String host) throws UnknownHostException {
|
||||
lookups.add(host);
|
||||
throw new UnknownHostException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostByAddr(byte[] addr) throws UnknownHostException {
|
||||
throw new UnknownHostException();
|
||||
}
|
||||
|
||||
public void install() throws Exception {
|
||||
getNameServices().add(this);
|
||||
}
|
||||
|
||||
public void uninstall() throws Exception {
|
||||
getNameServices().remove(this);
|
||||
}
|
||||
|
||||
private static List<NameService> getNameServices() throws Exception {
|
||||
return (List<NameService>) Reflections.getFieldValue(InetAddress.class, "nameServices");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package ysoserial.test.util;
|
||||
|
||||
import java.security.Permission;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordingSecurityManager extends SecurityManager {
|
||||
private final List<Permission> checks = new LinkedList<Permission>();
|
||||
|
||||
public List<Permission> getChecks() {
|
||||
return Collections.unmodifiableList(checks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm) {
|
||||
// System.err.println("check " + perm);
|
||||
checks.add(perm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm, Object context) {
|
||||
checkPermission(perm);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user