Netsh Utility Guide – Tracing and Beyond

Introduction

Provide a brief overview of the Netsh utility and its importance in network management. Highlight its key features, such as scripting support, remote execution, and troubleshooting capabilities.



Content Optimization

1. What is Netsh Utility?

Netsh (Network Shell) is a powerful Windows command-line tool for configuring and troubleshooting network settings. It interacts with system components via dynamic-link libraries (DLLs) and supports various contexts like advfirewall, wlan, and winhttp.

2. General Syntax of Netsh Commands

netsh [-a AliasFile] [-c Context] [-r RemoteMachine] [-u [Domain\]UserName] [-p Password|*] [Command | -f ScriptFile]

Explain the syntax parameters briefly, highlighting their use cases.

3. Deep-Dive into Netsh Tracing

Collecting Traces:
Use the netsh trace context to capture network events and packets for diagnostics.

  • Command to show scenarios:
netsh trace show scenarios
  • To display providers for a specific scenario:
netsh trace show scenario <Scenario name>

Important Parameters:
Detail the key parameters like scenario, capture, report, persistent, traceFile, etc., with examples.

Common Trace Commands:

  • Start tracing:
netsh trace start scenario=InternetClient capture=yes tracefile=C:\temp\trace.etl
  • Stop tracing:
netsh trace stop

Advanced Options:
Provide advanced tracing examples with options like maxsize, filemode, and overwrite.

Convert ETL to CAP:
Explain how to convert ETL files for use in tools like Wireshark:

netsh trace convert input=trace.etl output=trace.cap


4. Filtering Network Captures with Netsh

Basic Filters:
Highlight commonly used filters, such as:

  • Capture traffic to/from a specific IPv4 address:
IPv4.Address == x.x.x.x

Protocol-Specific Filters:

  • Capture DNS traffic:
DNS

Advanced Filters:
Provide examples like capturing TCP handshake packets:

TCP.Flags.SYN == 1 AND TCP.Flags.ACK == 0


5. Key Netsh Contexts and Use Cases

IP Configuration:

  • Set a static IP:
netsh interface ip set address "Ethernet" static 10.0.0.5 255.255.255.0 10.0.0.1

Reset Winsock and TCP/IP Stack:

  • Reset TCP/IP stack:
netsh int ip reset

Operating Firewall:

  • Add a firewall rule:
netsh advfirewall firewall add rule name="Allow Ping" dir=in action=allow protocol=icmpv4

Configuring WinHTTP Proxy:

  • Set proxy:
netsh winhttp set proxy "proxy:8080" "<local>"

Commonly used netmon filters to analyze network capture:

Basic Filters

FilterPurpose
IPv4.Address == x.x.x.xCaptures traffic to/from a specific IPv4 address.
IPv4.SourceAddress == x.x.x.xFilters traffic from a specific source IP.
IPv4.DestinationAddress == x.x.x.xFilters traffic to a specific destination IP.
IPv6.Address == xxxx::xxxxFilters IPv6 traffic to/from a specific address.
TCP.Port == 80Captures traffic on a specific TCP port (e.g., 80 for HTTP).
UDP.Port == 53Captures traffic on a specific UDP port (e.g., 53 for DNS).

Protocol-Specific Filters

FilterProtocolDescription
DNSDNSCaptures DNS queries and responses.
HTTPHTTPCaptures HTTP traffic (can be further filtered with methods).
TCPTCPCaptures all TCP traffic.
UDPUDPCaptures all UDP traffic.
SMB2SMBCaptures SMBv2 file-sharing traffic.
KerberosKerberosCaptures Kerberos authentication packets.
LDAPLDAPCaptures LDAP queries/responses.

Conversation Filters

FilterPurpose
IPv4.SourceAddress == x.x.x.x AND IPv4.DestinationAddress == y.y.y.yFilters traffic between two specific hosts.
TCP.SourcePort == 12345 AND TCP.DestinationPort == 80Filters a specific client-server session.

Application Layer Filters

FilterExample
HTTP.Request.Method == “GET”Captures only GET requests.
HTTP.Host == “example.com”Filters HTTP traffic to a specific domain.
DNS.QryName == “example.com”Filters DNS queries for a specific domain.
SMB2.CreateRequest.FileName == “filename.txt”Captures file access in SMB traffic.

Advanced Filters

FilterPurpose
TCP.Flags.SYN == 1 AND TCP.Flags.ACK == 0Captures SYN packets (start of TCP handshake).
TCP.Flags.FIN == 1Captures FIN packets (end of TCP session).
TCP.Flags.Reset == 1Captures TCP RST packets (connection resets).
Frame.Length > 1000Captures only packets larger than 1000 bytes.

Key Netsh Contexts and Use-Case

Set IP configuration

netsh interface ip set address “Ethernet” static 10.0.0.5 255.255.255.0 10.0.0.1
netsh interface ip set dns “Ethernet” static 1.1.1.1
netsh interface ip set address “Ethernet” dhcp

Reset Winsock and TCP/IP Stack

netsh int ip reset
netsh winsock reset

Operating Firewall

netsh advfirewall firewall add rule name=”Allow Ping” dir=in action=allow protocol=icmpv4
netsh advfirewall firewall add rule name=”Allow RDP” dir=in action=allow protocol=TCP localport=3389

netsh advfirewall set allprofiles state on
netsh advfirewall export “C:\\backup\\fwconfig.wfw”

WinHTTP Proxy

netsh winhttp show proxy
netsh winhttp set proxy “proxy:8080” “<local>”
netsh winhttp reset proxy


6. Conclusion

Summarize the versatility of Netsh as a tool for network management and troubleshooting. Encourage readers to explore more contexts and commands using official Microsoft documentation.

Leave a Comment