2011-03-04 187 views
2

我有两个文件,一个用户名列表和一个密码列表。我需要编写一个程序来检查每个用户名和密码列表。然后,我需要去一个网站,看看它是否登录。我不太清楚如何去比较和如何模拟程序登录网站输入信息。你能帮我解决这个问题吗?这是一个家庭作业问题。密码破解

+4

请问Java,C++和C标签是否意味着您可以选择实现这些功能? – 2011-03-04 01:39:40

+0

您会特别针对密码检查每个用户名吗?或者正在登录您所指的支票? – razlebe 2011-03-04 01:44:31

+0

是啊!我不完全确定要使用什么.. – Priya 2011-03-04 01:44:38

回答

6

无论选择哪种语言来实现它,基本思想都是以编程方式模拟登录。这可以通过手动登录并查看HTTP标头,然后以编程方式发送“伪造”标头,更改用户/密码字段来完成。

大多数登录将使用POST并使POST不是完全简单。如果您可以使用外部库,则可以尝试cURL。只需设置适当的标题并查看响应以检查您的尝试是否成功。如果不是,请尝试使用新组合。

在伪代码:

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 
+0

我不是很确定如何使用卷曲?我如何检查使用这个? – Priya 2011-03-04 01:52:58

+0

@Priya检查我提供的链接我的答案 – NullUserException 2011-03-04 01:54:56

+0

非常感谢,这是有帮助的:) – Priya 2011-03-04 01:55:59

3

如果你想使用Java中,你可以用的HtmlUnit尝试(参见:http://htmlunit.sourceforge.net/gettingStarted.html),或者如果你被允许Groovy中你可以用http://www.gebish.org/

这里是去从入门指南中选择与您的案例相关的示例:

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(); 
}