Guest User

Untitled

a guest
Apr 7th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #! /usr/bin/env ruby
  2.  
  3. $: << '/ops/lib/ruby'
  4.  
  5. TARGET_HOST=''
  6. TARGET_USER=''
  7. TARGET_PASS=''
  8. TARGET_DB=''
  9.  
  10. require 'rubygems'
  11. require 'pcaplet'
  12. require 'mysql'
  13.  
  14. MYSQL_COM_QUERY = 0x03
  15.  
  16. target_db = Mysql.real_connect(TARGET_HOST, TARGET_USER, TARGET_PASS, TARGET_DB)
  17.  
  18. mysqlsniff = Pcaplet.new('-s 65535 -i eth0')
  19. mysqlsniff.add_filter Pcap::Filter.new("tcp port 3306 and not dst #{TARGET_HOST}",
  20. mysqlsniff.capture)
  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 then
  28. if query[/^select/i] then
  29. start_time = Time.now
  30. puts query
  31. target_db.query query
  32. times = "== [%.2fs] ==" % (Time.now - start_time)
  33. puts times + '=' * (80 - times.length)
  34. puts
  35. end
  36. query = nil
  37. query_length = 0
  38. else
  39. query << pkt.tcp_data
  40. end
  41. end
  42.  
  43. if pkt.tcp_data[3] == 0 and pkt.tcp_data[4] == MYSQL_COM_QUERY then
  44. query_length = (pkt.tcp_data[0,3] + "\0").unpack('V')[0] - 1
  45. next if query_length < 1
  46. query = pkt.tcp_data[5..-1]
  47. end
  48. end
Add Comment
Please, Sign In to add comment