#!/usr/bin/perl # # use strict; use warnings; use HTML::TreeBuilder; use Digest::SHA qw (hmac_sha256_hex); use Crypt::PasswdMD5; use LWP::UserAgent; my $passwd = "xxxx"; my $html = HTML::TreeBuilder->new_from_url("http://10.0.0.138/ui/dboard"); print $html; my $nonce = $html->look_down( _tag => q{input}, type => q{hidden}, name => q{nonce} )->attr(q{value}); my $code1 = $html->look_down( _tag => q{input}, type => q{hidden}, name => q{code1} )->attr(q{value}); my $code2 = $html->look_down( _tag => q{input}, type => q{hidden}, name => q{code2} )->attr(q{value}); my $code3 = $html->look_down( _tag => q{input}, type => q{hidden}, name => q{code3} )->attr(q{value}); my $newpwd = hmac_sha256_hex( $passwd, $nonce ); #print "$nonce\n$code1\n$code2\n$code3\n\n"; #print "$newpwd\n"; #print calc_hash( $passwd, $code1, $nonce ), "\n"; #print calc_hash( $passwd, $code2, $nonce ), "\n"; #print calc_hash( $passwd, $code3, $nonce ), "\n\n"; my $ua = LWP::UserAgent->new(); $ua->cookie_jar( { file => "cookies.txt" } ); my $response = $ua->post( "http://10.0.0.138/ui/login", [ 'userName' => '>Telek0m', 'language' => 'DE', 'login' => 'login', 'userPwd' => $newpwd, 'nonce' => $nonce, 'code1' => calc_hash( $passwd, $code1, $nonce ), 'code2' => calc_hash( $passwd, $code2, $nonce ), 'code3' => calc_hash( $passwd, $code3, $nonce ) ] ); sleep 5; $response = $ua->get("http://10.0.0.138/ui/dboard?edit=wan&if=5"); my $content = $response->decoded_content(); print "$content\n"; my $recon = HTML::TreeBuilder->new_from_content($content); my $actionkey = $recon->look_down( _tag => q{input}, type => q{hidden}, name => q{action__key} )->attr(q{value}); #print "ActionKey=",$actionkey,"\n"; sleep 5; $response = $ua->post( "http://10.0.0.138/ui/dboard/html/wifi?edit=wifi&if=1", [ 'enable' => 'false', 'action__key' => $actionkey, 'apply' => 'Apply' ] ); sleep 20; $response = $ua->get("http://10.0.0.138/ui/logout"); sleep 1; sub calc_hash { my ( $passwd, $value, $nonce ) = @_; my $calculated = hmac_sha256_hex( unix_md5_crypt( $passwd, $value ), $nonce ); return $calculated; }