mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-21 22:50:46 +08:00
dns test
This commit is contained in:
@@ -41,7 +41,7 @@ import ysoserial.payloads.util.Reflections;
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@PayloadTest(skip = "true")
|
||||
@PayloadTest(harness="ysoserial.test.payloads.DnsLookupTest")
|
||||
@Dependencies()
|
||||
@Authors({ Authors.GEBL })
|
||||
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]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user