SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
WinPcap Do’s and Don’ts Wednesday, June 17th, 2009 GianlucaVarenni Senior Software Engineer |  CACE Technologies, Inc. WinPcapProduct Manager gianluca.varenni@cacetech.com SHARKFEST'09 Stanford University June 15-18, 2009
Agenda Do’s and Don’ts Tips and tricks Open discussion/questions 2
Do’s and Don’ts
Packet reception Do NOT keep the packet pointers received from pcap_next_ex pcap_loop pcap_dispatch pcap_next in your own data structures. They are valid only up to the next call to pcap_next_ex.  Copy the packets if needed. 4
Packet dissection Packets can be truncated.  Be savvy when dissecting packets, check boundaries. If you receive a 30 bytes IP packet, the IP header is truncated! Do NOT assume that the headers have a fixed length! The IP header is 20 bytes when there are no options Compute the header length properly IP header Ethernet header IP options L4 protocol 14 bytes 20 bytes 0 or more bytes 5
Data link types Do NOT assume that the link type is Ethernet (DLT_EN10MB). Check the link type with pcap_datalink In case of wireless (AirPcap), three possible encapsulations Bare 802.11 (no meta-information) Per-Packet Information (PPI) Radiotap 6
Packet API Do NOT use it. No longer documented (it was a mistake) It can change between releases Do NOT access the npf.sys driver directly IOCTLs change over time Use the pcap API 7
WinPcap installation Do NOT create your custom WinPcap installer. It works most of the times on Windows XP x86. What about Vista x64 or NT4? It corrupts any existing installation. Debugging installation issues is a major pain. Solutions Official WinPcap installer. WinPcap Professional. 8
WinPcap and services You can use WinPcap in a service. You MUST call any WinPcap function after you have notified the SCM that the service is started. Alternatively, put “nm” and “npf” as service dependencies using ChangeServiceConfigwhen installing the service VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) {    //    // perform any initialization here // DO NOT CALL WINPCAP HERE    //  SetServiceStatus( ....SERVICE_RUNNING...);    //    // Service is now running, perform work until shutdown // Start using WinPcap here    // } 9
Kernel buffers Do NOT use large kernel buffers. It’s a cache for traffic spikes or app processing slowdowns. Kernel memory is a precious resource. 4-8 MB is ok in most cases (even at 1Gbps). Optimize your processing code! 10
Tips and tricks
Multiple devices support You can open the same device multiple times Within the same process. From the same or different threads. Each instance uses its own capture buffer and filter. Packets are replicated among instances. Be careful with pcap_compile. It’s not thread safe (as of WinPcap4.1beta5). Future versions will fix the issue. Use a critical section to protect the calls to pcap_compile. 12
Dumping to disk Disks are generally slow. Dumping all the packets to disk without losses is not trivial on high speed links. Solutions Dump just the first n bytes of a packet (snaplen). Filter packets. Dedicated disks (not partitions!). RAID 0 (striping). 13
Use pcap_next_ex Why? It’s much easier to use. Especially to stop capture. Do notuse pcap_loop/pcap_dispatch/pcap_next They are less immediate to use. pcap_next_ex is blocking It respects the timeout set in pcap_open_live 14
Timestamps They are generated in software after The packet has been received by the NIC The NIC has notified the OS about available packets (interrupt coalescing) The NIC driver has processed the packet and notified NDIS about the packet The precision is in the order of tens of microseconds in the best case. Do not rely on timestamps for critical measurements. 15
Responsiveness vs. performance Packets are received by the app when the timeout elapses or at least mintocopy bytes are in the kernel driver buffer (whatever comes first) Small read timeouts can affect performance Small mintocopy values can affect performance Do you really need to get the packets as soon as they arrive? 16
Devpack samples Use them as a reference Header files to include (or not) LIB files How to open/close an adapter or capture packets from it 17
GUI applications The UI needs to be responsive while capturing. Use a separate thread to capture (or inject) packets. Use messages for inter-thread communication. SendMessage PostMessage Do NOT touch the UI in the capture thread! 18
Wireless capture  Most adapters (excluding AirPcap) do not support promiscuous/monitor mode It’s a limit of the hardware/NIC driver It’s not a limit of WinPcap Bug in WinPcap: it doesn’t detect lack of promiscuous support. Fixed in 4.1 betas. Ethernet “fake” frames. No management/control frames, no 802.11 headers. Vista native Wi-Fi drivers? Not really. 19
Privileges to run WinPcap Pretty weak security model Admin privileges are needed to Install WinPcap Start the driver at each reboot Change the driver start type to SERVICE_AUTO_START to have the driver started at boot time Once the driver is running, a standard user can capture/inject packets 20
WinPcap and .NET You need to create your own wrapper, or use an existing one No official wrappers No support for 3rd party ones Marshalling packet contents (without copies) is not trivial Some APIs (e.g. pcap_findalldevs) are not .NET friendly Use managed C++ to create your wrapper 21
Questions?

Weitere ähnliche Inhalte

Andere mochten auch

Ipc Policy Brief Re Mcss Fippa Act
Ipc Policy Brief Re Mcss Fippa ActIpc Policy Brief Re Mcss Fippa Act
Ipc Policy Brief Re Mcss Fippa ActROSEMARY CD
 
Network Security through IP Packet Filtering
Network Security through IP Packet FilteringNetwork Security through IP Packet Filtering
Network Security through IP Packet Filteringkarim baidar
 
Iptables fundamentals
Iptables fundamentalsIptables fundamentals
Iptables fundamentalsram_b17
 
Iptables Configuration
Iptables ConfigurationIptables Configuration
Iptables Configurationstom123
 

Andere mochten auch (7)

IT in arbitrage
IT in arbitrage IT in arbitrage
IT in arbitrage
 
Ipc Policy Brief Re Mcss Fippa Act
Ipc Policy Brief Re Mcss Fippa ActIpc Policy Brief Re Mcss Fippa Act
Ipc Policy Brief Re Mcss Fippa Act
 
Ip tables
Ip tablesIp tables
Ip tables
 
Network Security through IP Packet Filtering
Network Security through IP Packet FilteringNetwork Security through IP Packet Filtering
Network Security through IP Packet Filtering
 
Iptables fundamentals
Iptables fundamentalsIptables fundamentals
Iptables fundamentals
 
Iptables in linux
Iptables in linuxIptables in linux
Iptables in linux
 
Iptables Configuration
Iptables ConfigurationIptables Configuration
Iptables Configuration
 

Ähnlich wie Dt5 varenni win_pcapdosdonts

CAPI and OpenCAPI Hardware acceleration enablement
CAPI and OpenCAPI Hardware acceleration enablementCAPI and OpenCAPI Hardware acceleration enablement
CAPI and OpenCAPI Hardware acceleration enablementGanesan Narayanasamy
 
DPDK Integration: A Product's Journey - Roger B. Melton
DPDK Integration: A Product's Journey - Roger B. MeltonDPDK Integration: A Product's Journey - Roger B. Melton
DPDK Integration: A Product's Journey - Roger B. Meltonharryvanhaaren
 
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)Igalia
 
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docx
Lab Exercise #4 IPv4   Dr. Anne Kohnke  1  Obj.docxLab Exercise #4 IPv4   Dr. Anne Kohnke  1  Obj.docx
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docxsmile790243
 
Snabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterSnabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterIgalia
 
Snabb, a toolkit for building user-space network functions (ES.NOG 20)
Snabb, a toolkit for building user-space network functions (ES.NOG 20)Snabb, a toolkit for building user-space network functions (ES.NOG 20)
Snabb, a toolkit for building user-space network functions (ES.NOG 20)Igalia
 
Developping drivers on small machines
Developping drivers on small machinesDevelopping drivers on small machines
Developping drivers on small machinesAnne Nicolas
 
Stupid iptables tricks
Stupid iptables tricksStupid iptables tricks
Stupid iptables tricksJim MacLeod
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDKKernel TLV
 
The ifconfig Command
The ifconfig CommandThe ifconfig Command
The ifconfig CommandKevin OBrien
 
Packet Sniffer
Packet Sniffer Packet Sniffer
Packet Sniffer vilss
 
How to Use GSM/3G/4G in Embedded Linux Systems
How to Use GSM/3G/4G in Embedded Linux SystemsHow to Use GSM/3G/4G in Embedded Linux Systems
How to Use GSM/3G/4G in Embedded Linux SystemsToradex
 
PACKET Sniffer IMPLEMENTATION
PACKET Sniffer IMPLEMENTATIONPACKET Sniffer IMPLEMENTATION
PACKET Sniffer IMPLEMENTATIONGoutham Royal
 

Ähnlich wie Dt5 varenni win_pcapdosdonts (20)

CAPI and OpenCAPI Hardware acceleration enablement
CAPI and OpenCAPI Hardware acceleration enablementCAPI and OpenCAPI Hardware acceleration enablement
CAPI and OpenCAPI Hardware acceleration enablement
 
DPDK Integration: A Product's Journey - Roger B. Melton
DPDK Integration: A Product's Journey - Roger B. MeltonDPDK Integration: A Product's Journey - Roger B. Melton
DPDK Integration: A Product's Journey - Roger B. Melton
 
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)
D. Fast, Simple User-Space Network Functions with Snabb (RIPE 77)
 
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docx
Lab Exercise #4 IPv4   Dr. Anne Kohnke  1  Obj.docxLab Exercise #4 IPv4   Dr. Anne Kohnke  1  Obj.docx
Lab Exercise #4 IPv4 Dr. Anne Kohnke 1 Obj.docx
 
Using linux as_a_router
Using linux as_a_routerUsing linux as_a_router
Using linux as_a_router
 
Snabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporterSnabbflow: A Scalable IPFIX exporter
Snabbflow: A Scalable IPFIX exporter
 
Snabb, a toolkit for building user-space network functions (ES.NOG 20)
Snabb, a toolkit for building user-space network functions (ES.NOG 20)Snabb, a toolkit for building user-space network functions (ES.NOG 20)
Snabb, a toolkit for building user-space network functions (ES.NOG 20)
 
Firewall
FirewallFirewall
Firewall
 
Developping drivers on small machines
Developping drivers on small machinesDevelopping drivers on small machines
Developping drivers on small machines
 
Stupid iptables tricks
Stupid iptables tricksStupid iptables tricks
Stupid iptables tricks
 
100 M pps on PC.
100 M pps on PC.100 M pps on PC.
100 M pps on PC.
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
A new perspective on Network Visibility - RISK 2015
A new perspective on Network Visibility - RISK 2015A new perspective on Network Visibility - RISK 2015
A new perspective on Network Visibility - RISK 2015
 
Troubleshooting basic networks
Troubleshooting basic networksTroubleshooting basic networks
Troubleshooting basic networks
 
Linux Network Stack
Linux Network StackLinux Network Stack
Linux Network Stack
 
Os Selbak
Os SelbakOs Selbak
Os Selbak
 
The ifconfig Command
The ifconfig CommandThe ifconfig Command
The ifconfig Command
 
Packet Sniffer
Packet Sniffer Packet Sniffer
Packet Sniffer
 
How to Use GSM/3G/4G in Embedded Linux Systems
How to Use GSM/3G/4G in Embedded Linux SystemsHow to Use GSM/3G/4G in Embedded Linux Systems
How to Use GSM/3G/4G in Embedded Linux Systems
 
PACKET Sniffer IMPLEMENTATION
PACKET Sniffer IMPLEMENTATIONPACKET Sniffer IMPLEMENTATION
PACKET Sniffer IMPLEMENTATION
 

Mehr von Sunil Kumar

Basics of Cryptography
Basics of CryptographyBasics of Cryptography
Basics of CryptographySunil Kumar
 
3Es of Ransomware
3Es of Ransomware3Es of Ransomware
3Es of RansomwareSunil Kumar
 
Http2 Security Perspective
Http2 Security PerspectiveHttp2 Security Perspective
Http2 Security PerspectiveSunil Kumar
 
Memory forensics
Memory forensicsMemory forensics
Memory forensicsSunil Kumar
 
n|u Dharamsala Humla : Memory Forensic by Tenzin Chokden
n|u Dharamsala Humla : Memory Forensic by Tenzin Chokdenn|u Dharamsala Humla : Memory Forensic by Tenzin Chokden
n|u Dharamsala Humla : Memory Forensic by Tenzin ChokdenSunil Kumar
 
Nullcon 2011- Behaviour Analysis with DBI
Nullcon 2011- Behaviour Analysis with DBINullcon 2011- Behaviour Analysis with DBI
Nullcon 2011- Behaviour Analysis with DBISunil Kumar
 

Mehr von Sunil Kumar (6)

Basics of Cryptography
Basics of CryptographyBasics of Cryptography
Basics of Cryptography
 
3Es of Ransomware
3Es of Ransomware3Es of Ransomware
3Es of Ransomware
 
Http2 Security Perspective
Http2 Security PerspectiveHttp2 Security Perspective
Http2 Security Perspective
 
Memory forensics
Memory forensicsMemory forensics
Memory forensics
 
n|u Dharamsala Humla : Memory Forensic by Tenzin Chokden
n|u Dharamsala Humla : Memory Forensic by Tenzin Chokdenn|u Dharamsala Humla : Memory Forensic by Tenzin Chokden
n|u Dharamsala Humla : Memory Forensic by Tenzin Chokden
 
Nullcon 2011- Behaviour Analysis with DBI
Nullcon 2011- Behaviour Analysis with DBINullcon 2011- Behaviour Analysis with DBI
Nullcon 2011- Behaviour Analysis with DBI
 

Kürzlich hochgeladen

Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...itnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Kürzlich hochgeladen (20)

Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
Irene Moetsana-Moeng: Stakeholders in Cybersecurity: Collaborative Defence fo...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

Dt5 varenni win_pcapdosdonts

  • 1. WinPcap Do’s and Don’ts Wednesday, June 17th, 2009 GianlucaVarenni Senior Software Engineer | CACE Technologies, Inc. WinPcapProduct Manager gianluca.varenni@cacetech.com SHARKFEST'09 Stanford University June 15-18, 2009
  • 2. Agenda Do’s and Don’ts Tips and tricks Open discussion/questions 2
  • 4. Packet reception Do NOT keep the packet pointers received from pcap_next_ex pcap_loop pcap_dispatch pcap_next in your own data structures. They are valid only up to the next call to pcap_next_ex. Copy the packets if needed. 4
  • 5. Packet dissection Packets can be truncated. Be savvy when dissecting packets, check boundaries. If you receive a 30 bytes IP packet, the IP header is truncated! Do NOT assume that the headers have a fixed length! The IP header is 20 bytes when there are no options Compute the header length properly IP header Ethernet header IP options L4 protocol 14 bytes 20 bytes 0 or more bytes 5
  • 6. Data link types Do NOT assume that the link type is Ethernet (DLT_EN10MB). Check the link type with pcap_datalink In case of wireless (AirPcap), three possible encapsulations Bare 802.11 (no meta-information) Per-Packet Information (PPI) Radiotap 6
  • 7. Packet API Do NOT use it. No longer documented (it was a mistake) It can change between releases Do NOT access the npf.sys driver directly IOCTLs change over time Use the pcap API 7
  • 8. WinPcap installation Do NOT create your custom WinPcap installer. It works most of the times on Windows XP x86. What about Vista x64 or NT4? It corrupts any existing installation. Debugging installation issues is a major pain. Solutions Official WinPcap installer. WinPcap Professional. 8
  • 9. WinPcap and services You can use WinPcap in a service. You MUST call any WinPcap function after you have notified the SCM that the service is started. Alternatively, put “nm” and “npf” as service dependencies using ChangeServiceConfigwhen installing the service VOID ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) { // // perform any initialization here // DO NOT CALL WINPCAP HERE // SetServiceStatus( ....SERVICE_RUNNING...); // // Service is now running, perform work until shutdown // Start using WinPcap here // } 9
  • 10. Kernel buffers Do NOT use large kernel buffers. It’s a cache for traffic spikes or app processing slowdowns. Kernel memory is a precious resource. 4-8 MB is ok in most cases (even at 1Gbps). Optimize your processing code! 10
  • 12. Multiple devices support You can open the same device multiple times Within the same process. From the same or different threads. Each instance uses its own capture buffer and filter. Packets are replicated among instances. Be careful with pcap_compile. It’s not thread safe (as of WinPcap4.1beta5). Future versions will fix the issue. Use a critical section to protect the calls to pcap_compile. 12
  • 13. Dumping to disk Disks are generally slow. Dumping all the packets to disk without losses is not trivial on high speed links. Solutions Dump just the first n bytes of a packet (snaplen). Filter packets. Dedicated disks (not partitions!). RAID 0 (striping). 13
  • 14. Use pcap_next_ex Why? It’s much easier to use. Especially to stop capture. Do notuse pcap_loop/pcap_dispatch/pcap_next They are less immediate to use. pcap_next_ex is blocking It respects the timeout set in pcap_open_live 14
  • 15. Timestamps They are generated in software after The packet has been received by the NIC The NIC has notified the OS about available packets (interrupt coalescing) The NIC driver has processed the packet and notified NDIS about the packet The precision is in the order of tens of microseconds in the best case. Do not rely on timestamps for critical measurements. 15
  • 16. Responsiveness vs. performance Packets are received by the app when the timeout elapses or at least mintocopy bytes are in the kernel driver buffer (whatever comes first) Small read timeouts can affect performance Small mintocopy values can affect performance Do you really need to get the packets as soon as they arrive? 16
  • 17. Devpack samples Use them as a reference Header files to include (or not) LIB files How to open/close an adapter or capture packets from it 17
  • 18. GUI applications The UI needs to be responsive while capturing. Use a separate thread to capture (or inject) packets. Use messages for inter-thread communication. SendMessage PostMessage Do NOT touch the UI in the capture thread! 18
  • 19. Wireless capture Most adapters (excluding AirPcap) do not support promiscuous/monitor mode It’s a limit of the hardware/NIC driver It’s not a limit of WinPcap Bug in WinPcap: it doesn’t detect lack of promiscuous support. Fixed in 4.1 betas. Ethernet “fake” frames. No management/control frames, no 802.11 headers. Vista native Wi-Fi drivers? Not really. 19
  • 20. Privileges to run WinPcap Pretty weak security model Admin privileges are needed to Install WinPcap Start the driver at each reboot Change the driver start type to SERVICE_AUTO_START to have the driver started at boot time Once the driver is running, a standard user can capture/inject packets 20
  • 21. WinPcap and .NET You need to create your own wrapper, or use an existing one No official wrappers No support for 3rd party ones Marshalling packet contents (without copies) is not trivial Some APIs (e.g. pcap_findalldevs) are not .NET friendly Use managed C++ to create your wrapper 21