-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.pl
More file actions
executable file
·70 lines (57 loc) · 1.42 KB
/
Copy pathapi.pl
File metadata and controls
executable file
·70 lines (57 loc) · 1.42 KB
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
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI qw(param);
$ENV{PATH}='/usr/bin:/bin';
my $VERSION = '1.2';
sub read_exec {
my $result = "\nExecuted command:\t";
foreach my $o(@_) {
$result .= ' ' . $o;
}
$result .= "\n";
$result .= do {
local $/;
open my $cmd, '|-', @_ or die 'Error: unable to execute ' . $_[0];
<$cmd>;
};
return $result;
}
print "Content-type: text/plain\r\n\r\n";
my $cmd = '';
my $host = '';
my %tools = (
0 => [ '/bin/ping', '-c', '5', '-w', '5', '--' ],
1 => [ '/usr/bin/traceroute', '-m', '14', '-q', '1', '--' ],
2 => [ '/usr/bin/host', '--' ],
3 => [ '/usr/bin/dig', '+trace' ],
4 => [ '/usr/bin/whois', '--' ],
5 => [ '/usr/bin/host', '-t', 'NS', '--' ],
6 => [ '/usr/bin/mtr', '-u', '--report-wide', '--report-cycles', '10', '--' ]
);
$cmd = param('cmd');
$host = param('host');
if (!defined($cmd)) {
print "Error: missing cmd\n";
exit 0;
}
if ($cmd eq 'ip') {
print $ENV{'REMOTE_ADDR'};
exit 0;
}
if (!defined($host)) {
print "Error: missing host\n";
exit 0;
}
if ($cmd !~ /^[0-9]$/) {
print "Error: invalid cmd format\n";
exit 0;
}
if ($host !~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$|^[-a-z0-9_\.]+$/) {
print "Error: invalid host format\n";
exit 0;
}
# Get the tool array, and add the host to it, then execute the command with the provided parameters and return the result of the command
my @tool = @{$tools{$cmd}};
push(@tool, $host);
print read_exec(@tool);