首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >密码破解

密码破解
EN

Stack Overflow用户
提问于 2011-03-04 09:38:00
回答 3查看 8.9K关注 0票数 2

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

EN

回答 3

Stack Overflow用户

发布于 2011-03-04 09:47:39

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

大多数登录都会使用POST,创建POST并不是很简单。如果允许使用外部库,可以尝试使用cURL。只需设置适当的标头并查看响应,即可检查您的尝试是否成功。如果没有,请使用新的组合重试。

在伪代码中:

代码语言:javascript
复制
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
票数 6
EN

Stack Overflow用户

发布于 2011-03-04 09:54:21

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

以下是入门指南中与您的案例相关的示例:

代码语言:javascript
复制
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();
}
票数 3
EN

Stack Overflow用户

发布于 2019-04-02 22:37:27

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

以下是入门指南中与您的案例相关的示例:

public void login()抛出异常{ final WebClient webClient = new WebClient();

代码语言:javascript
复制
// 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();

  • 列表项
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5188734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档