Created
August 4, 2011 20:26
-
-
Save zopf/1126162 to your computer and use it in GitHub Desktop.
Java for bit-squatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.io.UnsupportedEncodingException; | |
| import java.net.InetAddress; | |
| import java.net.UnknownHostException; | |
| import java.util.regex.Pattern; | |
| public class DomainTest { | |
| private static String domainRegex = "^([a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+"; | |
| public static void testOriginalDomain(String domain, String extension) throws UnsupportedEncodingException { | |
| String fullDomain = domain+"."+extension; | |
| byte[] bytes = null;; | |
| bytes = domain.getBytes("US-ASCII"); | |
| for(int i=0; i<bytes.length; i++){ | |
| for(int j=0; j<8; j++){ | |
| byte[] testBytes = bytes.clone(); | |
| byte flipper = (byte) (1 << j) ; | |
| //System.out.println("Flipper: "+flipper); | |
| testBytes[i] = (byte) ( flipper ^ testBytes[i] ); | |
| String testDomain = new String(testBytes, "US-ASCII") + "." + extension; | |
| if(!Pattern.matches(domainRegex+extension, testDomain)) | |
| continue; | |
| if(testDomain.toLowerCase().equals(fullDomain.toLowerCase())) | |
| continue; | |
| if(!domainIsRegistered(testDomain)) | |
| System.out.println("Domain ["+testDomain+"] is NOT registered."); | |
| } | |
| } | |
| } | |
| public static boolean domainIsRegistered(String domain) { | |
| InetAddress address = null; | |
| try { | |
| address = InetAddress.getByName(domain); | |
| } catch (UnknownHostException e) { | |
| return false; | |
| } | |
| // open dns domain miss | |
| if(address.getHostAddress().equals("67.215.65.132")) | |
| return false; | |
| //System.out.println("["+domain+"] => ["+address+"]"); | |
| return true; | |
| } | |
| /** | |
| * @param args | |
| */ | |
| public static void main(String[] args) { | |
| // TODO Auto-generated method stub | |
| try { | |
| testOriginalDomain("microsoft", "com"); | |
| } catch (UnsupportedEncodingException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment