-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.rs
More file actions
36 lines (27 loc) · 1.25 KB
/
script.rs
File metadata and controls
36 lines (27 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::{ffi:CString};
extern crate winapi;
use winapi::{um::{winreq::{ReqOpenKeyExA,HKEY_CURRENT_USER,RegGetValueA,RRF_RT_REQ_SZ},winnt::KEY_READ},shared::{minwindef::{HKEY,DWORD},ntdef::{LPCSTR}}};
use winapi::shared::ntdef::NULL;
pub fn grab_username() -> Result<String,Box<dyn std::error:Error>>{
let mut hk:HKEY = 0 as HKEY;
let mut ret: Vec<u8> = Vec::new();
unsafe{
let venv = CString::new("Volatile Enviroment").unwrap();
let username = CString::new("USERNAME").unwrap();
let usernameptr : LPCSTR = username.as_ptr();
let venvptr : LPCSTR = username.as_ptr();
let openkeyres = RegOpenKeyExA(HKEY_CURRENT_USER,venvptr,0,KEY_READ,&mut hk as *mut HKEY);
let mut buffsize : u32 = 200;
ret.resize(buffsize,as usize,0u8);
println!("Result of open:",{openkeyres});
println!("HK:{}",hk as DWORD);
let openvalueenum = RegGetValueA(hk,NULL as *const i8,usernameptr,RRF_RT_REQ_SZ,NULL as *mut u32,
ret.as_ptr() as *const _ as *mut _, &mut buffsize);
println!("[-] Result of enumvalue:",{openvalueenum});
let ret = &ret[..buffsize as usize];
Ok(String::from(std::str::from_utf8(&ret).unwrap();.trim();))
}
}
pub fn main(){
grab_username();
}