-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSn0ffer-TCP.pl
131 lines (107 loc) · 2.96 KB
/
Sn0ffer-TCP.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env perl
# Project website:: http://snoffer.tad0.org
# Licence:: CC-NC-BY-SA
# TCP sniffer for Sn0ffer
# v0.5.1 - 01/07/2016 - some code cleaning and comments
# v0.5 - 04/07/2013 - new
# v0.4 - 05/05/2010 - tAd tad0.org
use strict;
use warnings;
use Getopt::Std;
use Net::PcapUtils;
use NetPacket::Ethernet;
use NetPacket::IP;
use NetPacket::TCP;
use IO::Socket::INET;
my $i=1;
my $data;
my $freq;
## Usage
sub Usage
{
my $prog = $0;
$prog =~ s/.*\///g;
print STDERR <<EOM;
Usage: $prog -i interface
-i: listening interface
-h: this help
EOM
exit(1) ;
}
## Arguments
my $args = {};
getopts('i:h', $args);
if (exists($args->{'h'})
|| (not exists($args->{'i'})))
{
Usage();
}
my $interface = $args->{'i'};
# Filtering, Device, ...
# You can use a Pcap style filtering rule
# Net::PcapUtils::loop(\&process_pkt, FILTER => 'not port 4444 and not port 4443 and not port 4442', DEV => $interface, PROMISC => 1,);
Net::PcapUtils::loop(\&process_pkt, FILTER => '', DEV => $interface, PROMISC => 1,);
sub process_pkt {
my ($user_data,$hdr,$pkt)=@_;
my $eth=NetPacket::Ethernet->decode($pkt);
if($eth->{type} == 2048){
my $ip=NetPacket::IP->decode($eth->{data});
if($ip->{proto} == 6){
my $tcp=NetPacket::TCP->decode($ip->{data});
if ($tcp->{dest_port}<10000){
# Print data informations into terminal
print "[TCP] $ip->{src_ip}($tcp->{src_port}) -> $ip->{dest_ip}($tcp->{dest_port}) - ";
$i++;
$freq=$tcp->{dest_port};
# Open a socket to PureData
my $Socket=new IO::Socket::INET->new(
PeerPort=>4444,
Proto=>'tcp',
PeerAddr=>'127.0.0.1',
LocalAddr => '127.0.0.1',
) or die "Can't bind : $@\n Is PureData running? ... \n";
# Send data to PureData
print "$freq Hz \n";
print $Socket $freq;
print $Socket ';';
close($Socket);
}
if ($tcp->{src_port}<1024){
# Print data informations into terminal
print "[TCP] $ip->{dest_ip}($tcp->{dest_port}) <- $ip->{src_ip}($tcp->{src_port}) - ";
$i++;
$freq=($tcp->{src_port});
# Open a socket to PureData
my $Socket=new IO::Socket::INET->new(
PeerPort=>4444,
Proto=>'tcp',
PeerAddr=>'127.0.0.1',
LocalAddr => '127.0.0.1',
) or die "Can't bind : $@\n Is PureData running? ... \n";
# Send data to PureData
print "$freq Hz \n";
print $Socket $freq;
print $Socket ';';
close($Socket)
}
if ($tcp->{src_port}>1024){
# Print data informations into terminal
print "[TCP] $ip->{dest_ip}($tcp->{dest_port}) <- $ip->{src_ip}($tcp->{src_port}) - ";
$i++;
$freq=($tcp->{src_port});
# Open a socket to PureData
my $Socket=new IO::Socket::INET->new(
PeerPort=>4454,
Proto=>'tcp',
PeerAddr=>'127.0.0.1',
LocalAddr => '127.0.0.1',
) or die "Can't bind : $@\n Is PureData running? ... \n";
# Send data to PureData
print "$freq Hz \n";
print $Socket $freq;
print $Socket ';';
close($Socket)
}
}
}
}