Tag Archives: KeyError: b‘system‘

result = e.symbols[symb] KeyError: b‘system‘ [How to Solve]

problem

Traceback (most recent call last):
  File "ot.py", line 16, in <module>
    sys_addr=d.lookup('system','libc')
  File "/usr/local/lib/python3.8/dist-packages/pwnlib/dynelf.py", line 582, in lookup
    result = e.symbols[symb]
KeyError: b'system'

This is a problem that python3 is incompatible with dynelf modules. The biggest difference between python3 and python2 (PWN) is that the bytes and STR types are not common. Therefore, for scripts that can run in python2, the problem of type conversion must be considered in python3. This is also the reason for the error reporting in dynelf

Solution:

vim /usr/local/lib/python3.8/dist-packages/pwnlib/dynelf.py

Find the dynelf.py file, find the error line, and modify the source code

result = e.symbols[symb]

by

result = e.symbols[symb.decode()]

Fixed