Guest User

Untitled

a guest
Mar 12th, 2018
107
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.  
  3. $: << '/ops/lib/ruby'
  4.  
  5. require 'pcaplet'
  6. require 'rubygems'
  7. require 'mysql'
  8.  
  9. MYSQL_USER = 'ffs_readonly'
  10. MYSQL_PASS = 'dar~quil6'
  11. MYSQL_HOST = '10.21.222.15'
  12. MYSQL_DB = 'ffs_production'
  13.  
  14. MYSQL_COM_QUERY = 0x03
  15.  
  16. db = Mysql.connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB)
  17.  
  18. mysqlsniff = Pcaplet.new('-s 65535 -i eth0')
  19. mysqlsniff.add_filter Pcap::Filter.new('tcp port 3306', mysqlsniff.capture)
  20.  
  21. query = ''
  22. query_length = 0
  23.  
  24. mysqlsniff.each_packet do |pkt|
  25. next unless pkt.tcp_data
  26. if query then
  27. if query.length == query_length and query[0,6] == 'SELECT' then
  28. $stderr.puts "#{query}"
  29. start = Time.now
  30. res = db.query(query)
  31. finish = Time.now
  32. $stderr.printf "#{res.num_rows} rows in %.2fs\n\n", finish - start
  33.  
  34. query = nil
  35. query_length = 0
  36. else
  37. query << pkt.tcp_data
  38. end
  39. end
  40.  
  41. if pkt.tcp_data[3] == 0 and pkt.tcp_data[4] == MYSQL_COM_QUERY then
  42. query_length = (pkt.tcp_data[0,3] + "\0").unpack('V')[0] - 1
  43. next if query_length < 1
  44. query = pkt.tcp_data[5..-1]
  45. end
  46. end
Add Comment
Please, Sign In to add comment