{"id":34,"date":"2010-12-08T14:44:46","date_gmt":"2010-12-08T20:44:46","guid":{"rendered":"http:\/\/blogs.wp.stage.cpanel.net\/2010\/12\/the_admins_toolbox_vol_1_-_tcpdump_and_you\/"},"modified":"2010-12-08T14:44:46","modified_gmt":"2010-12-08T20:44:46","slug":"the_admins_toolbox_vol_1_-_tcpdump_and_you","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/products\/the_admins_toolbox_vol_1_-_tcpdump_and_you\/","title":{"rendered":"The Admin’s Toolbox, Vol. 1 – tcpdump and you."},"content":{"rendered":"
Hey there! In this instance of The Admins Toolbox, I’ll be discussing the tcpdump utility and some common uses. Sit back, crack open a frosty beverage of your choosing, and let’s learn about packet inspection for fun and profit. \ud83d\ude42<\/p>\n
Tcpdump is by no means a new program. Written by Van Jacobson, Craig Leres, and Steven McCanne, while working at Berkley in 1987, tcpdump\u2019<\/span>s popularity quickly rose due to its high caliber of features. Soon after it\u2019<\/span>s release, it was ported to just about every *nix flavor, taking off like wildfire.<\/p>\n Tcpdump Basics.<\/strong> Here’s a quick and dirty scenario you might see in your daily routine, and how tcpdump could save the day. \u00a0Please keep in mind that encrypted protocols will not allow sniffing of this sorts, sorry!<\/p>\n Your ever faithful customer, Ron, is having email problems again. The cPanel admin for Ron’s company, Widgets.com, updated the passwords for every employee’s email address. Well, today’s your lucky day. Ron’s admin is out of town and gave everyone at Widgets.com your number “just in case”. You get this phone call…<\/p>\n \nYou: “Thank you for calling Super Awesome Hosting Company, how may I help you today?”<\/p>\n Ron: “Hey there, it’s Ron again! I’ve got a tough one for you this time!”<\/p>\n You: “What are you having trouble with Ron?”<\/p>\n Ron: “So here’s the story, I’m putting my new password into my Outlook and your server is telling me it’s not right. You should be able to change this, right?”<\/p>\n You: “Well, sure thing, let me go ahead and generate a new password, then you should be good to go; one second please.”<\/p>\n <furious typing><\/p>\n <3 seconds later><\/p>\n You: “Alright Ron, your new password is going to be abc123, lowercase letters. You should be set now, please let me know if you run into any more problems!”<\/p>\n Ron: “Thanks again, you’re awesome!”<\/p>\n 3 minutes pass…. RING.<\/p>\n You: “Thank you for calling Super Awesome Hosting Company, how may I help you today?”<\/p>\n Ron: “It’s me again!”<\/p>\n You: “Hey Ron, still having problems?”<\/p>\n Ron: “I put that password in JUST<\/em> like you told me to and it’s not working either… Have you tried rebooting the server yet?”<\/p>\n You: “Well before we do that, do you mind if I check something else quick? When I tell you, would you mind clicking “Send and Receive” in Outlook?”<\/p>\n Ron: “Right on!”\n<\/p><\/blockquote>\n Now, this is where the magic of tcpdump comes into play. You login to Ron’s server. Armed with the knowledge that Ron is using POP3 to retrieve his mail, you start checking out payloads on TCP port 110 and give Ron the go-ahead.<\/p>\n Hrm, that wasn’t very helpful there… What did we just see? Let’s start with the tcpdump commandline first and see what we get. We’re calling tcpdump with the ‘-nn’ flag, which tells tcpdump not to do reverse DNS lookups on all the IPs it picks up; also not to resolve the port names to service names. Without the ‘-nn’ flag, you would see something like this…<\/p>\n It could be an expensive time waster to have this additional information given over a high packet per second interface. This could leave the customer waiting for what seems to them like an eternity, in turn putting more pressure on you to quickly solve their issue.<\/p>\n Next up is the ‘-i’ flag, where we tell tcpdump which interface to attach to, in this case, eth0. Next we specify which port we want to focus on, in our example, port 110 for the POP3 protocol. If we don’t specify which port we’re using, your screen is going to be flooded with your SSH transactions alone. This is also our first glimpse of the BPF mechanism in play.<\/p>\n After looking over our first run with tcpdump, we decide we didn’t get the information needed, as tcpdump by default gives a very slim overview of the traffic. We need to dig a bit deeper here, using the ‘-A’ flag.<\/p>\n The ‘-A’ flag is fun for folks like us. In it’s default invocation, it’ll print the first 96 bytes of a packet in ASCII format. Yay, human readability! In this instance, using the ‘-A’ flag will be the key we need to see what’s going on with Ron, who’s patiently waiting.<\/p>\n One thing you’ll be able to pick up is how to parse the packets more effectively. As you may have read above, the output has the answer we were looking for to help Ron!<\/p>\n Let me clean the output up a bit for you.<\/p>\n This is one packet, but not necessarily in it’s entirety (tcp packets can be upwards of 65k apiece; we’re only peeking at 96 bytes by default). The first line represents the two hosts having the conversation, the ports they’re talking on, and who sent the packet; essentially the header.<\/p>\n In this part of the packet there’s a bit of padding on the front, then voila, our POP3 server response telling the customer, “I’m here, go for it!”<\/p>\n So, looking at the initial capture, cleaned up a bit with the aforementioned in mind, here’s what we have…<\/p>\n \nYou: “Hey Ron, are you there?”<\/p>\n Ron: “Sure am, are you rebooting the server now?”<\/p>\n You: “No Ron, but I did find the reason we’re having trouble. Can you do me a favor and turn your capslock off and enter that password again?”<\/p>\n Ron: “Is that necessary? I wanted my password to be REALLY secret…”<\/p>\n You: “Yes Ron, Yes… Do that and try it again”<\/p>\n Ron: “Oh hey, it works! Are you sure you didn’t reboot the server?”\n<\/p><\/blockquote>\n So there you go; an easy to use basic usage of tcpdump you might see in your daily routine. We could’ve figured out Ron had a bad password from \/var\/log\/maillog, however, it wouldn’t have shown us how<\/em> it was bad. Given Ron’s frequency of calls into the helpdesk, tcpdump saved time by finding the specifics right away, and you never know, Ron may have learned a little something about passwords in the process.<\/p>\n Next up, we’ll be talking about more advanced usages of tcpdump, digging a little deeper into The Admins Toolbox.<\/p>\n","protected":false},"excerpt":{"rendered":" Hey there! In this instance of The Admins Toolbox, I’ll be discussing the tcpdump utility and some common uses. Sit back, crack open a frosty beverage of your choosing, and let’s learn about packet inspection for fun and profit. \ud83d\ude42 Tcpdump is by no means a new program. Written by Van Jacobson, Craig Leres, and […]<\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[49],"tags":[],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-products"],"acf":[],"yoast_head":"\n
\nAt it’s core, tcpdump is a wrapper for libpcap, which allows for full packet analysis of all traffic through the network stack of the interface you’re inspecting. The tcpdump app uses Berkeley filtering syntax for realtime packet filtering with extremely fine grained control, making it a “Swiss Army Knife” for server and network admins alike. Tcpdump allows for a proper view of network traffic that would be nearly impossible otherwise. A few examples of its use could be for detecting a (D)DoS attack or verifying an end-user really is entering the POP3 password they say they are.<\/p>\n
\nroot@cpanelvps [~]# tcpdump -nn -i eth0 port 110
\ntcpdump: verbose output suppressed, use -v or -vv for full protocol decode
\nlistening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
\n19:49:10.488790 IP 10.11.12.13.15263 > 172.16.134.69.110: S 2260515384:2260515384(0) win 64240 <mss 1460,nop,nop,sackOK>
\n19:49:10.488838 IP 172.16.134.69.110 > 10.11.12.13.15263: S 2161496985:2161496985(0) ack 2260515385 win 5840 <mss 1460,nop,nop,sackOK>
\n19:49:10.522786 IP 10.11.12.13.15263 > 172.16.134.69.110: . ack 1 win 64240
\n19:49:10.523022 IP 172.16.134.69.110 > 10.11.12.13.15263: P 1:21(20) ack 1 win 5840
\n19:49:10.556756 IP 10.11.12.13.15263 > 172.16.134.69.110: P 1:26(25) ack 21 win 64220
\n19:49:10.556770 IP 172.16.134.69.110 > 10.11.12.13.15263: . ack 26 win 5840
\n19:49:10.556862 IP 172.16.134.69.110 > 10.11.12.13.15263: P 21:26(5) ack 26 win 5840
\n19:49:10.590734 IP 10.11.12.13.15263 > 172.16.134.69.110: P 26:39(13) ack 26 win 64215
\n19:49:10.631034 IP 172.16.134.69.110 > 10.11.12.13.15263: . ack 39 win 5840
\n19:49:12.186189 IP 172.16.134.69.110 > 10.11.12.13.15263: P 26:55(29) ack 39 win 5840
\n19:49:12.220749 IP 10.11.12.13.15263 > 172.16.134.69.110: F 39:39(0) ack 55 win 64186
\n19:49:12.259941 IP 172.16.134.69.110 > 10.11.12.13.15263: . ack 40 win 5840
\n<\/code><\/p>\n
\n19:50:19.140525 IP office01.widgets.com.31773 > server18.superawesomehosting.com.pop3: . ack 1 win 64240
\n19:50:19.140648 IP server18.superawesomehosting.com.pop3 > office01.widgets.com.31773: P 1:21(20) ack 1 win 5840
\n19:50:19.174495 IP office01.widgets.com.31773 > server18.superawesomehosting.com.pop3: P 1:26(25) ack 21 win 64220
\n<\/code><\/p>\n
\nroot@cpanelvps [~]# tcpdump -nn -i eth0 port 110 -A
\ntcpdump: verbose output suppressed, use -v or -vv for full protocol decode
\nlistening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
\n19:54:12.405746 IP 10.11.12.13.12660 > 172.16.134.69.110: S 3147514733:3147514733(0) win 64240 <mss 1460,nop,nop,sackOK>
\nE..0 e@.s..P.JyfE.u.1t.n..Cm....p...R1..........
\n19:54:12.405787 IP 172.16.134.69.110 > 10.11.12.13.12660: S 2480457399:2480457399(0) ack 3147514734 win 5840 <mss 1460,nop,nop,sackOK>
\nE..0..@.@.5.E.u..Jyf.n1t......Cnp...............
\n19:54:12.439721 IP 10.11.12.13.12660 > 172.16.134.69.110: . ack 1 win 64240
\nE..( f@.s..W.JyfE.u.1t.n..Cn....P...$T..
\n19:54:12.439859 IP 172.16.134.69.110 > 10.11.12.13.12660: P 1:21(20) ack 1 win 5840
\nE..<..@.@.<.E.u..Jyf.n1t......CnP.......+OK Dovecot ready.
\n19:54:12.474717 IP 10.11.12.13.12660 > 172.16.134.69.110: P 1:26(25) ack 21 win 64220
\nE..A g@.s..=.JyfE.u.1t.n..Cn....P....#..USER ron.c@widgets.com
\n19:54:12.474725 IP 172.16.134.69.110 > 10.11.12.13.12660: . ack 26 win 5840
\n@.@.<.E.u..Jyf.n1t......C.P....H..
\n19:54:12.474790 IP 172.16.134.69.110 > 10.11.12.13.12660: P 21:26(5) ack 26 win 5840
\nE..-..@.@.<.E.u..Jyf.n1t......C.P.......+OK
\n19:54:12.509666 IP 10.11.12.13.12660 > 172.16.134.69.110: P 26:39(13) ack 26 win 64215
\nE..5 h@.s..H.JyfE.u.1t.n..C.....P.......PASS ABC123
\n19:54:12.549339 IP 172.16.134.69.110 > 10.11.12.13.12660: . ack 39 win 5840
\nE..(..@.@.<.E.u..Jyf.n1t......C.P....6..
\n19:54:14.107478 IP 172.16.134.69.110 > 10.11.12.13.12660: P 26:55(29) ack 39 win 5840
\nE..E..@.@.<.E.u..Jyf.n1t......C.P....C..-ERR Authentication failed.
\n<\/code><\/p>\n
\n19:57:12.668150 IP 172.16.134.69.110 > 10.11.12.13.20989: P 1:21(20) ack 1 win 5840
\nE..<.y@.@.O0E.u..Jyf.nQ..:....J.P.......+OK Dovecot ready.
\n<\/code><\/p>\n
\n19:54:12.549339 IP 172.16.134.69.110 > 10.11.12.13.12660: . ack 39 win 5840
\n^---1 ^-2 ^-3 ^-4 ^-5 ^-6 ^-7 ^-8 ^-9 ^-10
\n<\/code><\/p>\n\n
\nE..<.y@.@.O0E.u..Jyf.nQ..:....J.P.......+OK Dovecot ready.
\n<\/code><\/p>\n
\nServer: +OK Dovecot ready
\nClient: USER ron.c@widgets.com
\nServer: +OK
\nClient: PASS ABC123
\nServer: -ERR Authentication failed.
\n<\/code><\/p>\n