新增了config.json实现
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -9,6 +9,7 @@ dependencies = [
|
|||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rust_mc_proto",
|
"rust_mc_proto",
|
||||||
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"socks",
|
"socks",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rust_mc_proto = "0.1.17"
|
rust_mc_proto = "0.1.17"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0.137"
|
serde_json = "1.0.137"
|
||||||
socks = "0.3.4"
|
socks = "0.3.4"
|
||||||
uuid = "1.12.1"
|
uuid = "1.12.1"
|
||||||
|
|||||||
14
config.json
14
config.json
@@ -1,13 +1,7 @@
|
|||||||
{
|
{
|
||||||
"server": {
|
"server_ip": "49.70.3.146",
|
||||||
"ip": "49.70.3.146",
|
"server_port": "33009",
|
||||||
"port": "33009"
|
"proxy_url": "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json",
|
||||||
},
|
|
||||||
"proxy": {
|
|
||||||
"socks5_url": "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json"
|
|
||||||
},
|
|
||||||
"settings": {
|
|
||||||
"username_prefix": "Nikke_",
|
"username_prefix": "Nikke_",
|
||||||
"player_count": 300
|
"count": 300
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ pub struct Socks5Bot {
|
|||||||
|
|
||||||
impl Socks5Bot {
|
impl Socks5Bot {
|
||||||
pub fn new(username: String, proxy_addr: String, server_addr: String) -> Result<Socks5Bot, Error> {
|
pub fn new(username: String, proxy_addr: String, server_addr: String) -> Result<Socks5Bot, Error> {
|
||||||
println!("[{}] Creating bot with proxy {}", username, proxy_addr);
|
println!("[{}] Creating bot on {} with proxy {}", username, server_addr, proxy_addr);
|
||||||
let stream = Socks5Stream::connect(proxy_addr.as_str(), server_addr.as_str());
|
let stream = Socks5Stream::connect(proxy_addr.as_str(), server_addr.as_str());
|
||||||
let should_restart = false;
|
let should_restart = false;
|
||||||
match stream {
|
match stream {
|
||||||
|
|||||||
68
src/configuration.rs
Normal file
68
src/configuration.rs
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::io::BufReader;
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Configuration {
|
||||||
|
server_ip: String,
|
||||||
|
server_port: String,
|
||||||
|
username_prefix: String,
|
||||||
|
count: i32,
|
||||||
|
proxy_url: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Configuration {
|
||||||
|
pub fn new(filename: &str) -> Self {
|
||||||
|
let file = File::open(filename);
|
||||||
|
match file {
|
||||||
|
Ok(file) => {
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
match serde_json::from_reader::<_,Configuration>(reader) { // serde可以直接解析出实现了Deserialize trait的类型 就很不错
|
||||||
|
Ok(config) => {
|
||||||
|
println!("[CONFIG] Server IP: {}", config.server_ip);
|
||||||
|
println!("[CONFIG] Server Port: {}", config.server_port);
|
||||||
|
println!("[CONFIG] Username Prefix: {}", config.username_prefix);
|
||||||
|
println!("[CONFIG] Bot Count: {}", config.count);
|
||||||
|
println!("[CONFIG] Proxy URL: {}", config.proxy_url);
|
||||||
|
config
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("[MAIN/CONF] Error parsing config file: {}", error);
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(error) => {
|
||||||
|
eprintln!("[MAIN/CONF] Unable to read config file, will use default values: {}", error);
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default() -> Self {
|
||||||
|
Configuration {
|
||||||
|
server_ip: "49.70.3.146".to_string(),
|
||||||
|
server_port: "33009".to_string(),
|
||||||
|
username_prefix: "".to_string(),
|
||||||
|
count: 300,
|
||||||
|
proxy_url: "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 下面是getter一堆
|
||||||
|
pub fn server_ip(&self) -> &str {
|
||||||
|
self.server_ip.as_str()
|
||||||
|
}
|
||||||
|
pub fn server_port(&self) -> &str {
|
||||||
|
self.server_port.as_str()
|
||||||
|
}
|
||||||
|
pub fn username_prefix(&self) -> &str {
|
||||||
|
self.username_prefix.as_str()
|
||||||
|
}
|
||||||
|
pub fn count(&self) -> i32 {
|
||||||
|
self.count
|
||||||
|
}
|
||||||
|
pub fn proxy_url(&self) -> &str {
|
||||||
|
self.proxy_url.as_str()
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main.rs
39
src/main.rs
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
mod bot_socks5;
|
mod bot_socks5;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
mod configuration;
|
||||||
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@@ -9,16 +10,19 @@ use std::sync::Arc;
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use crate::utils::generate_username;
|
use crate::utils::generate_username;
|
||||||
|
use crate::configuration::Configuration;
|
||||||
|
|
||||||
// 目标的ip地址(暂时不能解析dns)
|
// 暂且保留一下
|
||||||
// 理论上你可以把它改成任何支持1.20.1的服务器
|
// // 目标的ip地址(暂时不能解析dns)
|
||||||
const SERVER_ADDR: &str = "49.70.3.146:33009";
|
// // 理论上你可以把它改成任何支持1.20.1的服务器
|
||||||
// uu代理的api(用来实时获取代理)
|
// const SERVER_ADDR: &str = "49.70.3.146:33009";
|
||||||
const UU_URL: &str = "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json";
|
// // uu代理的api(用来实时获取代理)
|
||||||
// 用户名的开头
|
// const UU_URL: &str = "http://uu-proxy.com/api/get_proxies?id=RZ7GS5ZYTA&size=1&schemes=socks5&support_https=false&format=json";
|
||||||
const USERNAME_PREFIX: &str = "Nikke_"; // 2 3 3
|
// // 用户名的开头
|
||||||
// 假人数量
|
// // 这很不错了
|
||||||
const COUNT :i32 = 300;
|
// const USERNAME_PREFIX: &str = "Nikke_"; // 2 3 3
|
||||||
|
// // 假人数量
|
||||||
|
// const COUNT :i32 = 300;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -33,9 +37,12 @@ async fn main() {
|
|||||||
let thread_lock = Arc::new(Mutex::new(()));
|
let thread_lock = Arc::new(Mutex::new(()));
|
||||||
|
|
||||||
let mut handles = Vec::new();
|
let mut handles = Vec::new();
|
||||||
|
let configuration = Configuration::new("config.json");
|
||||||
|
let configuration_rc = Arc::new(configuration);
|
||||||
|
|
||||||
for i in 0..COUNT {
|
for i in 0..configuration_rc.count() {
|
||||||
let lock_clone = thread_lock.clone();
|
let lock_clone = thread_lock.clone();
|
||||||
|
let configuration_rc_clone = configuration_rc.clone();
|
||||||
// let handle = tokio::spawn(async move {
|
// let handle = tokio::spawn(async move {
|
||||||
// attack_thread(lock_clone).await;
|
// attack_thread(lock_clone).await;
|
||||||
// println!("[MAIN] Thread {} created", i);
|
// println!("[MAIN] Thread {} created", i);
|
||||||
@@ -48,12 +55,12 @@ async fn main() {
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.block_on(async move {
|
.block_on(async move {
|
||||||
attack_thread(lock_clone).await;
|
attack_thread(lock_clone, configuration_rc_clone).await;
|
||||||
// println!("[MAIN] Thread {} created", i);
|
// println!("[MAIN] Thread {} created", i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
handles.push(handle);
|
handles.push(handle);
|
||||||
println!("[MAIN] Thread {} created", i)
|
// println!("[MAIN] Thread {} created", i) // 这个太吵了(
|
||||||
}
|
}
|
||||||
|
|
||||||
// 等待所有任务完成(虽然大概也许可能这辈子都等不到)
|
// 等待所有任务完成(虽然大概也许可能这辈子都等不到)
|
||||||
@@ -63,18 +70,18 @@ async fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 用于殴打的线程
|
// 用于殴打的线程
|
||||||
async fn attack_thread(lock: Arc<Mutex<()>>) -> () {
|
async fn attack_thread(lock: Arc<Mutex<()>>, config: Arc<Configuration>) -> () {
|
||||||
loop {
|
loop {
|
||||||
// 请求proxy
|
// 请求proxy
|
||||||
let resp: reqwest::Response;
|
let resp: reqwest::Response;
|
||||||
{
|
{
|
||||||
let _guard = lock.lock().await;
|
let _guard = lock.lock().await;
|
||||||
resp = reqwest::get(UU_URL).await.unwrap();
|
resp = reqwest::get(config.proxy_url()).await.unwrap();
|
||||||
}
|
}
|
||||||
let proxy_list: Value = serde_json::from_str(&resp.text().await.unwrap()).unwrap();
|
let proxy_list: Value = serde_json::from_str(&resp.text().await.unwrap()).unwrap();
|
||||||
let proxy = &proxy_list["proxies"].as_array().unwrap()[0];
|
let proxy = &proxy_list["proxies"].as_array().unwrap()[0];
|
||||||
|
|
||||||
let username = generate_username();
|
let username = generate_username(&config);
|
||||||
// 这里用来标记是否需要重启
|
// 这里用来标记是否需要重启
|
||||||
let mut flag = true;
|
let mut flag = true;
|
||||||
|
|
||||||
@@ -84,7 +91,7 @@ async fn attack_thread(lock: Arc<Mutex<()>>) -> () {
|
|||||||
let bot_result = bot_socks5::Socks5Bot::new(
|
let bot_result = bot_socks5::Socks5Bot::new(
|
||||||
username.clone(),
|
username.clone(),
|
||||||
format!("{}:{}", proxy["ip"].as_str().unwrap(), proxy["port"]),
|
format!("{}:{}", proxy["ip"].as_str().unwrap(), proxy["port"]),
|
||||||
SERVER_ADDR.to_string(),
|
format!("{}:{}",config.server_ip(),config.server_port()).to_string(),
|
||||||
);
|
);
|
||||||
if let Ok(mut bot) = bot_result {
|
if let Ok(mut bot) = bot_result {
|
||||||
match bot.run() {
|
match bot.run() {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
// 一些杂七杂八的小东西可以放在这
|
// 一些杂七杂八的小东西可以放在这
|
||||||
|
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use crate::USERNAME_PREFIX;
|
use crate::configuration::Configuration;
|
||||||
|
|
||||||
// 处理json组件(有些TextComponent里面一堆extra看的我头皮发麻,所以整个这个)
|
// 处理json组件(有些TextComponent里面一堆extra看的我头皮发麻,所以整个这个)
|
||||||
pub fn parse_json_component(json: &str) -> String {
|
pub fn parse_json_component(json: &str) -> String {
|
||||||
@@ -53,6 +55,6 @@ fn generate_string() -> String {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_username() -> String {
|
pub fn generate_username(config: &Arc<Configuration>) -> String {
|
||||||
USERNAME_PREFIX.to_string() + &*generate_string().to_string()
|
config.username_prefix().to_string() + generate_string().to_string().as_str()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user