DavidBuchanan314 / unsafe-python

A library to assist writing memory-unsafe code in "pure" python, without any imports (i.e. no ctypes etc.)
MIT License
213 stars 6 forks source link

Unable to find gadgets #2

Closed commonuserlol closed 5 months ago

commonuserlol commented 5 months ago

> python shellcode_example_nocheats.py

Traceback (most recent call last):
  File "/home/commonuserlol/unsafe-python/shellcode_example_nocheats.py", line 5, in <module>
    gadgets = unsafe.find_gadgets()
              ^^^^^^^^^^^^^^^^^^^^^
  File "/home/commonuserlol/unsafe-python/unsafe.py", line 206, in find_gadgets
    libc_base = int([l for l in open("/proc/self/maps").read().split("\n") if "libc-" in l and "r-x" in l][0].split("-")[0], 16) # XXX: cheating!
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

> python --version Python 3.11.8

the OS is linux x86_64

DavidBuchanan314 commented 5 months ago

Yup, this only works on very specific versions of python, see code comments

DavidBuchanan314 commented 5 months ago

Also, I'm not 100% sure on this, but I think there might've been compiler security features added, which try to limit the availability of common gadgets

commonuserlol commented 5 months ago

The shellcode_example.py works tho (ik that it uses mmap), btw 15 line should be shellcode = shellcodes[platform.machine()] not shellcode = shellcode[platform.machine()]