Advertisement
Guest User

Untitled

a guest
May 1st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1.  
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.net.HttpURLConnection;
  8. import java.net.URL;
  9. import java.util.logging.Logger;
  10.  
  11. abstract public class AttackWebserver {
  12. protected final static Logger log = Logger.getLogger(AttackWebserver.class
  13. .getName());
  14.  
  15. /**
  16. * Posts username/password pair to the website running at localhost port
  17. * 8080 and returns whether the login attempt was successful.
  18. *
  19. * @param username
  20. * String giving the username
  21. * @param password
  22. * String giving the password
  23. * @return True if successful
  24. * @throws IOException
  25. */
  26. protected static boolean isCorrectPassword(String username, String password)
  27. throws IOException {
  28. URL url;
  29. url = new URL("http://localhost:8080");
  30. HttpURLConnection hurl = (HttpURLConnection) url.openConnection();
  31. hurl.setRequestMethod("POST");
  32.  
  33. String urlParameters = "username=" + username + "&password=" + password;
  34.  
  35. hurl.setDoOutput(true);
  36. DataOutputStream wr = new DataOutputStream(hurl.getOutputStream());
  37. wr.writeBytes(urlParameters);
  38. wr.flush();
  39. wr.close();
  40.  
  41. int responseCode = hurl.getResponseCode();
  42.  
  43. BufferedReader in = new BufferedReader(new InputStreamReader(
  44. hurl.getInputStream()));
  45. String inputLine;
  46. StringBuffer response = new StringBuffer();
  47.  
  48. while ((inputLine = in.readLine()) != null) {
  49. response.append(inputLine);
  50. }
  51. in.close();
  52.  
  53. if (response.indexOf("Summary of") > 0) {
  54. log.info("Testing: " + username + " : " + password + " SUCCESS");
  55. return true;
  56. }
  57.  
  58. log.info("Testing: " + username + " : " + password + " FAIL");
  59. return false;
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement