Gallopsled / pwntools

CTF framework and exploit development library
http://pwntools.com
Other
11.74k stars 1.67k forks source link

Fix pwn constgrep when it matches a non-constant type (Fixes #2344) #2345

Closed disconnect3d closed 5 months ago

disconnect3d commented 5 months ago

This commit fixes https://github.com/Gallopsled/pwntools/issues/2344 - the following issue:

root@pwndbg:~# pwn constgrep a
Traceback (most recent call last):
  File "/usr/local/bin/pwn", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/main.py", line 58, in main
    commands[args.command](args)
  File "/usr/local/lib/python3.10/dist-packages/pwnlib/commandline/constgrep.py", line 110, in main
    for _, k in sorted(out):
TypeError: '<' not supported between instances of 'Constant' and 'type'

Note that it was caused because of the following type object being matched and fetched from the module object:

ipdb> out[25:27]
[(Constant('CS', 0xd), 'CS'), (<class 'pwnlib.constants.constant.Constant'>, 'Constant')]
ipdb> sorted(out[24:27])
*** TypeError: '<' not supported between instances of 'type' and 'Constant'
disconnect3d commented 5 months ago

Note pwn constgrep C would also fail for the same reason. I added a test to CI for this.