Thread Problem mit Perl Script am Raspberrypi (2 answers)
Opened by klaus1 at 2015-05-30 21:00

klaus1
 2015-05-30 21:00
#181218 #181218
User since
2015-05-30
1 article
BenutzerIn
[default_avatar]
Aktuell folgender Code:
more (3.8kb):
Code: (dl )
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
#!/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;
}


folgendes HTML zum Parsen:
more (5.5kb):
Code: (dl )
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<link rel="SHORTCUT ICON" href="/images/A1.ico">
<title>WLAN Box</title>
<link rel="stylesheet" type="text/css" href="/css/common.css" />
<link rel="stylesheet" type="text/css" href="/css/theme.css" />
<link rel='stylesheet' type='text/css' href='/css/login.css'/>

<script src="/js/jquery.tools.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script src='/js/hmac-sha256.js'></script>
<script src='/js/md5.js'></script>
<script src='/js/md5_crypt.js'></script>

</head>
<body>
<div id="header">
<img id="logo" src="/images/logo.gif" />
</div>

<!--START content-->
<div id="content">

<form name="form" action="/ui/login" method="post" onsubmit="login_onsubmit();">
<div id="loginPanelBox">
<div id="panelLogin" class="panel">
<label class="panel">
Login
</label>
<img class="panel" src="/images/Login16.png" />
<hr class="panel" />

<fieldset class="form">


<div class="formField" id="userName" help_tooltip="off">
<label for="userName">Benutzername:</label>
<input type="text" name="userName" value="admin" />

</div>

<div class="formField" id="origUserPwd">
<label for="origUserPwd">Kennwort:</label>
<input type="password" autocomplete="off" name="origUserPwd" value="" />

</div>

<div class="formField" id="languageBox" help_tooltip="off">
<label for="language">Sprache:</label>

<select name="language" onchange='language_reload();'>
<option value='EN'>English</option>
<option value='DE' selected>Deutsch</option>

</select>

</div>

</fieldset>

<ul class="links">

</ul>
<div class="buttons">
<input type="submit" name="login" onclick="return link_onclick(this);"
value="Login"/>
</div>
</div>


</div>

<input type="hidden" name="userPwd" />
<input type="hidden" name="nonce" value="34614602" />
<input type='hidden' name='code1' value='t9Nvoe64I34pP9' />
<input type='hidden' name='code3' value='JaNTzSgHbiQMV' />

</form>
<script>
document.form.userName.focus();
function login_onsubmit() {

document.form.origUserPwd.disabled = true;
document.form.userPwd.value = CryptoJS.HmacSHA256(document.form.origUserPwd.value, document.form.nonce.value);
}
function language_reload() {
var uname = $("input[name=userName]").val();
var upwd = $("input[name=origUserPwd]").val();
var lang = $("select[name=language]").val();
var url = "login/panel?lang=" + lang;
$.get(url, function(data) {
$("#loginPanelBox").html(data);
$("input[name=userName]").val(uname);
$("input[name=origUserPwd]").val(upwd);
$("select[name=language]").val(lang);
});
}
</script>
<!--content END-->
</div>
<div id="footer">
Copyright &copy; 2010-2014 ADB Broadband S.p.A.
</div>
</body>
</html>


folgendes ergebnis:
Code: (dl )
1
2
3
root@raspberrypi:~# perl wlan_off.pl
Can't call method "attr" on an undefined value at wlan_off.pl line 29.
HTML::TreeBuilder=HASH(0xcafe00)root@raspberrypi:~#


Frage: Hab ich hier auf meinem Raspberrypi ein falsches Modul instaliert, oder was genau ist hier das Problem ?
danke,
Last edited: 2015-05-31 10:48:43 +0200 (CEST)

View full thread Problem mit Perl Script am Raspberrypi