Add support for oidentd spoofing

This commit is contained in:
Maxime Poulin 2016-04-26 16:41:08 -04:00
parent 9aafffd273
commit fabb758985
5 changed files with 106 additions and 2 deletions

View File

@ -309,5 +309,15 @@ module.exports = {
// @default 113 // @default 113
// //
port: 113 port: 113
} },
//
// Enable oidentd support using the specified file
//
// Example: oidentd: "~/.oidentd.conf",
//
// @type string
// @default null
//
oidentd: null,
}; };

View File

@ -3,11 +3,18 @@ var fs = require("fs");
var Client = require("./client"); var Client = require("./client");
var mkdirp = require("mkdirp"); var mkdirp = require("mkdirp");
var Helper = require("./helper"); var Helper = require("./helper");
var oidentd = require("./oidentd");
module.exports = ClientManager; module.exports = ClientManager;
function ClientManager() { function ClientManager() {
var config = Helper.getConfig();
this.clients = []; this.clients = [];
if (typeof config.oidentd === "string") {
this.identHandler = new oidentd(config.oidentd);
}
} }
ClientManager.prototype.findClient = function(name) { ClientManager.prototype.findClient = function(name) {

73
src/oidentd.js Normal file
View File

@ -0,0 +1,73 @@
var fs = require("fs");
var Helper = require("./helper");
function oidentdFile(file) {
this.file = Helper.expandHome(file);
this.connectionId = 0;
this.connections = {};
this.refresh();
}
oidentdFile.prototype = {
hookSocket: function(socket, user) {
var that = this;
var id = null;
socket.on("connect", function() {
id = that.addSocket(socket, user);
that.refresh();
});
socket.on("close", function() {
that.removeConnection(id);
that.refresh();
});
},
addSocket: function(socket, user) {
var id = this.connectionId++;
this.connections[id] = {socket: socket, user: user};
return id;
},
removeSocket: function(socket) {
for (var id in this.connections) {
if (this.connections[id] === socket) {
delete this.connections[id];
break;
}
}
},
removeConnection: function(id) {
delete this.connections[id];
},
getSockets: function() {
return this.connections;
},
refresh: function() {
var file = "# Warning: file generated by The Lounge: changes will be overwritten!\n";
function makeRule(connection) {
return "to " + connection.socket.remoteAddress
+ " lport " + connection.socket.localPort
+ " from " + connection.socket.localAddress
+ " fport " + connection.socket.remotePort
+ " { reply \"" + connection.user + "\" }\n";
}
for (var id in this.connections) {
file += makeRule(this.connections[id]);
}
fs.writeFile(this.file, file, {flag: "w+"}, function(err) {
if (err) {
log.error("Failed to update oidentd file!", err);
}
});
},
};
module.exports = oidentdFile;

View File

@ -4,6 +4,7 @@ var Msg = require("../../models/msg");
module.exports = function(irc, network) { module.exports = function(irc, network) {
var client = this; var client = this;
var identHandler = this.manager.identHandler;
network.channels[0].pushMessage(client, new Msg({ network.channels[0].pushMessage(client, new Msg({
text: "Network created, connecting to " + network.host + ":" + network.port + "..." text: "Network created, connecting to " + network.host + ":" + network.port + "..."
@ -27,6 +28,18 @@ module.exports = function(irc, network) {
}); });
} }
if (identHandler) {
irc.on("socket connected", function() {
identHandler.addSocket(irc.connection.socket, client.name || network.username);
identHandler.refresh();
});
irc.on("socket close", function() {
identHandler.removeSocket(irc.connection.socket);
identHandler.refresh();
});
}
irc.on("socket error", function(err) { irc.on("socket error", function(err) {
log.debug("IRC socket error", err); log.debug("IRC socket error", err);
network.channels[0].pushMessage(client, new Msg({ network.channels[0].pushMessage(client, new Msg({

View File

@ -10,9 +10,10 @@ var dns = require("dns");
var Helper = require("./helper"); var Helper = require("./helper");
var config = {}; var config = {};
var manager = new ClientManager(); var manager = null;
module.exports = function(options) { module.exports = function(options) {
manager = new ClientManager();
config = Helper.getConfig(); config = Helper.getConfig();
config = _.extend(config, options); config = _.extend(config, options);