-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'open3' | ||
|
||
def test_calls(user_input) | ||
# ruleid: dangerous-exec | ||
exec("ls -lah #{user_input}") | ||
|
||
# ruleid: dangerous-exec | ||
Process.spawn([user_input, "smth"]) | ||
|
||
commands = "ls -lah /raz/dva" | ||
# ok: dangerous-exec | ||
system(commands) | ||
|
||
cmd_name = "sh" | ||
# ok: dangerous-exec | ||
Process.exec([cmd_name, "ls", "-la"]) | ||
# ok: dangerous-exec | ||
Open3.capture2({"FOO" => "BAR"}, [cmd_name, "smth"]) | ||
# ok: dangerous-exec | ||
system("ls -lah /tmp") | ||
# ok: dangerous-exec | ||
exec(["ls", "-lah", "/tmp"]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
rules: | ||
- id: dangerous-exec | ||
patterns: | ||
- pattern-either: | ||
- pattern: | | ||
$EXEC(...) | ||
- pattern-not: | | ||
$EXEC("...",...) | ||
- pattern-not: | | ||
$EXEC(["...",...],...) | ||
- pattern-not: | | ||
$EXEC({...},"...",...) | ||
- pattern-not: | | ||
$EXEC({...},["...",...],...) | ||
- metavariable-regex: | ||
metavariable: $EXEC | ||
regex: ^(system|exec|Process.exec|Process.spawn|Open3.capture2|Open3.capture2e|Open3.capture3|Open3.popen2|Open3.popen2e|Open3.popen3|IO.popen|Gem::Util.popen|PTY.spawn)$ | ||
message: | | ||
Detected non-static command inside $EXEC. Audit the input to '$EXEC'. | ||
If unverified user data can reach this call site, this is a code injection | ||
vulnerability. A malicious actor can inject a malicious script to execute | ||
arbitrary code. | ||
metadata: | ||
cwe: "CWE-94: Improper Control of Generation of Code ('Code Injection')" | ||
owasp: 'A1: Injection' | ||
severity: WARNING | ||
languages: [ruby] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ok:dangerous-open | ||
cmd = open("|date") | ||
print cmd.gets | ||
cmd.close | ||
|
||
filename = "testfile" | ||
# ok:dangerous-open | ||
open(filename) do |f| | ||
print f.gets | ||
end | ||
|
||
# ruleid:dangerous-open | ||
cmd = open("|%s" % user_input) | ||
print cmd.gets | ||
cmd.close | ||
|
||
# ruleid:dangerous-open | ||
cmd = open(Kernel::sprintf("|%s", user_input)) | ||
print cmd.gets | ||
cmd.close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
rules: | ||
- id: dangerous-open | ||
patterns: | ||
- pattern: | | ||
open($CMD,...) | ||
- pattern-not: | | ||
open("...",...) | ||
- metavariable-regex: | ||
metavariable: $CMD | ||
regex: '|' | ||
message: | | ||
Detected non-static command inside 'open'. Audit the input to 'open'. | ||
If unverified user data can reach this call site, this is a code injection | ||
vulnerability. A malicious actor can inject a malicious script to execute | ||
arbitrary code. | ||
metadata: | ||
cwe: "CWE-94: Improper Control of Generation of Code ('Code Injection')" | ||
owasp: 'A1: Injection' | ||
severity: WARNING | ||
languages: [ruby] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'open3' | ||
|
||
fname = "/usr/share/man/man1/ruby.1.gz" | ||
# ok:dangerous-open3-pipeline | ||
p Open3.pipeline(["zcat", fname], "nroff -man", "less") | ||
|
||
fname = "/usr/share/man/man1/ls.1.gz" | ||
# ok:dangerous-open3-pipeline | ||
Open3.pipeline(["zcat", fname], "nroff -man", "colcrt") | ||
|
||
# ok:dangerous-open3-pipeline | ||
Open3.pipeline("sort", "uniq -c", :in=>"names.txt", :out=>"count") | ||
|
||
r,w = IO.pipe | ||
w.print "ibase=14\n10\n" | ||
# ok:dangerous-open3-pipeline | ||
Open3.pipeline("bc", "tee /dev/tty", :in=>r, :out=>w) | ||
|
||
pdf_file = "paper.pdf" | ||
# ruleid:dangerous-open3-pipeline | ||
Open3.pipeline(["pdftops", pdf_file, "-"], ["lpr", "-P#{user_input}"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
rules: | ||
- id: dangerous-open3-pipeline | ||
patterns: | ||
- pattern: | | ||
Open3.$PIPE(...) | ||
- pattern-not: | | ||
Open3.$PIPE(...,"...",...) | ||
- metavariable-regex: | ||
metavariable: $PIPE | ||
regex: ^(pipeline|pipeline_r|pipeline_rw|pipeline_start|pipeline_w)$ | ||
message: | | ||
Detected non-static command inside $PIPE. Audit the input to '$PIPE'. | ||
If unverified user data can reach this call site, this is a code injection | ||
vulnerability. A malicious actor can inject a malicious script to execute | ||
arbitrary code. | ||
metadata: | ||
cwe: "CWE-94: Improper Control of Generation of Code ('Code Injection')" | ||
owasp: 'A1: Injection' | ||
severity: WARNING | ||
languages: [ruby] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test | ||
# ruleid:dangerous-syscall | ||
syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
rules: | ||
- id: dangerous-syscall | ||
pattern: | | ||
syscall | ||
message: | | ||
'syscall' is essentially unsafe and unportable. The DL (https://apidock.com/ruby/Fiddle) library is preferred for safer and a bit more portable programming. | ||
metadata: | ||
cwe: "CWE-94: Improper Control of Generation of Code ('Code Injection')" | ||
owasp: 'A1: Injection' | ||
severity: WARNING | ||
languages: [ruby] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters