Last active
July 21, 2017 13:19
-
-
Save cgimenes/e28f57977fb437422c470c5256bdf833 to your computer and use it in GitHub Desktop.
tcpdump MySQL traffic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
intf=$1 | |
port=$2 | |
if [ -z "${intf}" ]; then | |
intf="eth0" | |
fi | |
if [ -z "${port}" ]; then | |
port="3306" | |
fi | |
tcpdump -i ${intf} -s 0 -l -w - dst port ${port} | strings | perl -e ' | |
while(<>) { chomp; next if /^[^ ]+[ ]*$/; | |
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|CALL)/i) | |
{ | |
if (defined $q) { print "$q\n"; } | |
$q=$_; | |
} else { | |
$_ =~ s/^[ \t]+//; $q.=" $_"; | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment