Instantly share code, notes, and snippets.

Embed
What would you like to do?
Memcached honeypot
const dgram = require('dgram');
const net = require('net');
const server = dgram.createSocket('udp4');
const fs = require('fs')
let udp_logger = fs.createWriteStream('udp_log.txt', {
flags: 'a'
});
let tcp_logger = fs.createWriteStream('tcp_log.txt', {
flags: 'a'
});
server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
udp_logger.end();
tcp_logger.end();
});
server.on('message', (msg, rinfo) => {
udp_logger.write(`${rinfo.address}:${rinfo.port}|${msg}`);
});
server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);
});
server.bind(11211);
const tcpserver = net.createServer((socket) => {
let clientName = `${socket.remoteAddress}:${socket.remotePort}`;
socket.on('data', (msg) => {
socket.write('OK\r\n');
tcp_logger.write(`${clientName}|${msg}`);
});
}).on('error', (err) => {
return;
});
tcpserver.listen(11211);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment