Skip to content

Instantly share code, notes, and snippets.

@typcn
Created March 2, 2018 01:02
Show Gist options
  • Save typcn/8c2b1f7452f8cb2ff0767c994a43e192 to your computer and use it in GitHub Desktop.
Save typcn/8c2b1f7452f8cb2ff0767c994a43e192 to your computer and use it in GitHub Desktop.
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