Skip to content

Commit 12446b6

Browse files
committed
Merge pull request #55 from LTe/tools_check_updated
Tools check updated
2 parents e5437fa + 7b1d079 commit 12446b6

12 files changed

Lines changed: 323 additions & 0 deletions

File tree

lib/scanny.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative "scanny/report"
44
require_relative "scanny/runner"
55
require_relative "scanny/checks/check"
6+
require_relative "scanny/checks/helpers"
67

78
Dir[File.dirname(__FILE__) + "/scanny/checks/**/*_check.rb"].each do |file|
89
require file

lib/scanny/checks/helpers.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Scanny
2+
module Checks
3+
module Helpers
4+
def build_pattern_exec_command(command)
5+
command = command.to_s if command.is_a?(Symbol)
6+
result = command.inspect
7+
8+
<<-EOT
9+
SendWithArguments
10+
<
11+
name = :system | :exec,
12+
arguments = ActualArguments<
13+
array = [
14+
any*,
15+
StringLiteral<string *= #{result}>,
16+
any*
17+
]
18+
>
19+
>
20+
|
21+
ExecuteString<string *= #{result}>
22+
EOT
23+
end
24+
end
25+
end
26+
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module Scanny
2+
module Checks
3+
module SystemTools
4+
class GpgUsageCheck < Check
5+
include Scanny::Checks::Helpers
6+
7+
def pattern
8+
[
9+
pattern_gpg_class,
10+
pattern_gpg_method,
11+
build_pattern_exec_command('gpg')
12+
].join("|")
13+
end
14+
15+
def check(node)
16+
issue :info, warning_message, :cwe => 0
17+
end
18+
19+
private
20+
21+
def warning_message
22+
"Using gpg tool in the wrong way can lead to security problems"
23+
end
24+
25+
def pattern_gpg_class
26+
<<-EOT
27+
Send | SendWithArguments
28+
<
29+
receiver = ConstantAccess<
30+
name =
31+
:GPG |
32+
:Gpg |
33+
:GpgKey
34+
>
35+
>
36+
37+
EOT
38+
end
39+
40+
def pattern_gpg_method
41+
"Send | SendWithArguments<name = :gpg>"
42+
end
43+
end
44+
end
45+
end
46+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Scanny
2+
module Checks
3+
module SystemTools
4+
class SudoCheck < Check
5+
include Scanny::Checks::Helpers
6+
7+
def pattern
8+
build_pattern_exec_command('sudo')
9+
end
10+
11+
def check(node)
12+
issue :info, warning_message, :cwe => 0
13+
end
14+
15+
private
16+
17+
def warning_message
18+
"Using sudo can lead to the execution" +
19+
"of programs on root administrator rights"
20+
end
21+
end
22+
end
23+
end
24+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Scanny
2+
module Checks
3+
module SystemTools
4+
class TarCheck < Check
5+
include Scanny::Checks::Helpers
6+
7+
def pattern
8+
build_pattern_exec_command(/tar\s+/)
9+
end
10+
11+
def check(node)
12+
issue :medium, warning_message, :cwe => 88
13+
end
14+
15+
private
16+
17+
def warning_message
18+
"Tar command can execute dangerous operations on files" +
19+
"and can travel through directories"
20+
end
21+
end
22+
end
23+
end
24+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Scanny
2+
module Checks
3+
module SystemTools
4+
class TarCommandsCheck < Check
5+
include Scanny::Checks::Helpers
6+
7+
def pattern
8+
[
9+
build_pattern_exec_command(/tar.*\-\-to\-command/),
10+
build_pattern_exec_command(/tar.*\-\-rmt\-command/),
11+
build_pattern_exec_command(/tar.*\-\-rsh\-command/)
12+
].join("|")
13+
end
14+
15+
def check(node)
16+
issue :high, warning_message, :cwe => 88
17+
end
18+
19+
private
20+
21+
def warning_message
22+
"Tar command has an option that allows to run external programs"
23+
end
24+
end
25+
end
26+
end
27+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Scanny
2+
module Checks
3+
module SystemTools
4+
class UnzipCheck < Check
5+
include Scanny::Checks::Helpers
6+
7+
def pattern
8+
[
9+
build_pattern_exec_command(/unzip\s+[^(=|&)]/),
10+
build_pattern_exec_command(/unzip.*-:/)
11+
].join("|")
12+
end
13+
14+
def check(node)
15+
if Machete.matches?(node, build_pattern_exec_command(/unzip.*-:/))
16+
issue :high, warning_message, :cwe => [23, 88]
17+
elsif Machete.matches?(node, build_pattern_exec_command(/unzip\s+[^(=|&)]/))
18+
issue :medium, warning_message, :cwe => [23, 88]
19+
end
20+
end
21+
22+
private
23+
24+
def warning_message
25+
"Unzip option allows '../' in archived file path, dir traversal"
26+
end
27+
end
28+
end
29+
end
30+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require "spec_helper"
2+
3+
module Scanny::Checks::SystemTools
4+
describe GpgUsageCheck do
5+
before do
6+
@runner = Scanny::Runner.new(GpgUsageCheck.new)
7+
@message = "Using gpg tool in the wrong way can lead to security problems"
8+
@issue = issue(:info, @message, 0)
9+
end
10+
11+
it "reports \"GPG.method\" correctly" do
12+
@runner.should check("GPG.method").with_issue(@issue)
13+
end
14+
15+
it "reports \"GPG.method\" correctly" do
16+
@runner.should check("Gpg.method").with_issue(@issue)
17+
end
18+
19+
it "reports \"GPG.method\" correctly" do
20+
@runner.should check("GpgKey.method").with_issue(@issue)
21+
end
22+
23+
it "reports \"system('gpg --example-flag')\" correctly" do
24+
@runner.should check("system('gpg --example-flag')").with_issue(@issue)
25+
end
26+
27+
it "reports \"`gpg --example-flag`\" correctly" do
28+
@runner.should check("`gpg --example-flag`").with_issue(@issue)
29+
end
30+
end
31+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require "spec_helper"
2+
3+
module Scanny::Checks::SystemTools
4+
describe SudoCheck do
5+
before do
6+
@runner = Scanny::Runner.new(SudoCheck.new)
7+
@message = "Using sudo can lead to the execution" +
8+
"of programs on root administrator rights"
9+
@issue = issue(:info, @message, 0)
10+
end
11+
12+
it "reports \"system('sudo shutdown -h now')\" correctly" do
13+
@runner.should check("system('sudo shutdown -h now')").with_issue(@issue)
14+
end
15+
16+
it "reports \"exec('sudo shutdown -h now')\" correctly" do
17+
@runner.should check("exec('sudo shutdown -h now')").with_issue(@issue)
18+
end
19+
20+
it "reports \"`sudo shutdown -h now`\" correctly" do
21+
@runner.should check("`sudo shutdown -h now`").with_issue(@issue)
22+
end
23+
end
24+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "spec_helper"
2+
3+
module Scanny::Checks::SystemTools
4+
describe TarCheck do
5+
before do
6+
@runner = Scanny::Runner.new(TarCheck.new)
7+
@message = "Tar command can execute dangerous operations on files" +
8+
"and can travel through directories"
9+
@issue = issue(:medium, @message, 88)
10+
end
11+
12+
it "reports \"system('tar xvf archive.tar.gz')\" correctly" do
13+
@runner.should check("system('tar xvf archive.tar.gz')").with_issue(@issue)
14+
end
15+
16+
it "reports \"`tar xvf archive.tar.gz`\" correctly" do
17+
@runner.should check("`tar xvf archive.tar.gz`").with_issue(@issue)
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)