Skip to content

Instantly share code, notes, and snippets.

@hc0d3r
Created May 16, 2014 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hc0d3r/f1d9c3fa9d0f65bde845 to your computer and use it in GitHub Desktop.
Save hc0d3r/f1d9c3fa9d0f65bde845 to your computer and use it in GitHub Desktop.
Packet Sniffer using RAW_SOCK. By MMxM | http://hc0der.blogspot.com
#!/usr/bin/perl -w
# Sniffer Coded by MMxM
# This script picks up only incoming packets
# hc0der.blogspot.com
use strict;
use IO::Socket;
sub print_c { (ord($_[0]) >= 33 && ord($_[0]) <= 126) ? print $_[0] : print '.'; }
die("Must Run as root\n") if($>);
my $sniffer = new IO::Socket::INET->new( Type => SOCK_RAW ) || die($!);
my $x = 0;
my $j = 0;
print "\n[+] Running ...\n\n";
while(my $packet = <$sniffer>){
print "\n[+] Captured package:\n";
my @rr = unpack("(H2)*",$packet);
my $size = scalar(@rr);
print "\n0x0000: ";
my $aux = 0;
for(my $i=0;$i<$size;$i+=2){
print $rr[($i-1)].$rr[$i]." ";
$j++;
if($j >= 8){
for(my $f=$aux;$f<=$i;$f++){
my $p = pack("H*",$rr[$f]);
print_c $p;
}
$aux = $i+1;
$j = 0;
last if($aux >= $size);
$x++;
printf "\n0x%03d0: ", $x;
}
}
if($j!=0){
printf "\n%49s", "";
for(my $g=($aux);$g<$size;$g++){
my $p = pack("H*",$rr[$g]);
print_c $p;
}
}
$x = 0;
$j = 0;
print "\n\n[*] End\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment