How to modify and forward packets with python on the fly in the MitM attack?

this is for a CTF challenge, we have a client and server communicating with each other in the same subnet as us, we need to arp poison them and then modify the packets and forward them

i know how to use scapy to modify the packets and i already implemented the arp poisoning part of it

the problem I’m facing right now is how to connect the receiving packet which was received by the socket library and send it to a function which modifies it, then send it, i don’t know how to receive the incoming packets with scapy so i tried socket library

should i have something like this in my python code? :

s = socket.socket(socket.AF_INET , socket.SOCK_STREAM) s.bind((host,port)) s.listen(5)  while True:  conn,addr = s.accept() 

if this is how should i start the code, then now how can i modify it using scapy?!

can scapy even modify packet which was received by socket accept?

AND i cant use tools and libraries that need access to iptables command since the access is blocked in the O.S (for exampleNetfilterqueue )

how can do this? i need to basically listen to packets coming from 2 different IP addresses then then modify parts of them and then send them to their real destination

am i even approaching this right or is there a better library for this?