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

Version 1.0 #44

Merged
merged 8 commits into from
Apr 4, 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
4 changes: 2 additions & 2 deletions lib/Zarn/Sarif.pm
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ package Zarn::Sarif {
uri => $info -> {file}
},
region => {
startLine => $info -> {line},
startColumn => $info -> {rowchar}
startLine => $info -> {line_sink},
startColumn => $info -> {rowchar_sink}
}
}
}]
Expand Down
8 changes: 8 additions & 0 deletions rules/prototype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
rules:
- id: '0001'
category: vuln
name: Cross Site Scripting (XSS)
message: Occur when untrusted data is rendered as HTML without proper escaping, allowing attackers to execute malicious scripts in the context of the victim's browser.
sample:
- render
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];

Dismissed Show dismissed Hide dismissed
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);
Dismissed Show dismissed Hide dismissed
print Dumper($document);
}
}

main();