node.js - Port trap/guard ip BAN -
i have proxy socks5 server.
i trying make systems prevent me server being scaned oppening 10 random ports , whoever surfs on 1 on banned.
the problem 8 of 10 don't work, mean not opened, though see them in netstat
in listening mode.
code :
var portguards = 10; open_portguards(portguards); function open_portguards(portguards) { if(debug >= 3) console.log("cl.portguards.open [oppening "+portguards+" portguards ...]"); // create server on port for(var = 1; <= portguards; i++) { create_portguard(); } } function create_portguard() { var random_port = rand(1080,60000); var net2 = require('net'); var server; server = net2.createserver(function(socket){ socket.on("data", function(data){ // ban ip, close server, open new port trap if(isset(socket.remoteaddress) && socket.remoteaddress != "127.0.0.1" && socket.remoteaddress != server_ip) { if(debug >= 3) console.log("cl.portguard.ban banning_ip["+socket.remoteaddress +"]"); firewall_ban_by_ip(socket.remoteaddress,'portguard',function(){}); settimeout(function(){ create_portguard(); },1000); server.close(); socket.end(); } }); socket.on("error", function(error){ if(debug >= 3) console.log("cl.portguard.error ["+error.tostring()+"] "); socket.end(); }); socket.on("end", function(){ if(debug >= 3) console.log("cl.portguard.end"); }); socket.on("connect", function(){ if(debug >= 3) console.log("cl.portguard.connect"); }); socket.on("lookup", function(){ if(debug >= 3) console.log("cl.portguard.lookup"); }); socket.on("timeout", function(){ if(debug >= 3) console.log("cl.portguard.timeout"); }); socket.on("drain", function(){ if(debug >= 3) console.log("cl.portguard.drain"); }); socket.on("close", function(error){ if(debug >= 3) console.log("cl.portguard.close"); socket.end(); }); }); server.on("connection",function(){ if(debug >= 3) console.log('cl.portguard.server.connection'); }); server.on("listening",function(){ if(debug >= 3) console.log('cl.portguard.server.listening'); }); server.on("error",function(error){ if(debug >= 3) console.log('cl.portguard.server.error error_server ['+error.tostring()+']'); if(error.tostring().includes("eaddrinuse")) { settimeout(function(){ create_portguard(); },1000); server.close(); } }); server.on("close",function(){ if(debug >= 3) console.log('cl.portguard.server.close'); }); server.listen(random_port,drone_server_host,function(){ if(debug >= 3) console.log('cl.portguard.server portguard_placed ['+drone_server_host+':'+random_port+']'); }); }
output :
cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:2765] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:39453] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:30421] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:51256] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:40036] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:19320] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:16789] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:4603] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:2445] cl.portguard.server.listening cl.portguard.server portguard_placed [5.5.5.5:46736]
i surf on port 2765 , in firefox
the proxy server refusing connections
witch normal expected
cl.portguard.server.close cl.portguard.close cl.firewall.ban.ip [1.2.3.4] (insert) cl.firewall.apply apply_multiple_port_range on [1.2.3.4/32 1080:60000] cl.portguard.server.listening cl.portguard.server sockstrap_placed [5.5.5.5:25324]
i surf on port 25324 , in firefox timeout
the connection has timed out
as if server not open, netstat
won't lie, socket opened every time.
netstat -an | grep 25324 tcp 0 0 5.5.5.5:25324 0.0.0.0:* listen
what problem? ideas? @ least debug ideas.
thanks.
Comments
Post a Comment