mysql抓包_mysql抓包工具
簡介
MySQL Sniffer 是一個基于 MySQL 協議的抓包工具,實時抓取 MySQLServer 端或 Client 端請求,并格式化輸出。輸出內容包括訪問時間、訪問用戶、來源 IP、訪問 Database、命令耗時、返回數據行數、執行語句等。有批量抓取多個端口,后臺運行,日志分割等多種使用方式,操作便捷,輸出友好。
同時也適用抓取 Atlas 端的請求,Atlas 是奇虎開源的一款基于MySQL協議的數據中間層項目,項目地址:https://github.com/Qihoo360/Atlas
同類型工具還有vc-mysql-sniffer,以及 tshark 的 -e mysql.query 參數來解析 MySQL 協議。
使用
建議在 centos6.2 及以上編譯安裝,并用 root 運行。
依賴
glib2-devel、libpcap-devel、libnet-devel
安裝
git clone git@github.com:Qihoo360/mysql-sniffer.git
cd mysql-sniffer
mkdir proj
cd proj
cmake ../
make
cd bin/
參數:
./mysql-sniffer -h
Usage mysql-sniffer [-d] -i eth0 -p 3306,3307,3308 -l /var/log/mysql-sniffer/ -e stderr
[-d] -i eth0 -r 3000-4000
-d daemon mode.
-s how often to split the log file(minute, eg. 1440). if less than 0, split log everyday
-i interface. Default to eth0
-p port, default to 3306. Multiple ports should be splited by ','. eg. 3306,3307
this option has no effect when -f is set.
-r port range, Don't use -r and -p at the same time
-l query log DIRECTORY. Make sure that the directory is accessible. Default to stdout.
-e error log FILENAME or 'stderr'. if set to /dev/null, runtime error will not be recorded
-f filename. use pcap file instead capturing the network interface
-w white list. dont capture the port. Multiple ports should be splited by ','.
-t truncation length. truncate long query if it's longer than specified length. Less than 0 means no truncation
-n keeping tcp stream count, if not set, default is 65536. if active tcp count is larger than the specified count, mysql-sniffer will remove the oldest one
示例
1. 實時抓取某端口信息并打印到屏幕
輸出格式為:時間,訪問用戶,來源 IP,訪問 Database,命令耗時,返回數據行數,執行語句。
mysql-sniffer -i eth0 -p 3306
2017-02-23 14:47:45???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? select @@version_comment limit 1
2017-02-23 14:47:45???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? select USER()
2017-02-23 14:47:48???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms???????????? 13???? show databases
2017-02-23 14:47:51???? testuser???? 10.xx.xx.xx???? NULL??????????????0ms??????????????1???? SELECT DATABASE()
2017-02-23 14:47:51???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms??????????????0???? use mysql
2017-02-23 14:47:53???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms???????????? 29???? show tables
2017-02-23 14:47:54???? testuser???? 10.xx.xx.xx???? mysql??????????????0ms??????????????1???? select 1
2017-02-23 14:48:01???? testuser1???? 10.xx.xx.xx???? NULL??????????????0ms??????????????0???? set autocommit=1
2017-02-23 14:48:01???? testuser1???? 10.xx.xx.xx???? NULL??????????????0ms??????????????0???? set autocommit=1
2. 實時抓取某端口信息并打印到文件
-l 指定日志輸出路徑,日志文件將以 port.log 命名。
mysql-sniffer -i eth0 -p 3306 -l /tmp
3. 實時抓取多個端口信息并打印到文件
-l 指定日志輸出路徑,-p 指定需要抓取的端口列表逗號分割。日志文件將以各自 port.log 命名。
mysql-sniffer -i eth0 -p 3306,3307,3310 -l /tmp
……
問題
有lvs環境下,如果client IP是保存在在每個連接階段的tcp opt字段中,那么mysql-sniffer提取的真實的client IP而不是lvs的IP。
只能抓取新建的鏈接,如果是之前創建的鏈接將獲取不到用戶名和庫名,并有一定幾率丟包。
總結
以上是生活随笔為你收集整理的mysql抓包_mysql抓包工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 好玩的网名75个
- 下一篇: 蜜蜡颜色等级划分图解(蜜蜡成色分类及最高