tl;dr

  • memcpy in CPY goes out-of-bounds of VM stack.
  • Abuse memcpy to copy the register struct to stack and modify the values using stack operations and register operations.
  • Copy values back to the register struct, modifying the VM stack bp and sp registers.
  • This migrates the VM stack to wherever you want, gaining arbitrary read and write.
  • Leak environ pointer to get stack leak.
  • Migrate VM stack to main function’s stack to overwrite return address with ROP chain or one-gadget.