
{"id":15544,"date":"2014-03-10T12:51:03","date_gmt":"2014-03-10T12:51:03","guid":{"rendered":"http:\/\/www.beautifulwork.org\/?p=15544"},"modified":"2014-03-10T12:51:03","modified_gmt":"2014-03-10T12:51:03","slug":"tshark-dump-and-analyze-network-traffic","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2014\/03\/10\/tshark-dump-and-analyze-network-traffic\/","title":{"rendered":"tshark &#8211; Dump and analyze network traffic"},"content":{"rendered":"<p><u>ABOUT tshark<\/u><\/p>\n<pre>\nTShark is a command-line network traffic analyzer that enables you to capture packet data from a live network or read packets from a previously saved capture file by either printing a decoded form of those packets to the standard output or by writing the packets to a file. Without any options, TShark works similarly to the tcpdump command and also uses the same live capture file format, libpcap. In addition, TShark is capable of detecting, reading, and writing the same capture files as those that are supported by Wireshark.\n\n<\/pre>\n<p><u>RELATED SHELL EXPOSURE<\/u><br \/>\nsmall part of content formatted<br \/>\n[bash light=&#8221;true&#8221;]<br \/>\n$sudo tshark -c 2  -O tcp<br \/>\nsudo: \/var\/lib\/sudo writable by non-owner (040777), should be mode 0700<\/p>\n<p>We trust you have received the usual lecture from the local System<br \/>\nAdministrator. It usually boils down to these three things:<\/p>\n<p>    #1) Respect the privacy of others.<br \/>\n    #2) Think before you type.<br \/>\n    #3) With great power comes great responsibility.<\/p>\n<p>[sudo] password for jeffrin:<br \/>\ntshark: Lua: Error during loading:<br \/>\n [string &quot;\/usr\/share\/wireshark\/init.lua&quot;]:46: dofile has been disabled due to running Wireshark as<br \/>\nsuperuser. See http:\/\/wiki.wireshark.org\/CaptureSetup\/CapturePrivileges for help in running Wireshark as<br \/>\nan unprivileged user.<br \/>\nRunning as user &quot;root&quot; and group &quot;root&quot;. This could be dangerous.<br \/>\nCapturing on &#8216;eth0&#8217;<br \/>\nFrame 1: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0<br \/>\nEthernet II, Src: AsustekC_59:c2:7d (60:a4:4c:59:c2:7d), Dst: D-Link_5c:01:1a (5c:d9:98:5c:01:1a)<br \/>\nInternet Protocol Version 4, Src: 192.168.0.102 (192.168.0.102), Dst: 74.125.236.160 (74.125.236.160)<br \/>\nTransmission Control Protocol, Src Port: 46926 (46926), Dst Port: https (443), Seq: 1, Ack: 1, Len: 0<br \/>\n    Source port: 46926 (46926)<br \/>\n    Destination port: https (443)<br \/>\n    [Stream index: 0]<br \/>\n    Sequence number: 1    (relative sequence number)<br \/>\n    Acknowledgment number: 1    (relative ack number)<br \/>\n    Header length: 32 bytes<br \/>\n    Flags: 0x010 (ACK)<br \/>\n        000. &#8230;. &#8230;. = Reserved: Not set<br \/>\n        &#8230;0 &#8230;. &#8230;. = Nonce: Not set<br \/>\n        &#8230;. 0&#8230; &#8230;. = Congestion Window Reduced (CWR): Not set<br \/>\n        &#8230;. .0.. &#8230;. = ECN-Echo: Not set<br \/>\n        &#8230;. ..0. &#8230;. = Urgent: Not set<br \/>\n        &#8230;. &#8230;1 &#8230;. = Acknowledgment: Set<br \/>\n        &#8230;. &#8230;. 0&#8230; = Push: Not set<br \/>\n        &#8230;. &#8230;. .0.. = Reset: Not set<br \/>\n        &#8230;. &#8230;. ..0. = Syn: Not set<br \/>\n        &#8230;. &#8230;. &#8230;0 = Fin: Not set<br \/>\n    Window size value: 353<br \/>\n    [Calculated window size: 353]<br \/>\n    [Window size scaling factor: -1 (unknown)]<br \/>\n    Checksum: 0xa100a [validation disabled]<br \/>\n        [Good Checksum: False]<br \/>\n        [Bad Checksum: False]<br \/>\n    Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps<br \/>\n        No-Operation (NOP)<br \/>\n            Type: 1<br \/>\n                0&#8230; &#8230;. = Copy on fragmentation: No<br \/>\n                .00. &#8230;. = Class: Control (0)<br \/>\n                &#8230;0 0001 = Number: No-Operation (NOP) (1)<br \/>\n        No-Operation (NOP)<br \/>\n            Type: 1<br \/>\n                0&#8230; &#8230;. = Copy on fragmentation: No<br \/>\n                .00. &#8230;. = Class: Control (0)<br \/>\n                &#8230;0 0001 = Number: No-Operation (NOP) (1)<br \/>\n        Timestamps: TSval 300928, TSecr 2174612263<br \/>\n            Kind: Timestamp (8)<br \/>\n            Length: 10<br \/>\n            Timestamp value: 300928<br \/>\n            Timestamp echo reply: 2174612263<\/p>\n<p>Frame 2: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0<br \/>\nEthernet II, Src: D-Link_5c:01:1a (5c:d9:98:5c:01:1a), Dst: AsustekC_59:c2:7d (60:a4:4c:59:c2:7d)<br \/>\nInternet Protocol Version 4, Src: 74.125.236.160 (74.125.236.160), Dst: 192.168.0.102 (192.168.0.102)<br \/>\nTransmission Control Protocol, Src Port: https (443), Dst Port: 46926 (46926), Seq: 1, Ack: 2, Len: 0<br \/>\n    Source port: https (443)<br \/>\n    Destination port: 46926 (46926)<br \/>\n    [Stream index: 0]<br \/>\n    Sequence number: 1    (relative sequence number)<br \/>\n    Acknowledgment number: 2    (relative ack number)<br \/>\n    Header length: 32 bytes<br \/>\n    Flags: 0x010 (ACK)<br \/>\n        000. &#8230;. &#8230;. = Reserved: Not set<br \/>\n        &#8230;0 &#8230;. &#8230;. = Nonce: Not set<br \/>\n        &#8230;. 0&#8230; &#8230;. = Congestion Window Reduced (CWR): Not set<br \/>\n        &#8230;. .0.. &#8230;. = ECN-Echo: Not set<br \/>\n        &#8230;. ..0. &#8230;. = Urgent: Not set<br \/>\n        &#8230;. &#8230;1 &#8230;. = Acknowledgment: Set<br \/>\n        &#8230;. &#8230;. 0&#8230; = Push: Not set<br \/>\n        &#8230;. &#8230;. .0.. = Reset: Not set<br \/>\n        &#8230;. &#8230;. ..0. = Syn: Not set<br \/>\n        &#8230;. &#8230;. &#8230;0 = Fin: Not set<br \/>\n    Window size value: 661<br \/>\n    [Calculated window size: 661]<br \/>\n    [Window size scaling factor: -1 (unknown)]<br \/>\n    Checksum: 0xa521 [validation disabled]<br \/>\n        [Good Checksum: False]<br \/>\n        [Bad Checksum: False]<br \/>\n    Options: (12 bytes), No-Operation (NOP), No-Operation (NOP), Timestamps<br \/>\n        No-Operation (NOP)<br \/>\n            Type: 1<br \/>\n                0&#8230; &#8230;. = Copy on fragmentation: No<br \/>\n                .00. &#8230;. = Class: Control (0)<br \/>\n                &#8230;0 0001 = Number: No-Operation (NOP) (1)<br \/>\n        No-Operation (NOP)<br \/>\n            Type: 1<br \/>\n                0&#8230; &#8230;. = Copy on fragmentation: No<br \/>\n                .00. &#8230;. = Class: Control (0)<br \/>\n                &#8230;0 0001 = Number: No-Operation (NOP) (1)<br \/>\n        Timestamps: TSval 21741007319, TSecr 255876<br \/>\n            Kind: Timestamp (8)<br \/>\n            Length: 10<br \/>\n            Timestamp value: 21741007319<br \/>\n            Timestamp echo reply: 255876<br \/>\n    [SEQ\/ACK analysis]<br \/>\n        [TCP Analysis Flags]<br \/>\n            [This frame ACKs a segment we have not seen]<br \/>\n                [Expert Info (Warn\/Sequence): ACKed segment that wasn&#8217;t captured (common at capture start)]<br \/>\n                    [Message: ACKed segment that wasn&#8217;t captured (common at capture start)]<br \/>\n                    [Severity level: Warn]<br \/>\n                    [Group: Sequence]<\/p>\n<p>2<br \/>\n$<\/p>\n<p>[\/bash]<\/p>\n<p><u>RELATED SOURCE CODE EXPOSURE<\/u><br \/>\n[c light=&#8221;true&#8221;]<br \/>\n\/*<br \/>\n * Default one-shot callback; overridden for capture types where the<br \/>\n * packet data cannot be guaranteed to be available after the callback<br \/>\n * returns, so that a copy must be made.<br \/>\n *\/<br \/>\nvoid<br \/>\npcap_oneshot(u_char *user, const struct pcap_pkthdr *h, const u_char *pkt)<br \/>\n{<br \/>\n\tstruct oneshot_userdata *sp = (struct oneshot_userdata *)user;<\/p>\n<p>\t*sp-&gt;hdr = *h;<br \/>\n\t*sp-&gt;pkt = pkt;<br \/>\n}<\/p>\n<p>const u_char *<br \/>\npcap_next(pcap_t *p, struct pcap_pkthdr *h)<br \/>\n{<br \/>\n\tstruct oneshot_userdata s;<br \/>\n\tconst u_char *pkt;<\/p>\n<p>\ts.hdr = h;<br \/>\n\ts.pkt = &amp;pkt;<br \/>\n\ts.pd = p;<br \/>\n\tif (pcap_dispatch(p, 1, p-&gt;oneshot_callback, (u_char *)&amp;s) &lt;= 0)<br \/>\n\t\treturn (0);<br \/>\n\treturn (pkt);<br \/>\n}<\/p>\n<p>int<br \/>\npcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header,<br \/>\n    const u_char **pkt_data)<br \/>\n{<br \/>\n\tstruct oneshot_userdata s;<\/p>\n<p>\ts.hdr = &amp;p-&gt;pcap_header;<br \/>\n\ts.pkt = pkt_data;<br \/>\n\ts.pd = p;<\/p>\n<p>\t\/* Saves a pointer to the packet headers *\/<br \/>\n\t*pkt_header= &amp;p-&gt;pcap_header;<\/p>\n<p>\tif (p-&gt;rfile != NULL) {<br \/>\n\t\tint status;<\/p>\n<p>\t\t\/* We are on an offline capture *\/<br \/>\n\t\tstatus = pcap_offline_read(p, 1, p-&gt;oneshot_callback,<br \/>\n\t\t    (u_char *)&amp;s);<\/p>\n<p>\t\t\/*<br \/>\n\t\t * Return codes for pcap_offline_read() are:<br \/>\n\t\t *   &#8211;  0: EOF<br \/>\n\t\t *   &#8211; -1: error<br \/>\n\t\t *   &#8211; &gt;1: OK<br \/>\n\t\t * The first one (&#8216;0&#8217;) conflicts with the return code of<br \/>\n\t\t * 0 from pcap_read() meaning &quot;no packets arrived before<br \/>\n\t\t * the timeout expired&quot;, so we map it to -2 so you can<br \/>\n\t\t * distinguish between an EOF from a savefile and a<br \/>\n\t\t * &quot;no packets arrived before the timeout expired, try<br \/>\n\t\t * again&quot; from a live capture.<br \/>\n\t\t *\/<br \/>\n\t\tif (status == 0)<br \/>\n\t\t\treturn (-2);<br \/>\n\t\telse<br \/>\n\t\t\treturn (status);<br \/>\n\t}<\/p>\n<p>\t\/*<br \/>\n\t * Return codes for pcap_read() are:<br \/>\n\t *   &#8211;  0: timeout<br \/>\n\t *   &#8211; -1: error<br \/>\n\t *   &#8211; -2: loop was broken out of with pcap_breakloop()<br \/>\n\t *   &#8211; &gt;1: OK<br \/>\n\t * The first one (&#8216;0&#8217;) conflicts with the return code of 0 from<br \/>\n\t * pcap_offline_read() meaning &quot;end of file&quot;.<br \/>\n\t*\/<br \/>\n\treturn (p-&gt;read_op(p, 1, p-&gt;oneshot_callback, (u_char *)&amp;s));<br \/>\n}<br \/>\n[\/c]<br \/>\nSOURCE CODE TAKEN FROM DEBIAN SOURCE PACKAGE libpcap<\/p>\n<p>SOURCE AND OTHER LINK(S)<br \/>\n<a href=\"https:\/\/docs.oracle.com\/cd\/E53394_01\/html\/E54741\/gncns.html\">https:\/\/docs.oracle.com\/cd\/E53394_01\/html\/E54741\/gncns.html<\/a><br \/>\n<a href=\"https:\/\/hackertarget.com\/tshark-tutorial-and-filter-examples\/\">https:\/\/hackertarget.com\/tshark-tutorial-and-filter-examples\/<\/a><br \/>\n<a href=\"https:\/\/www.linuxjournal.com\/content\/using-tshark-watch-and-inspect-network-traffic\">https:\/\/www.linuxjournal.com\/content\/using-tshark-watch-and-inspect-network-traffic<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ABOUT tshark TShark is a command-line network traffic analyzer that enables you to capture packet data from a live network or read packets from a previously saved capture file by either printing a decoded form of those packets to the standard output or by writing the packets to a file. Without any options, TShark works &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2014\/03\/10\/tshark-dump-and-analyze-network-traffic\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;tshark &#8211; Dump and analyze network traffic&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[692,1166,1551,1694],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/15544"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=15544"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/15544\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=15544"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=15544"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=15544"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}