Priya
Priya

Reputation: 69

Password hacking

I have two files, a list of usernames and a list of passwords. I need to write a program to check each user name with the list of passwords. Then I need to go to a website and see if it logs in. I am not very sure how to go about the comparing and how to simulate the program to log in the website enter the information. Could you please help me out with this? It's a homework problem.

Upvotes: 2

Views: 13154

Answers (3)

AMAN
AMAN

Reputation: 1

If you would like to use java you can try with HtmlUnit (see: http://htmlunit.sourceforge.net/gettingStarted.html) or if you are allowed Groovy you can go with http://www.gebish.org/

Here is the example from getting started guide that is relevant to your case:

public void login() throws Exception { final WebClient webClient = new WebClient();

// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");

// Get the form that we are dealing with and within that form, 
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");

final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");

// Change the value of the text field
textField.setValueAttribute("username");
// Do similar for password and that's all

// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
  • List item

Upvotes: 0

draganstankovic
draganstankovic

Reputation: 5426

If you would like to use java you can try with HtmlUnit (see: http://htmlunit.sourceforge.net/gettingStarted.html) or if you are allowed Groovy you can go with http://www.gebish.org/

Here is the example from getting started guide that is relevant to your case:

public void login() throws Exception {
    final WebClient webClient = new WebClient();

    // Get the first page
    final HtmlPage page1 = webClient.getPage("http://some_url");

    // Get the form that we are dealing with and within that form, 
    // find the submit button and the field that we want to change.
    final HtmlForm form = page1.getFormByName("myform");

    final HtmlSubmitInput button = form.getInputByName("submitbutton");
    final HtmlTextInput textField = form.getInputByName("userid");

    // Change the value of the text field
    textField.setValueAttribute("username");
    // Do similar for password and that's all

    // Now submit the form by clicking the button and get back the second page.
    final HtmlPage page2 = button.click();

    webClient.closeAllWindows();
}

Upvotes: 3

NullUserException
NullUserException

Reputation: 85468

Regardless of the language you choose to implement this in, the basic idea is to simulate log-ins programatically. This can be done by logging in manually and looking at the HTTP headers, then sending "forged" headers programatically, changing the user/password fields.

Most log-ins will use POST and making a POST is not entirely straightforward. If you are allowed to use external libraries, you can try cURL. Simply set the appropriate headers and look at the response to check if your attempt was successful or not. If not, try again with a new combination.

In pseudo code:

bool simulate_login(user, password) :
    request = new request(url)
    request.set_method('POST')
    request.set_header('name', user)
    request.set_header('pass', password)

    response = request.fetch_reponse()
    return response.contains("Login successful")

success = []

foreach user:
    foreach password:
        if (simulate_login(user, password)):
            success.append((user, password))
            break

Upvotes: 6

Related Questions