oakb has asked for the wisdom of the Perl Monks concerning the following question:
I manage many clients' firewalls, and regularly generate pcap packet trace files of traffic passing through these firewalls. I do a lot of searching, matching, and extracting of data from these files, and often use Net::TcpDumpLog to automate the process.
I find myself stymied, however, by HTML that has been optimized for download speed through the use of chunked Transfer-Encoding and gzip Content-Encoding. Since the text HTML has been turned into binary data, I can't automate the parsing process and systematically extract interesting information.
Is there a relatively simple way to decompress and decode this data so that it can be manipulated automatically in my program?
Here is what I have so far:
#!/usr/bin/perl use strict; use Net::TcpDumpLog; my $log = Net::TcpDumpLog->new(); $log->read( "/my/tracefile.pcap" ); my $maxindex = $log->maxindex(); my $gzip = 0; foreach my $index ( 0..$maxindex ) { my ( $length_orig, $length_incl, $drops, $seconds, $milliseconds ) + = $log->header( $index ); my $data = $log->data( $index ); if (( $data =~ /Transfer-Encoding: chunked/g ) && ( $data =~ /Co +ntent-Encoding: gzip/g )) { $gzip++; print $index + 1 . "\t$length_orig\t$length_incl\t$seconds\t$m +illiseconds\n"; print "\t$data\n\n"; } } print "$gzip chunked-gzip packets.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Extract chunked/gzip data from pcap file (OT: Regex Usage)
by AnomalousMonk (Archbishop) on Dec 28, 2009 at 15:12 UTC | |
by ikegami (Patriarch) on Dec 28, 2009 at 15:27 UTC | |
by oakb (Scribe) on Jan 04, 2010 at 16:04 UTC | |
|
Re: Extract chunked/gzip data from pcap file
by Anonymous Monk on Dec 28, 2009 at 09:04 UTC | |
by oakb (Scribe) on Dec 28, 2009 at 14:17 UTC | |
by Corion (Patriarch) on Dec 28, 2009 at 14:28 UTC | |
by oakb (Scribe) on Jan 04, 2010 at 16:19 UTC | |
by Corion (Patriarch) on Jan 04, 2010 at 16:22 UTC |