-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor pwnlib.encoders.encode() to be more nice to bytes objects #1923
Open
heapcrash
wants to merge
8
commits into
Gallopsled:stable
Choose a base branch
from
heapcrash:stable-encoders-python3-byteset
base: stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1efc949
Refactor pwnlib.encoders.encode() to be more nice to bytes objects
heapcrash 763ff67
Allow an empty byteset()
heapcrash fcad2d7
Move Encoder class to its own module, as it does not need to be expos…
heapcrash ca80189
Adopt byteset() and the new module for encoder_class
heapcrash f983bbc
Disable broken ARM alphanumeric encoder
heapcrash c22d82a
Merge branch 'stable' into stable-encoders-python3-byteset
Arusekk f25e2b7
Merge branch 'stable' into stable-encoders-python3-byteset
peace-maker 39f6639
Fix missed raw-bytestring and byteset usage
peace-maker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python3 | ||
from pwn import * | ||
|
||
context.randomize = False | ||
context.log_level = 'error' | ||
|
||
def go(): | ||
info('========== %s ==========', context.arch) | ||
with context.silent: | ||
sc = asm(shellcraft.sh()) | ||
avoid=b'\x00\n\t ' | ||
enc = encode(sc, avoid=avoid, force=1) | ||
|
||
assert not (byteset(avoid) & byteset(enc)) | ||
assert enc != sc | ||
|
||
with context.silent: | ||
io = ELF.from_bytes(enc).process() | ||
io.sendline(b'whoami') | ||
|
||
try: | ||
info('%r', io.recvline() == b'pwntools\n') | ||
except EOFError: | ||
info('EOFError') | ||
|
||
with context.silent: | ||
io.close() | ||
|
||
|
||
context.clear(arch='i386') | ||
go() | ||
|
||
context.clear(arch='amd64') | ||
go() | ||
|
||
context.clear(arch='arm') | ||
go() | ||
|
||
context.clear(arch='mips') | ||
go() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from __future__ import absolute_import | ||
|
||
from pwnlib.encoders.arm import alphanumeric | ||
# from pwnlib.encoders.arm import alphanumeric | ||
from pwnlib.encoders.arm import xor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
|
||
import collections | ||
|
||
from pwnlib.util.misc import byteset | ||
|
||
class Encoder(object): | ||
_encoders = collections.defaultdict(lambda: []) | ||
|
||
#: Architecture which this encoder works on | ||
arch = None | ||
|
||
#: Blacklist of bytes which are known not to be supported | ||
blacklist = byteset() | ||
|
||
def __init__(self): | ||
"""Shellcode encoder class | ||
|
||
Implements an architecture-specific shellcode encoder | ||
""" | ||
Encoder._encoders[self.arch].append(self) | ||
|
||
def __call__(self, raw_bytes, avoid, pcreg): | ||
"""avoid(raw_bytes, avoid) | ||
|
||
Arguments: | ||
raw_bytes(bytes): | ||
Bytes to encode | ||
avoid(bytes): | ||
Bytes to avoid | ||
pcreg(str): | ||
Register which contains the address of the shellcode. | ||
May be necessary for some shellcode. | ||
""" | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ASCII encoder isn't added to the encoder mapping in the Encoder class. We should keep the docs for that one, since it has to be used explicitly.
It has extra settings worth documenting and decodes the shellcode onto the stack, so a
jmp esp
is required afterwards.