Skip to content

Bug relating to autosort in PayloadGenerator #10

Open

Description

@dok852

There's a mistake in the autosorting logic inside PayloadGenerator, as a consequence payload generation will often fail, raising a ValueError: Unknown error. Missing bytes on line 166 or an IndexError: list index out of range on line 180 of core.py.

A proof of concept crash:

from libformatstr import *

f = FormatStr()
f[0xdddddd05] = 0xcccccccc
payload = f.payload(6)

This is as a result of the if statement on line 145 of core.py being the wrong way round. At the moment the default value of autosort is True, and the if statement is:

if autosort:
    self.addrs = list(mem.keys())  # addresses of each byte to set
else:
    self.addrs = list(sorted(mem.keys()))

Which means the keys aren't sorted by default, causing various problems.
To rectify this the lines can simply be switched around like so:

if autosort:
    self.addrs = list(sorted(mem.keys()))  # addresses of each byte to set
else:
    self.addrs = list(mem.keys())

This only appears to be a problem in this git repository. The versions in pip don't have the autosort property so keys are always sorted and this problem doesn't exist.

Activity

  1. rip1s commented on Feb 9, 2018

    @rip1s
    Contributor

    Well, maybe there is an error. But I cannot reproduce your crash. I'm late because I don't get the notification...:( Sorry.

  2. dok852 commented on Feb 9, 2018

    @dok852
    Author

    Don't worry about it! Make sure you're testing the version in this repository, not the version in PyPI (because that appears to be a different version, without the autosort property).
    I've just cloned this repository again and reproduced the error. See the following screenshot.

    poc

  3. rip1s commented on Feb 12, 2018

    @rip1s
    Contributor

    Well, actually this feature was committed by me....I wrote it because it is useful in some CTF challenges.
    In my machine your code work just fine, but I use my submitted version.
    0

    Later I will check the version in this repo.

  4. dok852 commented on Aug 16, 2018

    @dok852
    Author

    Did you test the code in this repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions