Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.logging.Logger;
- abstract public class AttackWebserver {
- protected final static Logger log = Logger.getLogger(AttackWebserver.class
- .getName());
- /**
- * Posts username/password pair to the website running at localhost port
- * 8080 and returns whether the login attempt was successful.
- *
- * @param username
- * String giving the username
- * @param password
- * String giving the password
- * @return True if successful
- * @throws IOException
- */
- protected static boolean isCorrectPassword(String username, String password)
- throws IOException {
- URL url;
- url = new URL("http://localhost:8080");
- HttpURLConnection hurl = (HttpURLConnection) url.openConnection();
- hurl.setRequestMethod("POST");
- String urlParameters = "username=" + username + "&password=" + password;
- hurl.setDoOutput(true);
- DataOutputStream wr = new DataOutputStream(hurl.getOutputStream());
- wr.writeBytes(urlParameters);
- wr.flush();
- wr.close();
- int responseCode = hurl.getResponseCode();
- BufferedReader in = new BufferedReader(new InputStreamReader(
- hurl.getInputStream()));
- String inputLine;
- StringBuffer response = new StringBuffer();
- while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
- }
- in.close();
- if (response.indexOf("Summary of") > 0) {
- log.info("Testing: " + username + " : " + password + " SUCCESS");
- return true;
- }
- log.info("Testing: " + username + " : " + password + " FAIL");
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement