Skip to content

Commit b12e03c

Browse files
author
Smukx
committed
Paload Shuffling Technique
Makes the payload unrecognizable by shuffling its bytes
1 parent c567e89 commit b12e03c

File tree

9 files changed

+357
-0
lines changed

9 files changed

+357
-0
lines changed
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Payload Shuffling Technique ..
3+
4+
Original Credit Goes to Cocomelonc
5+
=> https://cocomelonc.github.io/malware/2024/09/30/malware-trick-43.html#byte-shuffling-technique
6+
By @5mukx
7+
*/
8+
9+
10+
use std::fs::File;
11+
use std::io::{self, Read, Write};
12+
use rand::{rngs::StdRng, SeedableRng, Rng};
13+
14+
fn shuffle_file_and_save(input_file: &str, output_file: &str, seed: u64) -> io::Result<()> {
15+
shuffle_bytes(input_file, output_file, seed)
16+
}
17+
18+
fn main() -> io::Result<()> {
19+
// You can create your own .bin if you need !
20+
let input_file = "w64-exec-calc-shellcode.bin";
21+
let shuffled_file = "shuffled.bin";
22+
let deshuffled_file = "deshuffled.bin";
23+
let seed = 12345;
24+
25+
// Lets shuffle the data and save it in seperate file !
26+
shuffle_file_and_save(input_file, shuffled_file, seed)?;
27+
28+
// Read the shuffled data
29+
let mut shuffled_data = Vec::new();
30+
let mut shuffled_fp = File::open(shuffled_file)?;
31+
shuffled_fp.read_to_end(&mut shuffled_data)?;
32+
33+
// At last. Deshuffle the data.
34+
deshuffle_bytes(&shuffled_data, shuffled_data.len(), deshuffled_file, seed)?;
35+
36+
Ok(())
37+
}
38+
39+
40+
fn shuffle_bytes(input_file: &str, output_file: &str, seed: u64) -> io::Result<()> {
41+
// open input file for reading
42+
let mut in_file = File::open(input_file)?;
43+
let size = in_file.metadata()?.len() as usize;
44+
45+
// read data from the input file
46+
let mut data = vec![0u8; size];
47+
in_file.read_exact(&mut data)?;
48+
49+
// create a list of indices
50+
let mut indices: Vec<usize> = (0..size).collect();
51+
52+
// shuffle the indices
53+
let mut rng = StdRng::seed_from_u64(seed);
54+
for i in (1..size).rev() {
55+
let j = rng.gen_range(0..=i);
56+
indices.swap(i, j);
57+
}
58+
59+
// rearrange data based on shuffled indices
60+
let mut shuffled_data = vec![0u8; size];
61+
for (i, &idx) in indices.iter().enumerate(){
62+
shuffled_data[i] = data[idx];
63+
}
64+
65+
// Write the shuffled data to the output file
66+
let mut out_file = File::create(output_file)?;
67+
out_file.write_all(&shuffled_data)?;
68+
69+
Ok(())
70+
}
71+
72+
fn deshuffle_bytes(data: &[u8], size: usize, output_file: &str, seed: u64) -> io::Result<()> {
73+
// Create a list of indices
74+
let mut indices: Vec<usize> = (0..size).collect();
75+
76+
// Shuffle the indices to get the same order
77+
let mut rng = StdRng::seed_from_u64(seed);
78+
for i in (1..size).rev() {
79+
let j = rng.gen_range(0..=i);
80+
indices.swap(i, j);
81+
}
82+
83+
// rearrang the data according to shuffled indices
84+
let mut deshuffled_data = vec![0u8; size];
85+
for (i, &idx) in indices.iter().enumerate() {
86+
deshuffled_data[idx] = data[i];
87+
}
88+
89+
// write the deshuffled data to the output file
90+
let mut out_file = File::create(output_file)?;
91+
out_file.write_all(&deshuffled_data)?;
92+
93+
Ok(())
94+
}
95+
96+
97+

Encryption Methods/payload_shuffling/Cargo.lock

+140
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "payload_shuffling"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rand = "0.8.5"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
## PAYLOAD SHUFFLING TECHNIQUE
4+
5+
POC OF Payload Shuffling
6+
7+
![payload_shuffling](./image/payload_shuffling.png)
8+
9+
10+
### CREDIS
11+
12+
Original Credit Goes to [cocolemonc](https://x.com/cocomelonckz)
13+
14+
Implemented in Rust By [5mukx](https://github.com/Whitecat18)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
j`ZhcalcTYH)�eH�2H�vH�vH�H�0H�~0W<�\(�t H��T$�,�R��<WinEu�tH��4�H����
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
,H��\n�HH��0�E�HY`�tu~(v�WlcZ�TWH<�$Ra��2<ie�Hhc4HH)0���׋�THj� ��tvH�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
Payload Shuffling Technique ..
3+
4+
Original Credit Goes to Cocomelonc
5+
=> https://cocomelonc.github.io/malware/2024/09/30/malware-trick-43.html#byte-shuffling-technique
6+
By @5mukx
7+
*/
8+
9+
10+
use std::fs::File;
11+
use std::io::{self, Read, Write};
12+
use rand::{rngs::StdRng, SeedableRng, Rng};
13+
14+
fn shuffle_file_and_save(input_file: &str, output_file: &str, seed: u64) -> io::Result<()> {
15+
shuffle_bytes(input_file, output_file, seed)
16+
}
17+
18+
fn main() -> io::Result<()> {
19+
let input_file = "w64-exec-calc-shellcode.bin";
20+
let shuffled_file = "shuffled.bin";
21+
let deshuffled_file = "deshuffled.bin";
22+
let seed = 12345;
23+
24+
// Lets shuffle the data and save it in seperate file !
25+
shuffle_file_and_save(input_file, shuffled_file, seed)?;
26+
27+
println!("[+] shuffled and stored at [shuffled.bin]");
28+
// Read the shuffled data
29+
let mut shuffled_data = Vec::new();
30+
let mut shuffled_fp = File::open(shuffled_file)?;
31+
shuffled_fp.read_to_end(&mut shuffled_data)?;
32+
33+
// At last. Deshuffle the data.
34+
deshuffle_bytes(&shuffled_data, shuffled_data.len(), deshuffled_file, seed)?;
35+
println!("[+] Desuffled and stored at [deshuffled.bin]");
36+
Ok(())
37+
}
38+
39+
40+
fn shuffle_bytes(input_file: &str, output_file: &str, seed: u64) -> io::Result<()> {
41+
// open input file for reading
42+
let mut in_file = File::open(input_file)?;
43+
let size = in_file.metadata()?.len() as usize;
44+
45+
// read data from the input file
46+
let mut data = vec![0u8; size];
47+
in_file.read_exact(&mut data)?;
48+
49+
// create a list of indices
50+
let mut indices: Vec<usize> = (0..size).collect();
51+
52+
// shuffle the indices
53+
let mut rng = StdRng::seed_from_u64(seed);
54+
for i in (1..size).rev() {
55+
let j = rng.gen_range(0..=i);
56+
indices.swap(i, j);
57+
}
58+
59+
// rearrange data based on shuffled indices
60+
let mut shuffled_data = vec![0u8; size];
61+
for (i, &idx) in indices.iter().enumerate(){
62+
shuffled_data[i] = data[idx];
63+
}
64+
65+
// Write the shuffled data to the output file
66+
let mut out_file = File::create(output_file)?;
67+
out_file.write_all(&shuffled_data)?;
68+
69+
Ok(())
70+
}
71+
72+
fn deshuffle_bytes(data: &[u8], size: usize, output_file: &str, seed: u64) -> io::Result<()> {
73+
// Create a list of indices
74+
let mut indices: Vec<usize> = (0..size).collect();
75+
76+
// Shuffle the indices to get the same order
77+
let mut rng = StdRng::seed_from_u64(seed);
78+
for i in (1..size).rev() {
79+
let j = rng.gen_range(0..=i);
80+
indices.swap(i, j);
81+
}
82+
83+
// rearrang the data according to shuffled indices
84+
let mut deshuffled_data = vec![0u8; size];
85+
for (i, &idx) in indices.iter().enumerate() {
86+
deshuffled_data[idx] = data[i];
87+
}
88+
89+
// write the deshuffled data to the output file
90+
let mut out_file = File::create(output_file)?;
91+
out_file.write_all(&deshuffled_data)?;
92+
93+
Ok(())
94+
}
95+
96+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
j`ZhcalcTYH)�eH�2H�vH�vH�H�0H�~0W<�\(�t H��T$�,�R��<WinEu�tH��4�H����

0 commit comments

Comments
 (0)