这篇文章是讲如何做一个论坛灌水机,针对某个大型房地产论坛测试通过,那是一个基于jive3的论坛,假如论坛加入了图片认证登陆,本程序将失去作用。
本程序使用了HTTPClient包,下载地址:
http://www.innovation.ch/java/HTTPClient/
灌水机原理很简单,就是分析论坛的表单,用自己的程序模拟提交就可以了,
本文的目的在于介绍HTTPClient这个开源工具,比jdk的.net包强何止百倍,
HTTPClient的特点是多个操作可以复用同一个连接,设置连接超时(基于socket),使用代理验证。具体可以到innovation网站看看对比数据。
如下是灌水程序的简单程序,仅供参考
import java.net.*;
import java.io.*;
import java.util.*;
import HTTPClient.*;
class WebRequester{
private static InputStream istr = null;
private static OutputStream ostr = null;
private static NVPair form_data[];
private static HTTPConnection httpCon;
private static HTTPResponse rsp;
private static String host;
private static WebRequester instance;
private WebRequester(){
}
public static WebRequester getInstance(){
if(instance==null){
instance = new WebRequester();
}
return instance;
}
public static String request(HTTPConnection connection,String pathName,String method,NVPair form_data[]) {
try{
httpCon = connection;
if(method.toLowerCase().equals("get")){
if(form_data!=null)
rsp = httpCon.Get(pathName, form_data);
else
rsp = httpCon.Get(pathName);
}
else{
if(form_data!=null)
rsp = httpCon.Post(pathName, form_data);
else
rsp = httpCon.Post(pathName);
}
istr = rsp.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(istr));
String line;
StringBuffer result = new StringBuffer();
while ((line = reader.readLine()) != null) {
result.append(line + System.getProperty("line.separator"));
}
return result.toString();
} catch(Exception e){
}
return "";
}
}
public class Flood
{
private HTTPConnection connection;
public Flood(){
getConnection("sitename.com",80);
}
public void releaseConnection(){
if(connection!=null){
connection.stop();
connection = null;
}
}
public HTTPClient.HTTPConnection getConnection(String hostName,int port){
if(connection==null){
try{
connection = new HTTPClient.HTTPConnection(hostName,port);
HTTPClient.Module.setPolicyHandler(null);
connection.addDefaultModule(Class.forName("HTTPClient.Module"), 1);
connection.addModule(Class.forName("HTTPClient.RedirectionModule"),2);
}catch(Exception e){
e.printStackTrace();
}
}
return connection;
}
public void post(String subject,String body){
NVPair[] form_data = new NVPair[5];
form_data[0] = new NVPair("forumID","87");
form_data[1] = new NVPair("subject",subject);
form_data[2] = new NVPair("classifier","-1");
form_data[3] = new NVPair("body",body);
form_data[4] = new NVPair("doPost"," 发 表 ");
WebRequester.getInstance().request(connection,"post!post.jspa","post",form_data);
}
public void reply(String thread,String subject,String body){
//提交表单需要多少项,查看回复页面表单可以获得
NVPair[] form_data = new NVPair[7];
form_data[0] = new NVPair("forumID","87");
form_data[1] = new NVPair("subject",subject);
form_data[2] = new NVPair("classifier","-1");
form_data[3] = new NVPair("body",body);
form_data[4] = new NVPair("reply","true");
form_data[5] = new NVPair("threadID",thread);
form_data[6] = new NVPair("doPost"," 发 表 ");
WebRequester.getInstance().request(connection,"post!post.jspa","post",form_data);
}
public void finish(){
releaseConnection();
}
public void login(){
WebRequester wr = WebRequester.getInstance();
NVPair[] form_data = new NVPair[4];
//对应登陆需要的表单字段填写
form_data[0] = new NVPair("formUsername","user");
form_data[1] = new NVPair("formPassword","pass");
form_data[2] = new NVPair("formLogins cript","sitename.com/loginuser.jsp");
form_data[3] = new NVPair("forumLogin","Y");
//提交到指定登陆页面
wr.request(connection,"cgi-bin/gzhome/registration/LoginUser1.jsp","post",form_data);
//假如重定向,必须用该链接再次请求新的页面
wr.request(connection,"loginuser.jsp","get",null);
wr.request(connection,"index.jspa","get",null);
}
public static void main(String[] args)
{
try{
Flood f=new Flood();
f.login();
//post一个新主题,id由系统自己产生
//f.post("friends","剧本");
//得到某个主题id,进行指定数量的跟帖
for(int i=0;i<50;i++){
f.reply("67145","Re: 警告:在线朋友发言又少了,望奔走相告","洪水来了");
}
/*如下是读取某个文件每一行文字作为回帖进行灌水
BufferedReader
br = new BufferedReader(new FileReader("E:""movie""101-105""Friends -
1x04 - TOW George Stephanopoulos.CHN.srt"));
StringBuffer sb = new StringBuffer();
String t = null;
int counter=0;
while((t=br.readLine())!=null){
if(t.length()==0){
//System.out.println(sb.toString());
//System.out.println("====");
counter++;
f.reply("66617","" + counter,sb.toString());
sb.delete(0,sb.length());
}
sb.append(t + ""n");
}*/
f.finish();
}catch(Exception e){
e.printStackTrace();
}
}
}
OKOK~大家自己研究
我做好了