Pages

Showing posts with label packet-level. Show all posts
Showing posts with label packet-level. Show all posts

1/02/2019

Capture on Windows Server without any Wireshark or other install




Netsh trace start capture=yes tracefile=c:\temp\trace.etl 
Netsh trace stop
 .\etl-to-pcap.ps1 -Path c:\temp\trace.etl -Destination c:\temp\trace.pcap



etl-to-pcap.ps1
[CmdletBinding()]

param(
[Parameter(Position=0)]
[ValidateScript({
    if( -Not ($_ | Test-Path) ){
        throw "File or folder $_ does not exist"
    }

    if($_.Extension -ne ".etl"){
        throw "Source file must be .etl file"
    }
    return $true
})]
[System.IO.FileInfo]$Path,

[Parameter(Position=1)]
[ValidateScript({
    if( -Not ($path.DirectoryName | Test-Path) ){
        throw "File or folder does not exist"
    }

    if($_.Extension -ne ".pcap") {
        throw "Estination file must be .pcap file"
    }
    return $true
})]
[System.IO.FileInfo]$Destination,

[Parameter(Position=2)]
[Uint32]$MaxPacketSizeBytes = 65536)


$csharp_code = @'
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace chentiangemalc
{
    public static class NetworkRoutines
    {
    public static long ConvertEtlToPcap(string source, string destination, UInt32 maxPacketSize)
        {
            int result = 0;
            using (BinaryWriter writer = new BinaryWriter(File.Open(destination, FileMode.Create)))
            {

                UInt32 magic_number = 0xa1b2c3d4;
                UInt16 version_major = 2;
                UInt16 version_minor = 4;
                Int32 thiszone = 0;
                UInt32 sigfigs = 0;
                UInt32 snaplen = maxPacketSize;
                UInt32 network = 1; // LINKTYPE_ETHERNET

                writer.Write(magic_number);
                writer.Write(version_major);
                writer.Write(version_minor);
                writer.Write(thiszone);
                writer.Write(sigfigs);
                writer.Write(snaplen);
                writer.Write(network);

                long c = 0;
                long t = 0;
                using (var reader = new EventLogReader(source, PathType.FilePath))
                {
                    EventRecord record;
                    while ((record = reader.ReadEvent()) != null)
                    {
                        c++;
                        t++;
                        if (c == 10000)
                        {
                            Console.WriteLine(String.Format("Processed {0} events with {1} packets processed",t,result));
                            c = 0;
                        }
                        using (record)
                        {
                            if (record.ProviderName == "Microsoft-Windows-NDIS-PacketCapture")
                            {
                                result++;
                                DateTime timeCreated = (DateTime)record.TimeCreated;
                                UInt32 ts_sec = (UInt32)((timeCreated.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
                                UInt32 ts_usec = (UInt32)(((timeCreated.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds) - ((UInt32)((timeCreated.Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000))) * 1000;
                                UInt32 incl_len = (UInt32)record.Properties[2].Value;
                                if (incl_len > maxPacketSize)
                                {
                                   Console.WriteLine(String.Format("Packet size of {0} exceeded max packet size {1}, packet ignored",incl_len,maxPacketSize));
                                }
                                UInt32 orig_len = incl_len;

                                writer.Write(ts_sec);
                                writer.Write(ts_usec);
                                writer.Write(incl_len);
                                writer.Write(orig_len);
                                writer.Write((byte[])record.Properties[3].Value);

                            }
                        }
                    }
                }
            }
            return result;
        }
    }
}
'@

Add-Type -Type $csharp_code

$result = [chentiangemalc.NetworkRoutines]::ConvertEtlToPcap($Path.FullName,$Destination.FullName,$MaxPacketSizeBytes)

Write-Host "$result packets converted."





4/21/2016

Cisco Nexus: EthAnalyzer

I've been fighting with getting EthAnalyzer trying to get it to do something useful.  But it always only showed me traffic to/from the switch itself, not packets that pass through it. 
Today I found the following information and EUREKA!
ethanalyzer data plane traffic analysis



ACLs and Ethanalyzer for Data Plane Sampling:
The Ethanalyzer captures only traffic on CPU, so seems as unsuitable solution for the data plane traffic analysis. However, this limitation can be avoided with a use of ACL logging to sample specific packets from data plane.
              .   .   .
When we use ACLs and the “log” keyword, access control entries (ACEs) with log keyword cause system to punt a copy of matching packets to supervisor CPU. Key point is that original traffic forwarded or dropped in hardware with no performance penalty. Note that punted copies subjected to hardware rate limiter, forwarding engine hardware enforces rate to avoid saturating inband interface/CPU.

So the following accomplished what I have been trying to do for a long time:
IP access list acl-cap

  10 permit ip 10.10.10.11/32 any log

  20 permit ip any any
Eth6/28
  ip port access-group acl-cap in

ethanalyzer local int inband limit-captured-frames 0 autostop duration 60 write bootflash:test-2.pcap




10/19/2015

How to Do TCP Sequence Number Analysis

How to Do TCP Sequence Number Analysis

From packetbomb.com
  • TCP typically ACKs every other segment
  • Add sequence number, next sequence number, and acknowledgment number to your Wireshark columns
  • Next sequence number is sequence number plus TCP data payload length
  • ACK number tells you what data has been received and what the next received sequence number should be
  • TCP will ACK every packet when in recovery


  • Command line: Using tcpdump to find scanning activity

    Command line: Using tcpdump to find scanning activity

    Great Stuff from packetbomb.com

    7/12/2015

    Packet Capture From Cisco Router


    7K

    ethanalyzer local interface inband limit-captured-frames 20000 autostop duration 120 write bootflash:capture.pcap

    IOS-XE Router


    monitor capture CAP int Gi0/0/1 both
    monitor capture CAP match ipv4 any any
    monitor capture CAP start
    show monitor capture CAP buffer brief
    monitor capture CAP stop
    monitor capture CAP export ftp://10.1.10.27/CAP.pcap
    no monitor capture CAP

    IOS Router

    1. create access-list for packet filter
    2. access-list 1 permit 10.100.1.45
    3. create buffer
    4. monitor capture buffer holdpackets
    5. filter buffer
    6. monitor capture buffer holdpackets filter access-list 1
    7. create capture point
    8. monitor capture point ip cef mytrace all both
    9. associate capture point with buffer
    10. monitor capture point associate mytrace holdpackets
    11. start capture
    12. monitor capture point start mytrace
      • Look at progress
      show monitor capture buffer all parameters
      • See list of capture points
      show monitor capture point all
    13. Stop the capture
    14. monitor capture point stop mytrace
    15. Export buffer as PCAP
    16. monitor capture buffer holdpackets export tftp://10.1.10.27/mytrace.pcap
    17. Remove buffer
    18. no monitor capture buffer holdpackets
    19. Remove capture point
    20. no monitor capture point ip cef mytrace all both



    1/12/2015

    Troubleshooting TCP Throughput

    Good presentation of TCP Throughput troubleshooting:
    PDF:  http://packetbomb.com/understanding-throughput-and-tcp-windows
    Video with example:
    https://www.youtube.com/watch?v=qFWjugyKyrE

    Thanks to kory@packetbomb.com

    Packet-Level: Am I looking at a trace from client side or server side?

    Look at 3 way handshake (SYN, SYN/ACK, ACK.)
      - Client side trace will have delay between SYN & SYN/ACK
      - Server side trace will have delay between SYN/ACK & ACK.

    Duh, this is obvious!  Some might say.  But I find it insightful as TCP analysis is just a "hobby" -- I do it so rarely in my work that I learn and re-learn each time I need to slog through a trace file.

    1/09/2013

    Some code playing around with sending mail with an attachment from a powershell script. Also launching a packet capture from another process so I can asynchronously repeat a test while doing a capture. -> Although I was able to execute an external command that included variables (to build the command line with a custom value for delay and output file) I was not able to start a job to do that same thing. I resorted to creating a custom batch file for this script and defining tshark duration and output file in that BAT file. -- not as flexible as I was trying to be.
    
    #INSTANCE 1 
    #  - Capture command:  C:\WORK\CAP1.BAT
    #  - Output file:  CAP1OUT.CAP
    
    $temp = "c:\work"
    $test = "\\fs05\users\admin\test"
    $threshold = 10
    $SmtpServer = "mail.usa.domain.com"
    $emailfrom = "no-reply-monitor@domain.com)"
    $emailto = "administrator@domain.com"
    $emailsubject = "folder count monitor output"
    $emailbody = "Folder:  $test contains less than $threshold items"
    $emailattachment="c:\temp\file.txt"
    $emailfrom = ""
    $emailto = ""
    $emailsubject = "Monitoring Output"  
    
    function send_email {
     $mailmessage = New-Object system.net.mail.mailmessage 
     $mailmessage.from = ($emailfrom) 
     $mailmessage.To.add($emailto)
     $mailmessage.Subject = $emailsubject
     $mailmessage.Body = $emailbody
     $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
     $mailmessage.Attachments.Add($attachment)
     #$mailmessage.IsBodyHTML = $true
     $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)  
     #$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTPAuthUsername", "$SMTPAuthPassword")
     $SMTPClient.Send($mailmessage)
    }#end-function
    
    if ((Get-ChildItem $test).Count -lt $threshold){
     "capturing for 30 s"
     ####################################################
     #     CAPTURE COMMAND
       $job = start-job {&cmd "/c","C:\WORK\CAP1.BAT"}
     ####################################################
     start-sleep 10
     "Testing Folder $test"
      Get-ChildItem $test | out-null
     "waiting 30 s"
      Start-Sleep 30
     wait-job $job
     remove-job $job
     "sending CAP file to $emailto"
     ####################################################
     #     OUTPUT FILE
      $emailattachment = "c:\work\cap1out.cap"
     ####################################################
      send_email 
    }
    

    1/08/2013

    8 Wireshark Filters Every Wiretapper Uses to Spy on Web Conversations and Surfing Habits « Null Byte

    8 Wireshark Filters
    http://null-byte.wonderhowto.com/inspiration/8-wireshark-filters-every-wiretapper-uses-spy-web-conversations-and-surfing-habits-0134508/
    ip.addr ==x.x.x.x
         Find packets with IP address as either source or destination
    ip.addr ==x.x.x.x && ip.addr ==x.x.x.x
         conversation filter between the two IP addresses
    http or dns
         filter based on protocol
    tcp.port==xxx
         filters based on TCP port numbers
    tcp.flags.reset==1
         filters to show all TCP resets.  A TCP reset basically kills a TCP connection instantly.
    http.request
         Sets a filter for all HTTP GET and POST requests. This will show webpages being accessed for the most part.
    tcp contains xxx
         Find TCP packets containing string.
    (arp or icmp or dns)
         filter out protocols. The example hides ARP, ICMP, and DNS packets.

    10/22/2009

    Good article: Storms RIP the Net

    This is an informative recounting by Laura Chappel of the investigation and repair of network traffic issue crippling a network. Nothing could stay connected even long enough to do a "normal" packet capture.
    She had them setup a quick packet capture outside the GUI to allow for getting on and getting the capture before being bumped off.

    tshark -c 100 -w gen1.pcap


    The -c parameter indicates the number of packets to capture. The -w parameter is
    used to define the name of the trace file to create.

    Looking at the 100 packets the fact that the IP Identification field matched for every packet indicated that this was a looping condition rather than some kind of denial of service from a single host.

    A switch loop is easy to create and often hard to troubleshoot, unless you are looking for this exact condition. And often the opportunity to create a loop is made available to the masses with proliferation of workgroup switches to avoid spending a couple hundred bucks on having another jack installed. ("Gee, here's an end of a cable coming out of a big tangle under my desk. It must need plugged in...")

    Separating broadcast domains into several VLAN's, like one per floor or some other logical separation, can limit the scope of a problem due to a switch loop. At least only one VLAN will be down and you have a narrower search area for the loop -- check the log on one or two switches instead of 20-30.

    8/14/2009

    Finicky QOS

    Laura's Blog
    The link to Laura Chappel's blog is really a teaser she posted to make us interested in her "top 10 reasons why the network is slow" online training session.
    If "training" was not a bad word around here, I'd recommend a couple of us attend that session and all the rest of them too. They are just $99 and they are awesome. I was able to watch one of them some time ago and it was extraordinary.
    Anyway, her blog has a link to a sample capture file. I wish I had gathered some captures a while back on our network because we had this very issue at one of our WAN sites.
    That office moved and got a new phone setup: all IP phones pointed to an enterprise phone system back in the HQ datacenter. That was all fine and good except the voice contractor doesn't listen to anything we say and we spent several days coming to some kind of half understanding of what the setup was and how we needed to make adjustments to QOS.
    Basically, we just need to dedicate half our circuit to the EF queue and then stick everything in it. :) Having work now with both Avaya and Cisco VOIP people I find there is a really big gap in Avaya contractors giving a care about communicating with network people.