annotate glang-galaxy-conf/snippets/perl_snippet_file.pl @ 2:8947fca5f715 draft default tip

Uploaded
author ktnyt
date Fri, 26 Jun 2015 05:21:44 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
1 #!/usr/bin/env perl
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
2 use warnings;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
3
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
4 my $scriptname = shift;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
5 my $outname = shift;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
6 open SCR, "<", $scriptname;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
7 open OUT, ">", $outname;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
8 open STDOUT, ">", shift;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
9 open STDERR, ">", shift;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
10
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
11 my $open = "";
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
12 my @files;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
13 for(my $i = 0; @ARGV; $i++) {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
14 my $fn = shift;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
15 push @files, $fn;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
16 $open .= qq(open IN$i, "<", "$fn";\n);
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
17 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
18
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
19 my $script = join("", <SCR>);
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
20
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
21 if($script =~ /(open)|(system)|(`.+`)|([$@%]ENV)/smg) {
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
22 printf(STDERR "Found vulnerable code (open, system, backticks) in given script.");
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
23 exit(1);
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
24 }
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
25
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
26 eval("$open$script");
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
27
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
28 close SCR;
8947fca5f715 Uploaded
ktnyt
parents:
diff changeset
29 close OUT;