Commit a784cdc9 authored by CompileNix's avatar CompileNix

Refactor into class

parent add83cee
# http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = tab
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details
"maxerr": 50, // {int} Maximum error before stopping
// Enforcing
"bitwise": true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase": false, // true: Identifiers must be in camelCase
"curly": true, // true: Require {} for every new block or scope
"eqeqeq": true, // true: Require triple equals (===) for comparison
"forin": true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"freeze": true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
"immed": false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"latedef": false, // true: Require variables/functions to be defined before being used
"newcap": false, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty": true, // true: Prohibit use of empty blocks
"nonbsp": true, // true: Prohibit "non-breaking whitespace" characters.
"nonew": false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus": false, // true: Prohibit use of `++` and `--`
"quotmark": false, // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused": true, // Unused variables:
// true : all variables, last function parameter
// "vars" : all variables only
// "strict" : all variables, all function parameters
"strict": true, // true: Requires all functions run in ES5 Strict Mode
"maxparams": false, // {int} Max number of formal params allowed per function
"maxdepth": false, // {int} Max depth of nested blocks (within functions)
"maxstatements": false, // {int} Max number statements per function
"maxcomplexity": false, // {int} Max cyclomatic complexity per function
"maxlen": false, // {int} Max number of characters per line
"varstmt": false, // true: Disallow any var statements. Only `let` and `const` are allowed.
// Relaxing
"asi": false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss": false, // true: Tolerate assignments where comparisons would be expected
"debug": false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull": false, // true: Tolerate use of `== null`
"esversion": 6, // {int} Specify the ECMAScript version to which the code must adhere.
"moz": false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil": false, // true: Tolerate use of `eval` and `new Function()`
"expr": false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope": false, // true: Tolerate defining variables inside control statements
"globalstrict": false, // true: Allow global "use strict" (also enables 'strict')
"iterator": false, // true: Tolerate using the `__iterator__` property
"lastsemic": false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak": false, // true: Tolerate possibly unsafe line breakings
"laxcomma": false, // true: Tolerate comma-first style coding
"loopfunc": false, // true: Tolerate functions being defined in loops
"multistr": false, // true: Tolerate multi-line strings
"noyield": false, // true: Tolerate generator functions with no yield statement in them.
"notypeof": false, // true: Tolerate invalid typeof operator values
"proto": false, // true: Tolerate using the `__proto__` property
"scripturl": false, // true: Tolerate script-targeted URLs
"shadow": false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub": false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew": false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis": false, // true: Tolerate using this in a non-constructor function
// Environments
"browser": true, // Web Browser (window, document, etc)
"browserify": false, // Browserify (node.js code in the browser)
"couch": false, // CouchDB
"devel": true, // Development/debugging (alert, confirm, etc)
"dojo": false, // Dojo Toolkit
"jasmine": false, // Jasmine
"jquery": false, // jQuery
"mocha": true, // Mocha
"mootools": false, // MooTools
"node": true, // Node.js
"nonstandard": false, // Widely adopted globals (escape, unescape, etc)
"phantom": false, // PhantomJS
"prototypejs": false, // Prototype and Scriptaculous
"qunit": false, // QUnit
"rhino": false, // Rhino
"shelljs": false, // ShellJS
"typed": false, // Globals for typed array constructions
"worker": false, // Web Workers
"wsh": false, // Windows Scripting Host
"yui": false, // Yahoo User Interface
// Custom Globals
"globals": {} // additional predefined global variables
}
{
// Use IntelliSense to find out which attributes exist for node debugging
// Use hover for the description of the existing attributes
// For further information visit https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"type": "node2",
"request": "launch",
"program": "${workspaceRoot}\\server.js",
"cwd": "${workspaceRoot}"
},
{
"name": "Attach to Process",
"type": "node2",
"request": "attach",
"port": 9229
}
]
}
\ No newline at end of file
{
"compilerOptions": {
"target": "ES6"
},
"exclude": [
"node_modules"
]
}
"use strict";
let net = require("net");
let fs = require("fs");
let readline = require("readline");
let Encoder = require("node-html-encoder").Encoder;
let encoder = new Encoder("entity");
class FtpScanner {
/**
* @param {string[]} ipAddresses
* @param {string} outFileHtml
* @param {string} outFileJson
*/
constructor(ipAddresses, outFileHtml, outFileJson) {
this.outFileHtml = outFileHtml;
this.outFileJson = outFileJson;
this.ipAddresses = ipAddresses;
this.ipAddressesCount = ipAddresses.length;
}
/**
* @param {string} targetDomain Domain
* @param {string} urlRelativeBasePath http://example.com/$urlRelativeBasePath/
* @param {string} urlRelativeArchivePath http://example.com/.../$urlRelativeArchivePath/
* @param {string} outputFilePath output.html
*/
WriteOutputHeaderHtml(targetDomain, urlRelativeBasePath, urlRelativeArchivePath) {
let header = "<html>\n" +
"<head>\n" +
"<title>" + targetDomain + " - ftpScan</title>\n" +
"</head>\n" +
"<body>\n" +
"<h1>Scan started at: " + new Date().toUTCString() + "</h1>\n" +
"<h3>\n<a href=\"//" + targetDomain + "/" + urlRelativeBasePath + "\">" + targetDomain + "/" + urlRelativeBasePath + "</a><br>\n</h3>\n" +
"<p>\n" +
"ftpscan archive: <a href=\"//" + targetDomain + "/" + urlRelativeBasePath + "/" + urlRelativeArchivePath + "\">" + targetDomain + "/" + urlRelativeBasePath + "/" + urlRelativeArchivePath + "/</a><br>\n" +
"</p>";
this.WriteHtmlToOutputFile(header);
this.UpdateStdOut(true);
}
StartProcessingOfNextJob() {
this.UpdateStdOut();
if (this.ipAddresses.length > 0) {
(() => this.ProcessJob())();
} else {
process.stdout.write('\n');
}
}
/**
* @param {boolean} force
*/
UpdateStdOut(force) {
if (force || (this.ipAddresses.length % 10 === 0)) {
this.ResetCursor();
readline.cursorTo(process.stdout, 0);
process.stdout.write(this.ipAddresses.length.toString());
}
}
ResetCursor() {
readline.cursorTo(process.stdout, 0);
}
/**
* @param {string} content
*/
AppendHtmlToOutputFile(content) {
fs.appendFileSync(this.outFileHtml, content, {
encoding: "utf8",
flag: fs.constants.O_APPEND
});
}
/**
* @param {string} content
*/
WriteHtmlToOutputFile(content) {
fs.writeFileSync(this.outFileHtml, content, {
encoding: "utf8",
flag: fs.constants.O_WRONLY
});
}
/**
* @param {string} ipAddress
* @param {string} data
*/
AddOutputFtpServer(ipAddress, data) {
this.AppendHtmlToOutputFile("<b><a href=\"ftp://" + ipAddress + "/\" target=\"_blank\">" + ipAddress + "</a></b><pre>" + data + "</pre>\n");
}
ProcessJob() {
let serverIpAddress = this.ipAddresses.pop();
let tcpSocket = new net.Socket();
let firstLine = true;
let firstLineData = "";
let firstLineDataHtmlEncoded = "";
let gotDirectoryListing = false;
tcpSocket.setTimeout(5000, () => {
tcpSocket.end();
tcpSocket.destroy();
this.StartProcessingOfNextJob();
});
tcpSocket.connect(21, serverIpAddress, () => {
tcpSocket.write("USER anonymous\nPASS 33c3\nPASV\nLIST\nQUIT\n");
});
tcpSocket.on("error", (error) => {
switch (error.code) {
case "ECONNREFUSED":
break;
default:
console.log(error);
break;
}
tcpSocket.destroy();
this.StartProcessingOfNextJob();
});
tcpSocket.on("data", (data) => {
data = encoder.htmlEncode(String(data));
if (tcpSocket.remoteAddress !== undefined) {
if (firstLine) {
firstLine = false;
firstLineData = data;
firstLineDataHtmlEncoded = encoder.htmlEncode(String(firstLineData));
}
if (data.startsWith("227 Entering Passive Mode")) {
let regex = /\(([0-9]).*,([0-9]).*\)/;
let regexResult = (data.match(regex))[0];
regexResult = regexResult.replace("(", "");
regexResult = regexResult.replace(")", "");
regexResult = regexResult.split(",");
let a = regexResult[regexResult.length - 2] * 256;
let b = regexResult[regexResult.length - 1] * 1;
let port = a + b;
let tcpSocketPassiveMode = new net.Socket();
tcpSocketPassiveMode.setTimeout(10000, () => {
tcpSocketPassiveMode.end();
tcpSocketPassiveMode.destroy();
});
tcpSocketPassiveMode.on("error", () => {
tcpSocketPassiveMode.destroy();
});
tcpSocketPassiveMode.on("data", (dataHtmlEncoded) => {
gotDirectoryListing = true;
dataHtmlEncoded = encoder.htmlEncode(String(dataHtmlEncoded));
this.AddOutputFtpServer(tcpSocket.remoteAddress, dataHtmlEncoded);
tcpSocketPassiveMode.end();
this.StartProcessingOfNextJob();
});
tcpSocketPassiveMode.connect(port, serverIpAddress, () => {});
}
}
this.StartProcessingOfNextJob();
});
tcpSocket.on("close", () => {
if (!gotDirectoryListing && !firstLine) {
this.AddOutputFtpServer(tcpSocket.remoteAddress, firstLineDataHtmlEncoded);
}
tcpSocket.destroy();
});
}
}
module.exports = FtpScanner;
......@@ -5,8 +5,13 @@
"main": "server.js",
"author": "Compilenix <Compilenix@compilenix.org>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://git.compilenix.org/Compilenix/ftpscan.git"
},
"dependencies": {
"node-html-encoder": "*"
"node-html-encoder": "*",
"netmask": "*"
}
}
"use strict";
var net = require('net');
var fs = require('fs');
var os = require("os");
var readline = require("readline");
var Encoder = require('node-html-encoder').Encoder;
var encoder = new Encoder('entity');
// var cluster = require("cluster");
let Netmask = require("netmask").Netmask;
let FtpScanner = require("./lib/FtpScanner.js");
// var jsonData = {};
var outfile = "tmp.html";
var infile = "ips.txt";
// var outfile = "test.html";
// var infile = "ips1.txt";
var eventss = 400;
var ips;
var iplen = 0;
let outfile = "tmp.html";
let countOfParalellJobWorker = 400;
let ipAddressBlock = new Netmask("151.217.0.0/16");
let ipAddresses = [];
// if (cluster.isMaster) {
ipAddressBlock.forEach((ip) => {
ipAddresses.push(ip);
});
// ipAddresses.push("151.217.173.21");
var header = "<html>\n\
<head>\n\
<title>compilenix.org - ftpScan</title>\n\
</head>\n\
<body>\n\
<h1>Scan started at: " + new Date().toUTCString() + "</h1>\n\
<h3>\n\
<a href=\"//compilenix.org/ftpscan\">compilenix.org/ftpscan</a><br>\n\
</h3>\n\
<p>\n\
ftpscan archive: <a href=\"//compilenix.org/ftpscan/archive\">compilenix.org/ftpscan/archive/</a><br>\n\
</p>";
fs.writeFileSync(outfile, header, { encoding: "utf8", flag: "w" });
let ftpScanner = new FtpScanner(ipAddresses, outfile, undefined);
ftpScanner.WriteOutputHeaderHtml("compilenix.org", "ftpscan", "archive");
var fsres = fs.readFileSync(infile, 'utf8');
ips = fsres.split('\n');
iplen = ips.length;
function onExit() {
// cluster.on('exit', function(worker, code, signal) {
if ((iplen - (os.cpus().length * 10)) > ips.length) {
readline.cursorTo(process.stdout, 0);
process.stdout.write(ips.length.toString());
iplen = ips.length;
}
if (ips.length > 0) {
// cluster.fork({ "ConnectToHost": ips.pop() });
(function () { next(); })();
} else {
readline.cursorTo(process.stdout, 0);
}
// });
for (var i = countOfParalellJobWorker; i > 0; i--) {
if (ipAddresses.length > 0) {
ftpScanner.StartProcessingOfNextJob();
}
for (var i = eventss; i > 0; i--) {
// for (var i = (os.cpus().length * 7); i > 0; i--) {
if (ips.length > 0) {
// cluster.fork({ "ConnectToHost": ips.pop() });
onExit();
}
};
// } else {
// if (ips.length > 1) {
// Connect(process.env["ConnectToHost"]);
// }
// }
// function getnext(ip) {
// if (ips.length > 1) {
// Connect(ips.pop());
// }
// }
// Connect('151.217.100.30');
// Connect('151.217.0.1');
function next() {
// function Connect(HOST) {
var HOST = ips.pop();
// console.log('...' + HOST);
var client = new net.Socket();
let firstLine = true;
let firstLineData = "";
let gotLIST = false;
client.setTimeout(5000, function() {
// console.log('timeout');
client.end();
client.destroy();
// process.exit();
onExit();
// getnext();
});
client.connect(21, HOST, function() {
// console.log('CONNECTED TO: ' + client.remoteAddress + ':' + client.remotePort);
// client.write('\r\n');
client.write("USER anonymous\nPASS 32c3\nPASV\nLIST\nQUIT\n");
});
client.on('error', function(err) {
// console.log(err);
client.destroy();
// process.exit();
onExit();
});
client.on('data', function(data) {
data = encoder.htmlEncode(String(data));
// console.log('DATA: ' + data);
if (!(client.remoteAddress === undefined)) {
if (firstLine) {
firstLine = false;
firstLineData = data;
// console.log('<a href="ftp://' + client.remoteAddress + '/" target="_blank">' + client.remoteAddress + "</a><pre>" + data + "</pre>");
}
if (data.startsWith("227 Entering Passive Mode")) {
var regex = /\(([0-9]).*,([0-9]).*\)/
var result = (data.match(regex))[0];
result = result.replace("(", "");
result = result.replace(")", "");
result = result.split(",");
var a = result[result.length - 2] * 256;
// console.log(a);
var b = result[result.length - 1] * 1;
// console.log(b);
var port = a + b;
// console.log(port);
var client1 = new net.Socket();
client1.setTimeout(10000, function() {
// console.log('timeout');
client1.end();
client1.destroy();
// getnext();
});
client1.on('error', function(err) {
// console.log(err);
client1.destroy();
});
client1.on("data", function (data1) {
gotLIST = true;
// console.log(String(data1));
data1 = encoder.htmlEncode(String(data1));
// console.log("<b><a href=\"ftp://" + client.remoteAddress + "/\" target=\"_blank\">" + client.remoteAddress + "</a></b><pre>" + data1 + "</pre>");
fs.appendFileSync(outfile, "<b><a href=\"ftp://" + client.remoteAddress + "/\" target=\"_blank\">" + client.remoteAddress + "</a></b><pre>" + data1 + "</pre>\n", { encoding: "utf8" });
client1.end();
onExit();
// process.exit();
});
client1.connect(port, HOST, function (err) {});
}
// if (jsonData === undefined) {
// jsonData[client.remoteAddress] = data;
// }
// jsonData[client.remoteAddress] += data;
}
// client.end();
onExit();
});
client.on('close', function() {
if (!gotLIST && !firstLine) {
fs.appendFileSync(outfile, "<b><a href=\"ftp://" + client.remoteAddress + "/\" target=\"_blank\">" + client.remoteAddress + "</a></b><pre>" + firstLineData + "</pre>\n", { encoding: "utf8" });
}
client.destroy();
// process.exit();
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment