Skip to main content

Moria

GitHub release (latest SemVer) Build Status PyPI Version Python Versions codecov

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

  1. Connor, Richard J. III, Improved Architectures for Secure Intra-process Isolation. PhD diss., University of Tennessee, 2021. https://trace.tennessee.edu/utk_graddiss/6533
  2. 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)

Source distribution for moria-c 0.3.1
File Size Uploaded
moria-c-0.3.1.tar.gz 26.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moria-c 0.3.1
File Interpreter ABI Platform
moria_c-0.3.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.9

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page