Moria
A library for interacting with in-memory C structures. With Moria, you can:
- Extract C struct information from compiled binaries (using DWARF debug info)
- Turn them into high-level python types
- Manipulate values including nested structs, pointers, and arrays
- Serialize into binary compatbile with the original program
- Pack objects into a binary buffer
- Automatically arrange string buffers, etc. in memory
- Automatically compute pointer values in packed objects
Why?
Data-only memory corruption exploits can involve reading and writing complex data structures in the target address space. Moria makes development of these types of exploits much easier.
Install
pip install moria-c
Examples
Moria can manipulate complicated in-memory C datastructures using high-level python objects. For example, take the following C declaration for a linked list of user data:
struct user
{
int id;
char name[MAX_USERNAME_LEN];
struct user *prev;
struct user *next;
};
Moria can automatically extract the types, sizes, and offsets of the structure from binary compiled with debug info:
with open("uesrlist.bin", "rb") as binary:
structs = DwarfParser(binary).parse()
user1 = structs.user()
user2 = structs.user()
You can set field values, including nested types and pointers that reference other objects, fields, or values:
user1.id = 1
user1.name = "alice"
user1.next = user2.ref()
user1.prev = user2.ref()
user2.id = 2
user2.name = "bob"
user2.next = user1.ref()
user2.prev = user1.ref()
Finally, you can pack your collection of objects into a byte array, automatically computing pointer values using a base address, ready to be injected into the target address space!
start_address = 0x560A61DF4000 # e.g. heap address
packed = namespace.pack_values(start_address, 0x1000, [user1, user2])
The result:
0000560a61df4000 01 00 00 00 61 6c 69 63 65 00 00 00 00 00 00 00 |....alice.......|
0000560a61df4010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0000560a61df4020 00 00 00 00 00 00 00 00 38 40 df 61 0a 56 00 00 |........8@.a.V..|
0000560a61df4030 38 40 df 61 0a 56 00 00 02 00 00 00 62 6f 62 00 |8@.a.V......bob.|
0000560a61df4040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0000560a61df4050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
0000560a61df4060 00 40 df 61 0a 56 00 00 00 40 df 61 0a 56 00 00 |.@.a.V...@.a.V..|
See Also
- Connor, Richard J. III, Improved Architectures for Secure Intra-process Isolation. PhD diss., University of Tennessee, 2021. https://trace.tennessee.edu/utk_graddiss/6533
- proc/mem attack
Metadata
Release files for moria-c 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moria-c-0.3.1.tar.gz | 26.5 kB | Without provenance | Details for moria-c-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moria_c-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for moria_c-0.3.1-py3-none-any.whl |
Total release size: 41.7 kB
Release files / moria-c-0.3.1.tar.gz
| Download URL | moria-c-0.3.1.tar.gz |
|---|---|
| Size | 26.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fa217f3c7b1540de2aee6f6b005aa52966a8cec8f2a7286dc66480caee83624
|
|
BLAKE2b-256 checksum How to use checksums |
956f79f3f8144e557a9cd35dc98916d13a786c7075d10535436bd9c36093e264
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Release files / moria_c-0.3.1-py3-none-any.whl
| Download URL | moria_c-0.3.1-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e46565ca8c0d94223f5d86240bdbff400d341c9d09d91aefa67265fd1b47a6a
|
|
BLAKE2b-256 checksum How to use checksums |
9211a99adc4fe5f7c41b294b6dc943da56700d0d71a3fd13ccc3d32ac6093206
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|
Security for moria-c 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.