Security Basics mailing list archives
timestamp request with perl..not sure
From: zaka rias <sciensez () yahoo com>
Date: Thu, 15 Sep 2005 04:44:05 +0100 (BST)
hi..
i read bout icmpush from ofir arkin's paper, and then
just for my curiosity i made a script with perl (icmp
time stamp request), it's working fine when i tried to
localhost, but i got an error when tried it to another
host, so i asked my friends to try this script into
their LAN, and they said this script's working fine in
their LAN.
but im just not so sure.. so i ask u guys to try this
script in your LAN..do u have any error messages?
(dont forget to turn on your packet analyzer)...
btw i sent this prob to perlmonks..
here's the script :
==========================================
use strict;
use Socket;
use constant ICMP_TS => 13;
use constant ICMP_STRUCT => "C2 n3 N3 A"; # Structure
of a minimal ICMP packet
use constant SUBCODE => 0; # No ICMP subcodefor ECHO
and ECHOREPLY
use constant ICMP_FLAGS => 0; # No special flags for
send or recv
use constant ICMP_PORT => 0; # No port with ICMP
use constant IOT => 0; #ICMP originate timestamp
use constant IRT => 0; #ICMP receive timestamp
use constant ITT => 0; #ICMP transmit timestamp
ping_icmp();
sub ping_icmp
{
my ($ip) = inet_aton('192.168.0.2');
my ($saddr, $checksum, $msg, $len_msg);
my $seq = 1;
my $pid = $$ & 0xffff;
$checksum = 0; # No checksum for starters
my $data= "";
$msg = pack(ICMP_STRUCT .
0,ICMP_TS,SUBCODE,$checksum,$pid,$seq,IOT,IRT,ITT,$data);
$checksum =checksum($msg);
$msg = pack(ICMP_STRUCT .
0,ICMP_TS,SUBCODE,$checksum,$pid,$seq,IOT,IRT,ITT,$data);
$len_msg = length($msg);
$saddr = sockaddr_in(ICMP_PORT, $ip);
socket(SOCK,PF_INET,SOCK_RAW,1);
send(SOCK,$msg,ICMP_FLAGS,$saddr);
}
sub checksum{
my ($msg) = @_;
my ($len_msg,$num_short,$short,$chk);
$len_msg = length($msg);
$num_short = int($len_msg / 2);
$chk = 0;
foreach $short (unpack("n$num_short", $msg)) {
$chk += $short;
}
$chk += (unpack("C", substr($msg, $len_msg - 1, 1))
<< 8) if $len_msg % 2;
$chk = ($chk >> 16) + ($chk & 0xffff); # Foldhigh
into low
return(~(($chk >> 16) + $chk) & 0xffff); # Again and
complement
}
===================================
sorry for my english...
thanks a lot, zak
Send instant messages to your online friends http://uk.messenger.yahoo.com
Current thread:
- timestamp request with perl..not sure zaka rias (Sep 15)
