6
0
mirror of https://github.com/EddieIvan01/memexec synced 2024-06-27 09:20:10 +00:00
memexec/README.md

88 lines
2.2 KiB
Markdown
Raw Normal View History

2020-11-10 07:46:52 +00:00
# memexec
[![](https://img.shields.io/crates/v/memexec)](https://crates.io/crates/memexec) [![](https://img.shields.io/crates/d/memexec?label=downloads%40crates.io&style=social)](https://crates.io/crates/memexec)
2020-11-13 13:05:55 +00:00
A library for loading and executing PE (Portable Executable) without ever touching the disk
2020-11-10 07:46:52 +00:00
# Features
2020-11-13 13:05:55 +00:00
+ Applicable to EXE and DLL (except .NET assembly)
+ Cross-architecture, applicable to x86 and x86-64
2020-11-10 07:46:52 +00:00
+ Zero-dependency
2020-11-13 13:05:55 +00:00
+ Contains a simple, zero-copy PE parser submodule
2020-11-10 07:46:52 +00:00
# Install
2020-11-10 09:14:59 +00:00
```toml
# Cargo.toml
[dependencies]
memexec = "0.1"
2020-11-10 07:46:52 +00:00
```
# Usage
## Load and execute
**⚠The architecture of target program must be same as current process, otherwise an error will occur**
```rust
use memexec;
use std::fs::File;
use std::io::Read;
/***********************************************************/
/* EXE */
/***********************************************************/
let mut buf = Vec::new();
File::open("./mimikatz.exe")
.unwrap()
.read_to_end(&mut buf)
.unwrap();
unsafe {
// If you need to pass command line parameters,
// try to modify PEB's command line buffer
memexec::memexec_exe(&buf).unwrap();
}
/***********************************************************/
/* DLL */
/***********************************************************/
let mut buf = Vec::new();
File::open("./test.dll")
.unwrap()
.read_to_end(&mut buf)
.unwrap();
use memexec::peloader::def::DLL_PROCESS_ATTACH;
unsafe {
// DLL's entry point is DllMain
memexec_dll(&buf, 0 as _, DLL_PROCESS_ATTACH, 0 as _).unwrap();
}
```
## Parse PE
**PE parser could parse programs which have different architectures from current process**
```rust
use memexec::peparser::PE;
// Zero copy
// Make sure that the lifetime of `buf` is longer than `pe`
let pe = PE::new(&buf);
println!("{:?}", pe);
```
2020-11-13 13:05:55 +00:00
# TODO
- [ ] Replace `LoadLibrary` with calling `load_pe_into_mem` recursively
- [ ] Replace `GetProcAddress` with self-implemented [`LdrpSnapThunk`](https://doxygen.reactos.org/dd/d83/ntdllp_8h.html#ae2196bc7f46cc2a92d36b7c4881ee633), so as to support resolving proc address by `IMAGE_IMPORT_BY_NAME.Hint`
2020-11-10 07:46:52 +00:00
# License
The GPLv3 license