-
Notifications
You must be signed in to change notification settings - Fork 1
/
smbfileanalyis.pl
executable file
·67 lines (53 loc) · 1.24 KB
/
smbfileanalyis.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
use CGI ':standard';
use GD::Graph::bars;
if (@ARGV != 1){
print("Need to give pcap file as arguement\n");
exit 1;
}
$pcap = $ARGV[0];
@files=`tshark -r \"$pcap\" -Tfields -e smb.file -e smb.data_len_low -Eseparator=# | sort `;
$current = trim($files[0]);
@cur = split(/\#/, $current);
$current = @cur[0];
$cnt = 0;
@data;
@dfiles;
@dfcnt;
foreach(@files){
$line = trim($_);
@factors = split(/\#/, $line);
if (trim($factors[1]) eq "" ){
$factors[1] = 0;
}
if ($current eq $factors[0]){
$result = $result + $factors[1];
# print ("Analysing $line, $factors[1] bytes, $cnt times\n");
$cnt = $cnt + 1;
}else{
print "|$current|$result|$cnt\n";
push(@dfiles, $current);
push(@dfcnt, $cnt);
$current = $factors[0];
$result = 0;
$cnt = 1;
$result = $result + $factors[1];
}
}
my @data = (\@dfiles,\@dfcnt);
my $mygraph = GD::Graph::bars->new(2048, 2048);
$mygraph->set(
title => 'SMB Files Transfers',
) or warn $mygraph->error;
$mygraph->set( x_labels_vertical => 1 );
my $myimage = $mygraph->plot(\@data) or die $mygraph->error;
open (MYFILE, '>>chart.png');
print MYFILE $myimage->png;
close (MYFILE);
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}