Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 246d1f1

Browse files
committedSep 2, 2010
Script for sniffing mysql traffic
1 parent fff1c0a commit 246d1f1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
 

‎tool/pcap-mysql.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env node
2+
3+
var sys = require("sys"),
4+
pcap = require("pcap"),
5+
mysqlPort = parseInt(process.argv[3]) || 3306,
6+
pcap_session = pcap.createSession(process.argv[2] || '', 'tcp port '+mysqlPort);
7+
8+
sys.puts('This tool allows to reverse engineer the mysql procotocol using node-pcap.');
9+
sys.puts('');
10+
sys.puts('Available devices (active one is denoted by *):');
11+
12+
// Print all devices, currently listening device prefixed with an asterisk
13+
pcap_session.findalldevs().forEach(function (dev) {
14+
sys.print(' ');
15+
if (pcap_session.device_name === dev.name) {
16+
sys.print("* ");
17+
}
18+
sys.print(dev.name + " ");
19+
if (dev.addresses.length > 0) {
20+
dev.addresses.forEach(function (address) {
21+
sys.print(address.addr + "/" + address.netmask);
22+
});
23+
sys.print("\n");
24+
} else {
25+
sys.print("no address\n");
26+
}
27+
});
28+
29+
sys.puts('');
30+
sys.puts('Execute `./pcap-mysql.js <device> <mysql-port>` to listen on another device.');
31+
sys.puts('');
32+
33+
// Listen for packets, decode them, and feed the simple printer. No tricks.
34+
pcap_session.on('packet', function (raw_packet) {
35+
var packet = pcap.decode.packet(raw_packet);
36+
//sys.puts(pcap.print.packet(packet));
37+
var tcp = packet.link.ip.tcp;
38+
if (!tcp.data) {
39+
return;
40+
}
41+
42+
if (tcp.sport == mysqlPort) {
43+
sys.puts('<- '+tcp.data.inspect());
44+
} else {
45+
sys.puts('-> '+tcp.data.inspect());
46+
}
47+
});
48+

0 commit comments

Comments
 (0)
Please sign in to comment.