line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# string::javascript Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::String::Javascript; |
7
|
2
|
|
|
2
|
|
757
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
8
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
10
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1494
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
eval => [ qw(js_code) ], |
20
|
|
|
|
|
|
|
deobfuscate => [ qw(js_code) ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
require_modules => { |
23
|
|
|
|
|
|
|
'JavaScript::V8' => [ ], |
24
|
|
|
|
|
|
|
'JavaScript::Beautifier' => [ qw(js_beautify) ], |
25
|
|
|
|
|
|
|
}, |
26
|
|
|
|
|
|
|
need_packages => { |
27
|
|
|
|
|
|
|
ubuntu => [ qw(libv8-dev) ], |
28
|
|
|
|
|
|
|
debian => [ qw(libv8-dev) ], |
29
|
|
|
|
|
|
|
kali => [ qw(libv8-dev) ], |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub eval { |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
my ($js) = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('eval', $js) or return; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
$@ = undef; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $context = JavaScript::V8::Context->new; |
43
|
0
|
0
|
0
|
|
|
|
if (defined($@) && ! defined($context)) { |
44
|
0
|
|
|
|
|
|
chomp($@); |
45
|
0
|
|
|
|
|
|
return $self->log->error("eval: cannot init V8 context: $@"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $r = $context->eval($js); |
49
|
0
|
0
|
0
|
|
|
|
if (defined($@) && ! defined($r)) { |
50
|
0
|
|
|
|
|
|
chomp($@); |
51
|
0
|
|
|
|
|
|
return $self->log->error("eval: cannot eval JS: $@"); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $r; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub deobfuscate { |
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
my ($js) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('deobfuscate', $js) or return; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$@ = undef; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $context = JavaScript::V8::Context->new; |
66
|
0
|
0
|
0
|
|
|
|
if (defined($@) && ! defined($context)) { |
67
|
0
|
|
|
|
|
|
chomp($@); |
68
|
0
|
|
|
|
|
|
return $self->log->error("deobfuscate: cannot init V8 context: $@"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $buf = ''; |
72
|
0
|
|
|
0
|
|
|
$context->bind_function(eval => sub { $buf .= join(' ', @_); }); |
|
0
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
|
|
$context->bind_function(alert => sub { $buf .= join(' ', @_); }); |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
0
|
|
|
$context->bind_function(ActiveXObject => sub { $buf .= join(' ', @_); }); |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
|
|
$context->bind_function(WScript => sub { $buf .= join(' ', @_); }); |
|
0
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Google V8 has no XMLHttpRequest nor network related functions. |
77
|
|
|
|
|
|
|
# We should replace it by NodeJS at some point. |
78
|
0
|
|
|
0
|
|
|
$context->bind_function(XMLHttpRequest => sub { $buf .= join(' ', @_); }); |
|
0
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $r = $context->eval($js); |
81
|
0
|
0
|
0
|
|
|
|
if (defined($@) && ! defined($r)) { |
82
|
0
|
|
|
|
|
|
chomp($@); |
83
|
0
|
|
|
|
|
|
return $self->log->error("deobfuscate: cannot eval JS: $@"); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $b = JavaScript::Beautifier::js_beautify($buf, { |
87
|
|
|
|
|
|
|
indent_size => 2, |
88
|
|
|
|
|
|
|
indent_character => ' ', |
89
|
|
|
|
|
|
|
}); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $b; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |