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

Develop #57

Merged
merged 42 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9c2874d
return feature to remove blank lines and comments
htrgouvea Feb 21, 2024
9e0144c
Merge branch 'main' of github.com:htrgouvea/zarn into develop
htrgouvea Mar 26, 2024
7cba4b3
add samples to perform tests
htrgouvea Mar 29, 2024
5dfc632
pushing some tools to help during debug tasks
htrgouvea Mar 29, 2024
22367a2
skip false positives - draft function
htrgouvea Mar 29, 2024
4e7dd58
improve taint analysis function
htrgouvea Mar 30, 2024
5c9a01d
drafting new rules
htrgouvea Apr 4, 2024
55c5ec4
update sarif output with new variables
htrgouvea Apr 4, 2024
7eda8ab
apply design pattern practices to a better code compreension
htrgouvea Apr 15, 2024
541eced
remove Data::Dumper
htrgouvea Apr 15, 2024
b871752
delete
htrgouvea Apr 15, 2024
73f1819
fixed sarif
htrgouvea Apr 15, 2024
f072c54
remove unecessary variables
htrgouvea Apr 16, 2024
4b3785a
resolve conflicts
htrgouvea Apr 16, 2024
eb9b4f9
remove old file
htrgouvea Apr 16, 2024
6af8614
remove samples
May 28, 2024
d7ef075
create some unit tests
htrgouvea Jun 1, 2024
dac1e88
update rules on linter
htrgouvea Jun 14, 2024
2c54236
resolv linter warnings
htrgouvea Jun 14, 2024
6b659e7
resolv linter warnings
htrgouvea Jun 14, 2024
1e68bd5
new module
htrgouvea Jun 14, 2024
1ba5f98
remove tools/
htrgouvea Jun 14, 2024
bef50af
tdy
htrgouvea Jul 21, 2024
5237223
Merge branch 'main' of github.com:htrgouvea/zarn into develop
htrgouvea Jul 21, 2024
19f2d83
update perltidyrc
htrgouvea Oct 10, 2024
f55041d
new line
htrgouvea Oct 10, 2024
36768ef
deleted tests/Sarif.t
htrgouvea Oct 10, 2024
f31bc27
remove blank lines
htrgouvea Oct 10, 2024
ccf020a
checking if the name of file that does exists
htrgouvea Oct 10, 2024
65b540f
fix(Source-to-Sink): handle empty token list in PPI find method (#55)
scriptprivate Dec 18, 2024
7edf65b
fix conflict
htrgouvea Dec 24, 2024
2774aa9
Merge branch 'main' into develop
htrgouvea Jan 4, 2025
c09fb12
update the license year
htrgouvea Jan 4, 2025
76767b1
feature/code-absence; fix missing filename (#54)
LvMalware Jan 4, 2025
363d846
Merge branch 'develop' of github.com:htrgouvea/zarn into develop
htrgouvea Jan 4, 2025
ad6ec77
draft rules
htrgouvea Jan 4, 2025
3d700ab
refact the usage of map to for
htrgouvea Jan 4, 2025
ed64ac7
update the type of each rule
htrgouvea Jan 4, 2025
fe2535b
update the documentation
htrgouvea Jan 4, 2025
eefd107
remove blank line
htrgouvea Jan 4, 2025
987dabe
remove blank line
htrgouvea Jan 4, 2025
e2743bf
fix code style
htrgouvea Jan 4, 2025
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
2 changes: 1 addition & 1 deletion LICENSE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ License
==============
The MIT License (MIT)

Copyright (c) 2023 - 2024 | Heitor Gouvêa.
Copyright (c) 2023 - 2025 | Heitor Gouvêa.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ $ perl zarn.pl --rules rules/quick-wins.yml --source ../nozaki --sarif report.sa
```yaml
rules:
- id: '0001'
type: presence
category: info
name: Debug module enabled
message: Debug modules can expose sensitive information and potentially create security vulnerabilities.
sample:
- Dumper
- id: '0002'
type: presence
category: vuln
name: Code Injection
message: Occur when untrusted data is executed as code, allowing attackers to run arbitrary commands on the server.
Expand All @@ -71,11 +73,34 @@ rules:
- exec
- qx
- id: '0003'
type: presence
category: vuln
name: Path Traversal
message: Occur when user input is not properly sanitized, allowing attackers to access files and directories outside of the intended directory structure.
sample:
- open
- id: '0004'
type: presence
category: vuln
name: Weak Criptography Algorithm
message: Weak algorithms like MD5 are susceptible to various attacks and should be avoided in favor of stronger alternatives to ensure the security of sensitive data.
sample:
- md5
- id: '0005'
type: presence
category: vuln
name: Weak Random Value Generator
message: Weak random value generators can lead to predictable values, which can be exploited by attackers to bypass security controls.
sample:
- rand
- id: '0006'
type: absence
category: warning
name: Error Suppression
message: Suppressing errors can make it difficult to identify and troubleshoot issues, potentially leading to security vulnerabilities.
sample:
- strict
- warnings
```

---
Expand Down
30 changes: 28 additions & 2 deletions lib/Zarn/Engine/Source_to_Sink.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,35 @@ package Zarn::Engine::Source_to_Sink {
'rules=s' => \$rules
);


if ($ast && $rules) {
my @absence = grep { $_ -> {type} && $_ -> {type} eq 'absence' } $rules -> @*;

for my $rule (@absence) {
my $category = $rule -> {category};
my $title = $rule -> {name};
my $message = $rule -> {message};

foreach my $token ($rule -> {sample} -> @*) {

if ($ast -> content() !~ m/$token/xms ) {
push @results, {
category => $category,
title => $title,
message => $message,
line_sink => 'n/a',
rowchar_sink => 'n/a',
line_source => 'n/a',
rowchar_source => 'n/a'
};
}
}
}

my @presence = grep { !($_ -> {type}) || $_ -> {type} eq 'presence' } $rules -> @*;

foreach my $token (@{$ast -> find('PPI::Token') || []}) {
foreach my $rule (@{$rules}) {
foreach my $rule (@presence) {
my @sample = $rule -> {sample} -> @*;
my $category = $rule -> {category};
my $title = $rule -> {name};
Expand Down Expand Up @@ -63,4 +89,4 @@ package Zarn::Engine::Source_to_Sink {
}
}

1;
1;
15 changes: 14 additions & 1 deletion rules/default.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
---
rules:
- id: '0001'
type: presence
category: info
name: Debug module enabled
message: Debug modules can expose sensitive information and potentially create security vulnerabilities.
sample:
- Dumper
- id: '0002'
type: presence
category: vuln
name: Code Injection
message: Occur when untrusted data is executed as code, allowing attackers to run arbitrary commands on the server.
Expand All @@ -16,20 +18,31 @@ rules:
- exec
- qx
- id: '0003'
type: presence
category: vuln
name: Path Traversal
message: Occur when user input is not properly sanitized, allowing attackers to access files and directories outside of the intended directory structure.
sample:
- open
- id: '0004'
type: presence
category: vuln
name: Weak Criptography Algorithm
message: Weak algorithms like MD5 are susceptible to various attacks and should be avoided in favor of stronger alternatives to ensure the security of sensitive data.
sample:
- md5
- id: '0005'
type: presence
category: vuln
name: Weak Random Value Generator
message: Weak random value generators can lead to predictable values, which can be exploited by attackers to bypass security controls.
sample:
- rand
- rand
- id: '0006'
type: absence
category: warning
name: Error Suppression
message: Suppressing errors can make it difficult to identify and troubleshoot issues, potentially leading to security vulnerabilities.
sample:
- strict
- warnings
76 changes: 74 additions & 2 deletions rules/prototype.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
---
rules:
- id: '0001'
- id: '0006'
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
- render
rules:
- id: '0012'
category: vuln
name: Command Injection
message: Command injection attacks are possible when an application passes unsafe user supplied data like form values, cookies, HTTP headers etc. to a system shell. In this attack, the attacker-supplied operating system commands are usually executed with the privileges of the vulnerable application.
sample:
- exec
- syscall
- open
- qx
- readpipe
- id: '0006'
category: vuln
name: Connection String Injection
message: A connection string injection attack can occur when dynamic string concatenation is used to build connection strings that are based on user input. If the string isn't validated and malicious text or characters not escaped, an attacker can potentially access sensitive data or other resources on the server.
sample:
- connect
- ora_login
- id: '0007'
category: vuln
name: LDAP Injection
message: LDAP Injection is an attack used to exploit web based applications that construct LDAP statements based on user input. When an application fails to properly sanitize user input, it's possible to modify LDAP statements using a local proxy. This could result in the execution of arbitrary commands such as granting permissions to unauthorized queries, and content modification inside the LDAP tree.
sample:
- search
- modify
- moddn
- add
- bind
- delete
- compare
- id: '0008'
category: vuln
name: XSS
message: Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user.
sample:
- print
- printf
- say
- echo
- header
- start_html
- end_html
- id: '0009'
category: vuln
name: Remote File Inclusion
message: This vulnerability allows an attacker to include a file, usually exploiting a "dynamic file inclusion" mechanisms implemented in the target application. The vulnerability occurs due to the use of user-supplied input without proper validation. this can lead to issues like - Code execution, Denial of Service, Sensitive Information Disclosure,etc.
sample:
- use
- require
- id: '0010'
category: vuln
name: Resource Injection
message: This attack consists of changing resource identifiers used by an application in order to perform a malicious task. When an application defines a resource type or location based on user input, such as a file name or port number, this data can be manipulated to execute or access different resources.
sample:
- socket
- id: '0011'
category: vuln
name: SQL Injection
message: A SQL injection attack consists of insertion or “injection” of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system.
sample:
- prepare
- execute
- bind_param
- do
- find
- create
- update
- ora_open
- ora_do
- ora_fetch
- select
- query
4 changes: 2 additions & 2 deletions zarn.pl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
);

if ( !$source ) {
print "\nZarn v0.1.0"

Check failure on line 30 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 30, column 9. See pages 208,278 of PBP.
. "\nCore Commands"
. "\n==============\n"
. "\tCommand Description\n"
Expand Down Expand Up @@ -55,8 +55,8 @@
]
);

if (@analysis) {
$analysis[0]->{'file'} = $file;
for (@analysis) {
$_->{file} = $file;
}

push @results, @analysis;
Expand All @@ -72,16 +72,16 @@
my $line_source = $result->{line_source};
my $rowchar_source = $result->{rowchar_source};

print

Check failure on line 75 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 75, column 9. See pages 208,278 of PBP.
"[$category] - FILE:$file \t Potential: $title. \t Dangerous function on line: $line_sink:$rowchar_sink \t Data point possibility controlled: $line_source:$rowchar_source\n";
}

if ($sarif) {
my $sarif_data = Zarn::Helper::Sarif->new(@results);

open( my $output, '>', $sarif ) or croak "Cannot open the $sarif file\n";

Check failure on line 82 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Builtin function called with parentheses at line 82, column 9. See page 13 of PBP.
print $output encode_json($sarif_data);

Check failure on line 83 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

File handle for "print" or "printf" is not braced at line 83, column 9. See page 217 of PBP.

Check failure on line 83 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Return value of flagged function ignored - print at line 83, column 9. See pages 208,278 of PBP.
close($output) or die "Error to close the file\n";

Check failure on line 84 in zarn.pl

View workflow job for this annotation

GitHub Actions / critic

Builtin function called with parentheses at line 84, column 9. See page 13 of PBP.
}

return 0;
Expand Down
Loading