Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements on Taint Analysis flow #43

Merged
merged 6 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions lib/Zarn/AST.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use PPI::Find;
use PPI::Document;

our $VERSION = '0.0.2';
our $VERSION = '0.0.4';

sub new {
my ($self, $parameters) = @_;
Expand Down Expand Up @@ -36,12 +36,25 @@
# this is a draft source-to-sink function
if (defined $next_element && ref $next_element && $next_element -> content() =~ /[\$\@\%](\w+)/xms) {
# perform taint analyis
my $var_token = $document -> find_first (
sub { $_[1] -> isa("PPI::Token::Symbol") and $_[1] -> content eq "\$$1" }
my $var_token = $document -> find_first (
sub {
$_[1] -> isa("PPI::Token::Symbol") and
($_[1] ->content eq "\$$1" or $_[1] -> content eq "\@$1" or $_[1] -> content eq "\%$1")
}
);

if ($var_token && $var_token -> can("parent")) {

Check failure on line 46 in lib/Zarn/AST.pm

View workflow job for this annotation

GitHub Actions / critic

Code structure is deeply nested at line 46, column 29. Consider refactoring.
my @childrens = $var_token -> parent -> children;

if (grep { # verifyng if the variable is a fixed string or a number

Check failure on line 49 in lib/Zarn/AST.pm

View workflow job for this annotation

GitHub Actions / critic

Code structure is deeply nested at line 49, column 33. Consider refactoring.
$_ -> isa("PPI::Token::Quote::Double") ||
$_ -> isa("PPI::Token::Quote::Single") ||
$_ -> isa("PPI::Token::Number")
} @childrens) {
next;
}

if ((

Check failure on line 57 in lib/Zarn/AST.pm

View workflow job for this annotation

GitHub Actions / critic

Code structure is deeply nested at line 57, column 33. Consider refactoring.
$var_token -> parent -> isa("PPI::Token::Operator") ||
$var_token -> parent -> isa("PPI::Statement::Expression")
)) {
Expand Down
13 changes: 13 additions & 0 deletions samples/code-injection.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/perl

use 5.018;
use strict;
use warnings;

sub main {

Check failure on line 7 in samples/code-injection.pl

View workflow job for this annotation

GitHub Actions / critic

Subroutine "main" does not end with "return" at line 7, column 1. See page 197 of PBP.
my $name = $ARGV[0];

system ("echo Hello World! $name");
}

exit main();
13 changes: 13 additions & 0 deletions samples/false-positive.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/perl

use 5.018;
use strict;
use warnings;

sub main {

Check failure on line 7 in samples/false-positive.pl

View workflow job for this annotation

GitHub Actions / critic

Subroutine "main" does not end with "return" at line 7, column 1. See page 197 of PBP.
my $name = "Zarn";

system ("echo Hello World! $name");
}

exit main();
21 changes: 21 additions & 0 deletions tools/graph.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env perl

use 5.018;
use strict;
use warnings;
use Devel::Graph;

sub main {
my $file = $ARGV[0];

if ($file) {
my $grapher = Devel::Graph -> new();
my $decompose = $grapher -> decompose ($file);

print $decompose -> as_ascii();
}

return 0;
}

exit main();
18 changes: 18 additions & 0 deletions tools/view-ast.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env perl

use 5.030;
use strict;
use warnings;
use PPI;
use Data::Dumper;

sub main {

Check failure on line 9 in tools/view-ast.pl

View workflow job for this annotation

GitHub Actions / critic

Subroutine "main" does not end with "return" at line 9, column 1. See page 197 of PBP.
my $file = $ARGV[0];

if ($file) {
my $document = PPI::Document -> new($file);
print Dumper($document);
}
}

main();
Loading