Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Module: docker_build #103

Merged
merged 13 commits into from
Mar 9, 2021
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ or (on Docker)
-e, --exit-after <exit-after> Exit after running for this long (format example: 2h10min)
-m, --modules <modules>... Run only these modules [possible values: bootlog, botnet,
cargo, cc, composer, cryptomining, simcity,
download, docker, memdump, mkinitcpio,
download, docker, docker_build, memdump, mkinitcpio,
kernel_compile, weblog]
-s, --speed-factor <speed-factor> Global speed factor [default: 1]

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub static ALL_MODULES: &[&str] = &[
"simcity",
"download",
"docker",
"docker_build",
"memdump",
"mkinitcpio",
"kernel_compile",
Expand Down Expand Up @@ -60,6 +61,7 @@ pub async fn run(appconfig: AppConfig) {
"cc" => modules::cc::run(&appconfig).await,
"download" => modules::download::run(&appconfig).await,
"docker" => modules::docker::run(&appconfig).await,
"docker_build" => modules::docker_build::run(&appconfig).await,
"memdump" => modules::memdump::run(&appconfig).await,
"composer" => modules::composer::run(&appconfig).await,
"kernel_compile" => modules::kernel_compile::run(&appconfig).await,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/bootlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use crate::args::AppConfig;
use crate::data::BOOTLOG_LIST;
use crate::io::{csleep, dprint};

pub fn get_signature() -> &'static str {
"bcdedit /set {current} bootlog Yes && shutdown /r"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let num_lines = rng.gen_range(50..200);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/botnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use crate::io::{csleep, cursor_up, dprint, erase_line, newline, print};
use rand::prelude::*;
use yansi::Paint;

pub fn get_signature() -> &'static str {
"./botnet.sh"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let clusters = {
Expand Down
4 changes: 4 additions & 0 deletions src/modules/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ use crate::data::PACKAGES_LIST;
use crate::generators::gen_package_version;
use crate::io::{csleep, dprint};

pub fn get_signature() -> &'static str {
"cargo run"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let num_packages = rng.gen_range(10..100);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use crate::data::{CFILES_LIST, PACKAGES_LIST};
use crate::generators::gen_random_n_from_list_into_string;
use crate::io::{csleep, newline, print};

pub fn get_signature() -> &'static str {
"gcc app.c"
}

/// Generate a `String` containing all of the `file_list`'s file's parents as -I flags
fn generate_includes(file_list: &[&str], max: u32, rng: &mut ThreadRng) -> String {
let mut include_flags = vec![];
Expand Down
4 changes: 4 additions & 0 deletions src/modules/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use crate::args::AppConfig;
use crate::data::COMPOSERS_LIST;
use crate::io::{csleep, newline, print};

pub fn get_signature() -> &'static str {
"composer install"
}

fn gen_package_version(rng: &mut ThreadRng) -> String {
let chi = ChiSquared::new(1.0).unwrap();
format!(
Expand Down
4 changes: 4 additions & 0 deletions src/modules/cryptomining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use crate::args::AppConfig;
use crate::generators::gen_hex_string;
use crate::io::{csleep, newline, print};

pub fn get_signature() -> &'static str {
"./cryptominer.sh --gpu all --provider stratum"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let num_lines = rng.gen_range(300..1000);
Expand Down
166 changes: 166 additions & 0 deletions src/modules/docker_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//! Module that pretends to build Docker images
use rand::prelude::*;
use rand::Rng;

use crate::args::AppConfig;
use crate::data::DOCKER_PACKAGES_LIST;
use crate::data::DOCKER_TAGS_LIST;
use crate::generators::gen_hex_string;
use crate::io::{csleep, dprint};

use crate::modules::bootlog;
use crate::modules::botnet;
use crate::modules::cargo;
use crate::modules::cc;
use crate::modules::composer;
use crate::modules::cryptomining;
use crate::modules::download;
use crate::modules::kernel_compile;
use crate::modules::memdump;
use crate::modules::mkinitcpio;
use crate::modules::simcity;
use crate::modules::weblog;

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();

// Output the sending of the context to Docker
let target_size: f64 = rng.gen_range(100.0..1000.0);
let mut current_size: f64 = 0.0;

while current_size <= target_size {
dprint(
format!(
"\rSending build context to Docker daemon {current_size:>4.2}MB",
current_size = current_size
),
0,
)
.await;

let remaining_size = target_size - current_size;
if remaining_size <= 5.0 {
current_size += 5.0;
} else {
current_size += rng.gen_range(5.0..30.0);
}

if appconfig.should_exit() {
return;
}

csleep(200).await;
}

// Loop trough a set number of steps
let total_steps = rng.gen_range(30..100);
let mut current_step = 1;

while current_step <= total_steps {
// Choose a random instruction
let command = select_command();

// Print the current step with the instruction to run
println!(
"\rStep {current_step}/{total_steps} : {instruction}",
current_step = current_step,
total_steps = total_steps,
instruction = ["RUN", get_module_signature(command)].join(" ")
);

if rand::random() {
println!(" ---> Using cache");
} else {
println!(
" ---> Running in {step_hash}",
step_hash = gen_hex_string(&mut rng, 12),
);

let docker_appconfig = appconfig;
match command {
"bootlog" => bootlog::run(&docker_appconfig).await,
"botnet" => botnet::run(&docker_appconfig).await,
"cargo" => cargo::run(&docker_appconfig).await,
"cryptomining" => cryptomining::run(&docker_appconfig).await,
"simcity" => simcity::run(&docker_appconfig).await,
"mkinitcpio" => mkinitcpio::run(&docker_appconfig).await,
"cc" => cc::run(&docker_appconfig).await,
"download" => download::run(&docker_appconfig).await,
"memdump" => memdump::run(&docker_appconfig).await,
"composer" => composer::run(&docker_appconfig).await,
"kernel_compile" => kernel_compile::run(&docker_appconfig).await,
"weblog" => weblog::run(&docker_appconfig).await,
_ => panic!("Unknown module!"),
}
}

println!(
" ---> {step_hash}",
step_hash = gen_hex_string(&mut rng, 12),
);

if appconfig.should_exit() {
return;
}

current_step += 1;
csleep(rng.gen_range(300..1000)).await;
}

// Print the final lines
let hash = gen_hex_string(&mut rng, 12);
let image: &&str = DOCKER_PACKAGES_LIST.choose(&mut rng).unwrap();
let image_tag: &&str = DOCKER_TAGS_LIST.choose(&mut rng).unwrap();

println!("Successfully built {hash}", hash = hash);

println!(
"Successfully tagged {image}:{tag}",
image = image,
tag = image_tag
);

if appconfig.should_exit() {
return;
}
}

fn select_command() -> &'static str {
let mut rng = thread_rng();

let available_modules = [
"bootlog",
"botnet",
"cargo",
"cc",
"composer",
"cryptomining",
"simcity",
"download",
"memdump",
"mkinitcpio",
"kernel_compile",
"weblog",
];

let rand_choice: &str = available_modules.choose(&mut rng).unwrap();
rand_choice
}

fn get_module_signature(choice: &str) -> &str {
match choice {
"bootlog" => bootlog::get_signature(),
"botnet" => botnet::get_signature(),
"cargo" => cargo::get_signature(),
"cryptomining" => cryptomining::get_signature(),
"simcity" => simcity::get_signature(),
"mkinitcpio" => mkinitcpio::get_signature(),
"cc" => cc::get_signature(),
"download" => download::get_signature(),
"memdump" => memdump::get_signature(),
"composer" => composer::get_signature(),
"kernel_compile" => kernel_compile::get_signature(),
"weblog" => weblog::get_signature(),
_ => panic!("Unknown module!"),
}
}
4 changes: 4 additions & 0 deletions src/modules/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ use humansize::{file_size_opts, FileSize};
use humantime::format_duration;
use std::time::Duration;

pub fn get_signature() -> &'static str {
"wget -i downloads.txt"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();

Expand Down
4 changes: 4 additions & 0 deletions src/modules/kernel_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use crate::args::AppConfig;
use crate::data::CFILES_LIST;
use crate::io::{csleep, newline, print};

pub fn get_signature() -> &'static str {
"sudo make install"
}

/// Generate a build step for a header file
fn gen_header(arch: &str, rng: &mut ThreadRng) -> String {
const RARE_CMDS: &[&str] = &["SYSTBL ", "SYSHDR "];
Expand Down
4 changes: 4 additions & 0 deletions src/modules/memdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use crate::args::AppConfig;
use crate::generators::gen_hex_string;
use crate::io::{csleep, is_printable_ascii, newline, print};

pub fn get_signature() -> &'static str {
"memdump -k -v"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();

Expand Down
4 changes: 4 additions & 0 deletions src/modules/mkinitcpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const REQUIRED_HOOKS: &[&str] = &[
&"filesystems",
];

pub fn get_signature() -> &'static str {
"mkinitcpio --generate /boot/initramfs-custom2.img --kernel 5.7.12-arch1-1"
}

async fn warn(msg: &str) {
print(format!(
"{}{}",
Expand Down
1 change: 1 addition & 0 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod cc;
pub mod composer;
pub mod cryptomining;
pub mod docker;
pub mod docker_build;
pub mod download;
pub mod kernel_compile;
pub mod memdump;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/simcity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use yansi::Paint;

use crate::data::SIMCITY_LIST;

pub fn get_signature() -> &'static str {
"./start-sumcity.sh"
}

pub async fn run(appconfig: &AppConfig) {
const SPINNERS: &[&str] = &["/", "-", "\\", "|"];
const SPINNER_SLEEP: u64 = 50;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/weblog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use crate::generators::gen_file_path;
use crate::io::{csleep, newline, print};
static HTTP_CODES: &[u16] = &[200, 201, 400, 401, 403, 404, 500, 502, 503];

pub fn get_signature() -> &'static str {
"tail -f /var/log/nginx/access.log"
}

pub async fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let num_lines = rng.gen_range(50..200);
Expand Down