Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'socket'
  3. require 'pcaprub'
  4. require 'packetfu'
  5.  
  6. IDENTIFY_TTL = 105
  7. interface = 'eth0'
  8. DUPS = 1 # number of duplicated packet(s)
  9.  
  10. SIOCGIFINDEX = 0x8933
  11.  
  12. rsock = Socket.new(Socket::AF_PACKET, Socket::SOCK_RAW, Socket::IPPROTO_RAW)
  13. ifreq = [interface.dup].pack('a32')
  14. rsock.ioctl(SIOCGIFINDEX, ifreq)
  15. rsock.bind([Socket::AF_PACKET].pack('s') + [Socket::IPPROTO_RAW].pack('n') + ifreq[16..20]+ ("\x00" * 12)) #let's blame ruby
  16. localaddrs = Socket.ip_address_list.select{|intf| intf.ipv4? or intf.ipv4_private? and !intf.ipv4_loopback? and !intf.ipv4_multicast? }
  17. capture = PCAPRUB::Pcap.open_live(interface, 65535, true, 0)
  18. filter = localaddrs.map{|addr| "src host #{addr.ip_address}" }.join(' or ') + ' and tcp'
  19. capture.setfilter(filter)
  20. begin
  21. capture.each do |pkt|
  22. pktf = PacketFu::IPPacket.parse pkt
  23. if pktf.ip_ttl != IDENTIFY_TTL
  24. pktf.ip_ttl = IDENTIFY_TTL
  25. begin
  26. DUPS.times { rsock.sendmsg_nonblock pktf.to_s }
  27. rescue => e
  28. p e
  29. end
  30. end
  31. end
  32. ensure
  33. capture.close
  34. rsock.close
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement