This commit is contained in:
Chris Frohoff
2022-05-07 15:21:16 -07:00
parent 34531b28fe
commit c6a0123f0b
3 changed files with 77 additions and 1 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ import ysoserial.payloads.util.Reflections;
* *
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
@PayloadTest(skip = "true") @PayloadTest(harness="ysoserial.test.payloads.DnsLookupTest")
@Dependencies() @Dependencies()
@Authors({ Authors.GEBL }) @Authors({ Authors.GEBL })
public class URLDNS implements ObjectPayload<Object> { public class URLDNS implements ObjectPayload<Object> {
@@ -0,0 +1,21 @@
package ysoserial.secmgr;
import java.util.concurrent.Callable;
public class SecurityManagers {
public static <T> Callable<T> wrapped(final Callable<T> callable, final SecurityManager sm) throws Exception {
final SecurityManager orig = System.getSecurityManager(); // save sm
return new Callable<T>() {
@Override
public T call() throws Exception {
System.setSecurityManager(sm);
try {
return callable.call();
} finally {
System.setSecurityManager(orig); // restore sm
}
}
};
}
}
@@ -0,0 +1,55 @@
package ysoserial.test.payloads;
import org.junit.Assert;
import ysoserial.Strings;
import ysoserial.payloads.Scala;
import ysoserial.payloads.URLDNS;
import ysoserial.secmgr.SecurityManagers;
import ysoserial.test.CustomTest;
import ysoserial.test.util.Files;
import ysoserial.test.util.OS;
import java.io.File;
import java.security.Permission;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
public class DnsLookupTest implements CustomTest {
private final String testDomain = Strings.randUUID();
@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) {}
};
try {
SecurityManagers.wrapped(payload, sm).call();
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertTrue(lookups.contains(testDomain));
}
@Override
public String getPayloadArgs() {
return "http://" + testDomain;
}
public static void main(String[] args) throws Exception {
PayloadsTest.testPayload(URLDNS.class, new Class[0]);
}
}