Skip to content

Instantly share code, notes, and snippets.

@chids
Created May 25, 2012 09:59
Show Gist options
  • Select an option

  • Save chids/2787076 to your computer and use it in GitHub Desktop.

Select an option

Save chids/2787076 to your computer and use it in GitHub Desktop.
How to break JmDNS (trunk as of 2012-05-25 - revision 340, fixed in revision 341)
package javax.jmdns.test;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.util.Enumeration;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import javax.jmdns.impl.DNSIncoming;
import javax.jmdns.impl.constants.DNSConstants;
import org.junit.Before;
import org.junit.Test;
/*
* Tracked here:
* https://sourceforge.net/tracker/?func=detail&aid=3529498&group_id=93852&atid=605791
*
* Fixed in Subversion, revision 341
*/
public class BreakJmDNS {
// This package is one of the packages sent by nmap when run as: nmap -v -sU -sV -F 127.0.0.1
private static final byte[] nmap_scan_package = new byte[] {
0x30, (byte)0x82, 0x00, 0x2f, 0x02, 0x01, 0x00, 0x04, 0x06, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, (byte)0xa0, (byte)0x82, 0x00, 0x20, 0x02, 0x04, 0x4c, 0x33, (byte)0xa7, 0x56, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x30, (byte)0x82, 0x00, 0x10, 0x30, (byte)0x82, 0x00, 0x0c, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x05, 0x00, 0x05, 0x00
};
@Test
public void snap() throws Exception {
// The DNSIncoming constructor should probably do bounds checking on the following parts of the
// package: questions, answers, authorities, additionals
// The package above results in these values
// questions -> 513
// answers -> 4
// authorities -> 1648
// additionals -> 30050
new DNSIncoming(new DatagramPacket(nmap_scan_package, nmap_scan_package.length, InetAddress.getByName(DNSConstants.MDNS_GROUP), DNSConstants.MDNS_PORT));
}
@Before
public void enableLogging() {
ConsoleHandler handler = new ConsoleHandler();
handler.setLevel(Level.FINEST);
for (Enumeration<String> enumerator = LogManager.getLogManager().getLoggerNames(); enumerator.hasMoreElements();) {
String loggerName = enumerator.nextElement();
Logger logger = Logger.getLogger(loggerName);
logger.addHandler(handler);
logger.setLevel(Level.FINEST);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment