Skip to content

Instantly share code, notes, and snippets.

@morkev
Created November 23, 2024 00:10
Show Gist options
  • Save morkev/9e21678804ffaff0e7eb151dad98d44b to your computer and use it in GitHub Desktop.
Save morkev/9e21678804ffaff0e7eb151dad98d44b to your computer and use it in GitHub Desktop.
Binary Exploitation Basic Shellcode
import subprocess
import sys
def main():
try:
with open('shellcode.bin', 'rb') as f:
shellcode = f.read()
except FileNotFoundError:
print("Error: 'shellcode.bin' not found. Make sure you have assembled 'shellcode.asm' using NASM.")
sys.exit(1)
challenge_path = '/challenge/binary-exploitation-basic-shellcode'
try:
proc = subprocess.Popen([challenge_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate(shellcode)
print(stdout.decode())
if stderr:
print(stderr.decode(), file=sys.stderr)
except Exception as e:
print(f"Failed to run the challenge: {e}")
sys.exit(1)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment