-
-
Save tehmasta/06411b0095331069fb0ddf19de1ded92 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
""" | |
# NOTE, you must change the string below for data you want. | |
# This script does not take arguments in its current form. Sorry! | |
""" | |
from pwn import * | |
string = b"foobar" | |
full = "eax" | |
half = "ax" | |
little = "al" | |
pieces = [] | |
for i in range(0, len(string), 4): | |
chunk = string[i : i + 4] | |
pieces.append((hex(unpack(chunk, "all")), chunk.decode("utf-8"))) | |
counter = 0 | |
for each in pieces[::-1]: | |
piece, value = each | |
if len(piece) <= 10: | |
register = full | |
if len(piece) <= 6: | |
print(f'"xor {full}, {full};" # zero out {full}') | |
register = half | |
print(f'"mov {register}, {piece}"; # ensure nullbyte') | |
print(f"\"push {full};\" # end of string '{value}' with nullbyte") | |
counter += 1 | |
continue | |
if len(piece) <= 4: | |
print(f'"xor {full}, {full};" # zero out {full}') | |
register = little | |
print(f'"mov {register}, {piece};" # ensure nullbyte') | |
print(f"\"push {full};\" # end of string '{value}' with nullbyte") | |
counter += 1 | |
continue | |
if counter == 0: | |
print(f'"xor {full}, {full};" # zero out {full}') | |
print(f'"push {full};" # ensure nullbyte') | |
print(f"\"push {piece};\" # push '{value}' onto stack") | |
counter += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment