shield_ast 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.idea/.gitignore +8 -0
- data/.idea/dictionaries/project.xml +7 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/shield_ast.iml +48 -0
- data/.idea/vcs.xml +6 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +12 -0
- data/exe/ast +7 -0
- data/lib/shield_ast/iac.rb +26 -0
- data/lib/shield_ast/runner.rb +32 -0
- data/lib/shield_ast/sast.rb +25 -0
- data/lib/shield_ast/sca.rb +220 -0
- data/lib/shield_ast/version.rb +5 -0
- data/lib/shield_ast.rb +237 -0
- data/sig/shield_ast.rbs +4 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: baa8585d940103a2ffa3e2b7ccd47166dd75d3caebd58b16031d814c1f9a9af1
|
4
|
+
data.tar.gz: 794fb75bf613ea453cc5628cddb7d37d43751f43d215619053958bec757069bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b9ca658a73fc85de6ef32f09a4525e8945e558ea52a00362b714ce26dc22162f81ecabd5684bf6e9aea92a51b70f6a0b1bcbad035d977d0eb467940a7339f7b8
|
7
|
+
data.tar.gz: fa30e723c35d87b199e79d7fad982dcb47ac868b04133e85216d6eb3023e902f9a6c2648cef2653118b58ff7b94ff84c55b05692030907a90b92ca58c1e1ae98
|
data/.idea/.gitignore
ADDED
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/shield_ast.iml" filepath="$PROJECT_DIR$/.idea/shield_ast.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.3, rbenv: 3.4.5) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.7.1, rbenv: 3.4.5) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="date (v3.4.1, rbenv: 3.4.5) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.2, rbenv: 3.4.5) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="erb (v5.0.2, rbenv: 3.4.5) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.1, rbenv: 3.4.5) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="irb (v1.15.2, rbenv: 3.4.5) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.13.2, rbenv: 3.4.5) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.5, rbenv: 3.4.5) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, rbenv: 3.4.5) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, rbenv: 3.4.5) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.3.9.0, rbenv: 3.4.5) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, rbenv: 3.4.5) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, rbenv: 3.4.5) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="prism (v1.4.0, rbenv: 3.4.5) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="psych (v5.2.6, rbenv: 3.4.5) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, rbenv: 3.4.5) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.4.5) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.3.0, rbenv: 3.4.5) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="rdoc (v6.14.2, rbenv: 3.4.5) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.11.0, rbenv: 3.4.5) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="reline (v0.6.2, rbenv: 3.4.5) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.1, rbenv: 3.4.5) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.5, rbenv: 3.4.5) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.5, rbenv: 3.4.5) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.5, rbenv: 3.4.5) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.4, rbenv: 3.4.5) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.79.1, rbenv: 3.4.5) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.46.0, rbenv: 3.4.5) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.4.5) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="stringio (v3.1.7, rbenv: 3.4.5) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.1.4, rbenv: 3.4.5) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.0.4, rbenv: 3.4.5) [gem]" level="application" />
|
47
|
+
</component>
|
48
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Jose Augusto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# Shield AST - Application Security Testing CLI
|
2
|
+
|
3
|
+
**Shield AST** is a powerful command-line tool for **Application Security Testing**, combining multiple open-source scanners into a single workflow. With `ast`, you can run **SAST** (Static Application Security Testing), **SCA** (Software Composition Analysis), and **IaC** (Infrastructure as Code) analysis quickly and automatically, helping you identify and fix vulnerabilities early in the development lifecycle.
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
## 📦 Requirements
|
8
|
+
|
9
|
+
- **Ruby** (version 3.0 or later) must be installed on your system.
|
10
|
+
You can check your Ruby version with:
|
11
|
+
```bash
|
12
|
+
ruby -v
|
13
|
+
```
|
14
|
+
If you don't have Ruby installed, follow the instructions at: [https://www.ruby-lang.org/en/documentation/installation/](https://www.ruby-lang.org/en/documentation/installation/)
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
## 📦 Installation
|
19
|
+
|
20
|
+
```bash
|
21
|
+
# Install the gem
|
22
|
+
gem install ast
|
23
|
+
```
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
## 🚀 Usage
|
28
|
+
|
29
|
+
```bash
|
30
|
+
ast [command] [options]
|
31
|
+
```
|
32
|
+
|
33
|
+
### Commands
|
34
|
+
- **`scan [path]`** – Scans a directory for vulnerabilities. Defaults to the current directory.
|
35
|
+
- **`report`** – Generates a detailed report from the last scan.
|
36
|
+
- **`help`** – Displays this help message.
|
37
|
+
|
38
|
+
### Options
|
39
|
+
- **`-s, --sast`** – Run SAST using [Semgrep](https://semgrep.dev).
|
40
|
+
- **`-c, --sca`** – Run SCA using [OSV Scanner](https://osv.dev).
|
41
|
+
- **`-i, --iac`** – Run IaC analysis using [Semgrep](https://semgrep.dev) with infrastructure rules.
|
42
|
+
- **`-o, --output`** – Specify the output format (`json`, `sarif`, `console`).
|
43
|
+
- **`-h, --help`** – Show this help message.
|
44
|
+
- **`--version`** – Show the AST version.
|
45
|
+
|
46
|
+
---
|
47
|
+
|
48
|
+
## 📌 Examples
|
49
|
+
|
50
|
+
```bash
|
51
|
+
# Scan the current directory for all types of vulnerabilities
|
52
|
+
ast scan
|
53
|
+
|
54
|
+
# Run only SAST and SCA on a specific project folder
|
55
|
+
ast scan /path/to/project --sast --sca
|
56
|
+
|
57
|
+
# Generate a report in SARIF format
|
58
|
+
ast report --output sarif
|
59
|
+
```
|
60
|
+
|
61
|
+
---
|
62
|
+
|
63
|
+
## 🛠 How It Works
|
64
|
+
|
65
|
+
AST integrates well-known open-source scanners into a single CLI tool:
|
66
|
+
- **SAST** – [Semgrep](https://semgrep.dev) for static code analysis
|
67
|
+
- **SCA** – [OSV Scanner](https://osv.dev) for dependency vulnerability scanning
|
68
|
+
- **IaC** – [Semgrep](https://semgrep.dev) rules for Infrastructure as Code
|
69
|
+
|
70
|
+
This unified approach streamlines security testing, enabling developers to catch security issues earlier in the development process.
|
71
|
+
|
72
|
+
---
|
73
|
+
|
74
|
+
## 📄 License
|
75
|
+
|
76
|
+
Distributed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
data/Rakefile
ADDED
data/exe/ast
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "English"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module ShieldAst
|
7
|
+
class IaC
|
8
|
+
def self.scan(path)
|
9
|
+
# Execute Semgrep with IaC-specific rulesets
|
10
|
+
cmd = "semgrep --config=r/terraform --config=r/kubernetes --config=r/docker --config=r/yaml --json --quiet #{path}"
|
11
|
+
output = `#{cmd}`
|
12
|
+
|
13
|
+
if $CHILD_STATUS.success? && !output.strip.empty?
|
14
|
+
begin
|
15
|
+
report = JSON.parse(output)
|
16
|
+
return { "results" => report["results"] || [] }
|
17
|
+
rescue JSON::ParserError
|
18
|
+
return { "results" => [] }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Fallback if semgrep fails
|
23
|
+
{ "results" => [] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "sast"
|
4
|
+
require_relative "sca"
|
5
|
+
require_relative "iac"
|
6
|
+
|
7
|
+
require "json"
|
8
|
+
|
9
|
+
module ShieldAst
|
10
|
+
class Runner
|
11
|
+
def self.run(options, path)
|
12
|
+
reports = {}
|
13
|
+
|
14
|
+
if options[:sast]
|
15
|
+
puts "🔍 Running SAST ..."
|
16
|
+
reports[:sast] = SAST.scan(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
if options[:sca]
|
20
|
+
puts "📦 Running SCA ..."
|
21
|
+
reports[:sca] = SCA.scan(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
if options[:iac]
|
25
|
+
puts "☁️ Running IaC ..."
|
26
|
+
reports[:iac] = IaC.scan(path)
|
27
|
+
end
|
28
|
+
|
29
|
+
reports
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/shield_ast/sast.rb
|
4
|
+
require "json"
|
5
|
+
require "open3"
|
6
|
+
|
7
|
+
module ShieldAst
|
8
|
+
# Runs SAST analysis using Semgrep.
|
9
|
+
class SAST
|
10
|
+
def self.scan(path)
|
11
|
+
cmd = ["semgrep", "scan", path, "--json", "--disable-version-check"]
|
12
|
+
stdout, stderr, status = Open3.capture3(*cmd)
|
13
|
+
|
14
|
+
if status.success?
|
15
|
+
JSON.parse(stdout)
|
16
|
+
else
|
17
|
+
warn "Semgrep SAST scan failed! Error: #{stderr}"
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
rescue JSON::ParserError => e
|
21
|
+
warn "Failed to parse Semgrep output: #{e.message}"
|
22
|
+
[]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module ShieldAst
|
6
|
+
class SCA
|
7
|
+
def self.scan(path)
|
8
|
+
puts "Scanning path: #{path}" if ENV["DEBUG"]
|
9
|
+
|
10
|
+
if scanner_available?
|
11
|
+
puts "OSV Scanner is available" if ENV["DEBUG"]
|
12
|
+
else
|
13
|
+
puts "OSV Scanner not found in PATH. Please install it first:"
|
14
|
+
puts "go install github.com/google/osv-scanner/cmd/osv-scanner@v1"
|
15
|
+
return { "results" => [] }
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
cmd = "osv-scanner scan --format json #{path}"
|
20
|
+
puts "Executing command: #{cmd}" if ENV["DEBUG"]
|
21
|
+
|
22
|
+
output = `#{cmd} 2>&1`
|
23
|
+
exit_code = $?.exitstatus
|
24
|
+
|
25
|
+
puts "Exit code: #{exit_code}" if ENV["DEBUG"]
|
26
|
+
puts "Output: #{output}" if ENV["DEBUG"]
|
27
|
+
|
28
|
+
# OSV Scanner exit codes:
|
29
|
+
# 0: No vulnerabilities found
|
30
|
+
# 1: Vulnerabilities found
|
31
|
+
# 1-126: Vulnerability result related errors
|
32
|
+
# 127: General error
|
33
|
+
# 128: No packages found
|
34
|
+
# 129-255: Non result related errors
|
35
|
+
|
36
|
+
case exit_code
|
37
|
+
when 0
|
38
|
+
{ "results" => [] } # No vulnerabilities
|
39
|
+
when 1
|
40
|
+
{ "results" => parse_json_output(output) } # Vulnerabilities found
|
41
|
+
when 1..126
|
42
|
+
# Vulnerability related errors, but try to parse results anyway
|
43
|
+
puts "OSV Scanner vulnerability error (exit code: #{exit_code})" if ENV["DEBUG"]
|
44
|
+
{ "results" => parse_json_output(output) }
|
45
|
+
when 127
|
46
|
+
# General error, but if we have JSON output, use it
|
47
|
+
if output.include?('{"results"')
|
48
|
+
puts "OSV Scanner completed with general error but has results" if ENV["DEBUG"]
|
49
|
+
{ "results" => parse_json_output(output) }
|
50
|
+
else
|
51
|
+
puts "OSV Scanner general error (exit code: #{exit_code})"
|
52
|
+
{ "results" => [] }
|
53
|
+
end
|
54
|
+
when 128
|
55
|
+
puts "OSV Scanner found no packages to scan" if ENV["DEBUG"]
|
56
|
+
{ "results" => [] }
|
57
|
+
else
|
58
|
+
puts "OSV Scanner non-result error (exit code: #{exit_code})"
|
59
|
+
{ "results" => [] }
|
60
|
+
end
|
61
|
+
rescue => e
|
62
|
+
puts "Error running OSV Scanner: #{e.message}"
|
63
|
+
{ "results" => [] }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.scanner_available?
|
68
|
+
result = system("osv-scanner scan --help > /dev/null 2>&1")
|
69
|
+
puts "Scanner availability check result: #{result}" if ENV["DEBUG"]
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.parse_json_output(output)
|
74
|
+
json_start = output.index("{")
|
75
|
+
return [] unless json_start
|
76
|
+
|
77
|
+
json_data = JSON.parse(output[json_start..-1])
|
78
|
+
convert_to_shield_format(json_data)
|
79
|
+
rescue JSON::ParserError
|
80
|
+
[]
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.convert_to_shield_format(osv_data)
|
84
|
+
results = []
|
85
|
+
scan_results = osv_data["results"] || []
|
86
|
+
|
87
|
+
scan_results.each do |scan_result|
|
88
|
+
packages = scan_result["packages"] || []
|
89
|
+
|
90
|
+
packages.each do |package_data|
|
91
|
+
vulnerabilities = package_data["vulnerabilities"] || []
|
92
|
+
|
93
|
+
vulnerabilities.each do |vuln|
|
94
|
+
results << build_shield_result(vuln, package_data)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
results
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.build_shield_result(vuln, package_data)
|
103
|
+
package_info = package_data["package"] || {}
|
104
|
+
package_name = package_info["name"] || "unknown"
|
105
|
+
package_version = package_info["version"] || "unknown"
|
106
|
+
ecosystem = package_info["ecosystem"] || "unknown"
|
107
|
+
|
108
|
+
vuln_id = vuln["id"] || "unknown"
|
109
|
+
summary = vuln["summary"] || vuln["details"] || "No description available"
|
110
|
+
|
111
|
+
severity = determine_severity(vuln, package_data)
|
112
|
+
file_path = determine_file_path(ecosystem)
|
113
|
+
|
114
|
+
# Extract fixed version info
|
115
|
+
fixed_version = extract_fixed_version(vuln)
|
116
|
+
|
117
|
+
{
|
118
|
+
"title" => "#{vuln_id}: #{package_name}",
|
119
|
+
"severity" => severity,
|
120
|
+
"file" => file_path,
|
121
|
+
"description" => summary,
|
122
|
+
"vulnerable_version" => package_version,
|
123
|
+
"fixed_version" => fixed_version,
|
124
|
+
"path" => file_path,
|
125
|
+
"start" => { "line" => 1 },
|
126
|
+
"extra" => {
|
127
|
+
"message" => "Vulnerable dependency: #{package_name} (#{package_version}) - #{vuln_id}",
|
128
|
+
"severity" => severity,
|
129
|
+
"metadata" => {
|
130
|
+
"category" => "security",
|
131
|
+
"subcategory" => "vulnerable-dependencies",
|
132
|
+
"vulnerability_id" => vuln_id,
|
133
|
+
"package" => {
|
134
|
+
"name" => package_name,
|
135
|
+
"ecosystem" => ecosystem,
|
136
|
+
"vulnerable_version" => package_version,
|
137
|
+
"fixed_version" => fixed_version
|
138
|
+
}
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.extract_fixed_version(vuln)
|
145
|
+
# Try to find fixed version in affected ranges
|
146
|
+
if vuln["affected"] && vuln["affected"].is_a?(Array)
|
147
|
+
vuln["affected"].each do |affected|
|
148
|
+
if affected["ranges"] && affected["ranges"].is_a?(Array)
|
149
|
+
affected["ranges"].each do |range|
|
150
|
+
if range["events"] && range["events"].is_a?(Array)
|
151
|
+
# Look for "fixed" events
|
152
|
+
fixed_event = range["events"].find { |event| event["fixed"] }
|
153
|
+
return fixed_event["fixed"] if fixed_event
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Also check database_specific for fixed version
|
159
|
+
if affected["database_specific"] && affected["database_specific"]["last_affected"]
|
160
|
+
return ">" + affected["database_specific"]["last_affected"]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# Fallback: check database_specific at root level
|
166
|
+
if vuln["database_specific"]
|
167
|
+
return vuln["database_specific"]["fixed_version"] if vuln["database_specific"]["fixed_version"]
|
168
|
+
end
|
169
|
+
|
170
|
+
"Not specified"
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.determine_severity(vuln, package_data)
|
174
|
+
# Check database_specific severity first
|
175
|
+
if vuln.dig("database_specific", "severity")
|
176
|
+
return map_severity(vuln["database_specific"]["severity"])
|
177
|
+
end
|
178
|
+
|
179
|
+
# Check groups max_severity
|
180
|
+
groups = package_data&.dig("groups") || []
|
181
|
+
max_severity = groups.first&.dig("max_severity")
|
182
|
+
return cvss_to_severity(max_severity.to_f) if max_severity
|
183
|
+
|
184
|
+
"WARNING" # Default
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.determine_file_path(ecosystem)
|
188
|
+
case ecosystem&.downcase
|
189
|
+
when "npm", "nodejs" then "package.json"
|
190
|
+
when "pip", "pypi" then "requirements.txt"
|
191
|
+
when "rubygems" then "Gemfile"
|
192
|
+
when "maven" then "pom.xml"
|
193
|
+
when "gradle" then "build.gradle"
|
194
|
+
when "composer" then "composer.json"
|
195
|
+
when "nuget" then "packages.config"
|
196
|
+
when "cargo" then "Cargo.toml"
|
197
|
+
when "go" then "go.mod"
|
198
|
+
else "dependencies"
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.map_severity(severity)
|
203
|
+
case severity&.to_s&.upcase
|
204
|
+
when "CRITICAL", "HIGH" then "ERROR"
|
205
|
+
when "MEDIUM", "MODERATE" then "WARNING"
|
206
|
+
when "LOW" then "INFO"
|
207
|
+
else "WARNING"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.cvss_to_severity(score)
|
212
|
+
case score
|
213
|
+
when 7.0..10.0 then "ERROR"
|
214
|
+
when 4.0..6.9 then "WARNING"
|
215
|
+
when 0.1..3.9 then "INFO"
|
216
|
+
else "WARNING"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
data/lib/shield_ast.rb
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "shield_ast/version"
|
4
|
+
require_relative "shield_ast/runner"
|
5
|
+
|
6
|
+
require "json"
|
7
|
+
|
8
|
+
# Main module for the Shield AST gem.
|
9
|
+
module ShieldAst
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
# Main class for the Shield AST command-line tool.
|
13
|
+
# Handles command-line argument parsing and delegates to the Runner.
|
14
|
+
class Main
|
15
|
+
def self.call(args)
|
16
|
+
options = parse_args(args)
|
17
|
+
handle_options(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
private_class_method def self.handle_options(options)
|
21
|
+
if options[:help]
|
22
|
+
show_help
|
23
|
+
elsif options[:version]
|
24
|
+
puts "Shield AST version #{ShieldAst::VERSION}"
|
25
|
+
elsif options[:command] == "scan"
|
26
|
+
run_scan(options)
|
27
|
+
elsif options[:command] == "report"
|
28
|
+
puts "Generating report... (not yet implemented)"
|
29
|
+
else
|
30
|
+
puts "Invalid command. Use 'ast help' for more information."
|
31
|
+
show_help
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private_class_method def self.run_scan(options)
|
36
|
+
path = options[:path] || Dir.pwd
|
37
|
+
options = apply_default_scanners(options)
|
38
|
+
|
39
|
+
puts "🚀 Starting scan ..."
|
40
|
+
start_time = Time.now
|
41
|
+
|
42
|
+
reports = Runner.run(options, path) || {}
|
43
|
+
|
44
|
+
end_time = Time.now
|
45
|
+
execution_time = end_time - start_time
|
46
|
+
|
47
|
+
display_reports(reports, execution_time)
|
48
|
+
end
|
49
|
+
|
50
|
+
private_class_method def self.apply_default_scanners(options)
|
51
|
+
options.tap do |o|
|
52
|
+
if !o[:sast] && !o[:sca] && !o[:iac]
|
53
|
+
o[:sast] = true
|
54
|
+
o[:sca] = true
|
55
|
+
o[:iac] = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private_class_method def self.display_reports(reports, execution_time)
|
61
|
+
total_issues = 0
|
62
|
+
|
63
|
+
reports.each do |type, report_data|
|
64
|
+
results = report_data["results"] || []
|
65
|
+
total_issues += results.length
|
66
|
+
|
67
|
+
next if results.empty?
|
68
|
+
|
69
|
+
puts "\n#{get_scan_icon(type)} #{type.to_s.upcase} (#{results.length} #{results.length == 1 ? "issue" : "issues"})"
|
70
|
+
puts "-" * 60
|
71
|
+
|
72
|
+
format_report(results, type)
|
73
|
+
end
|
74
|
+
|
75
|
+
puts "\n✅ Scan finished in: #{format_duration(execution_time)}"
|
76
|
+
|
77
|
+
if total_issues.zero?
|
78
|
+
puts "✅ No security issues found! Your code looks clean."
|
79
|
+
else
|
80
|
+
severity_summary = calculate_severity_summary(reports)
|
81
|
+
puts "📊 Total: #{total_issues} findings #{severity_summary}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private_class_method def self.format_report(results, scan_type)
|
86
|
+
results.each_with_index do |result, index|
|
87
|
+
if scan_type == :sca && has_sca_format?(result)
|
88
|
+
format_sca_result(result)
|
89
|
+
else
|
90
|
+
format_default_result(result)
|
91
|
+
end
|
92
|
+
puts "" if index < results.length - 1 # Add spacing between items, but not after last
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Helper methods for better formatting
|
97
|
+
private_class_method def self.get_severity_icon(severity)
|
98
|
+
case severity&.upcase
|
99
|
+
when "ERROR" then "🔴"
|
100
|
+
when "WARNING" then "🟡"
|
101
|
+
when "INFO" then "🔵"
|
102
|
+
else "⚪"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private_class_method def self.get_scan_icon(scan_type)
|
107
|
+
case scan_type
|
108
|
+
when :sast then "🔍"
|
109
|
+
when :sca then "📦"
|
110
|
+
when :iac then "☁️"
|
111
|
+
else "🛡️"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
private_class_method def self.extract_short_description(result)
|
116
|
+
description = result["extra"]["message"].gsub("\n", " ").strip
|
117
|
+
if description.length > 80
|
118
|
+
"#{description[0..80]}..."
|
119
|
+
else
|
120
|
+
description
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private_class_method def self.calculate_severity_summary(reports)
|
125
|
+
error_count = 0
|
126
|
+
warning_count = 0
|
127
|
+
info_count = 0
|
128
|
+
|
129
|
+
reports.each_value do |report_data|
|
130
|
+
(report_data["results"] || []).each do |result|
|
131
|
+
severity = result["severity"] || result.dig("extra", "severity")
|
132
|
+
case severity&.upcase
|
133
|
+
when "ERROR" then error_count += 1
|
134
|
+
when "WARNING" then warning_count += 1
|
135
|
+
when "INFO" then info_count += 1
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
parts = []
|
141
|
+
parts << "#{error_count} 🔴" if error_count.positive?
|
142
|
+
parts << "#{warning_count} 🟡" if warning_count.positive?
|
143
|
+
parts << "#{info_count} 🔵" if info_count.positive?
|
144
|
+
|
145
|
+
"(#{parts.join(", ")})"
|
146
|
+
end
|
147
|
+
|
148
|
+
private_class_method def self.format_duration(seconds)
|
149
|
+
if seconds < 1
|
150
|
+
"#{(seconds * 1000).round}ms"
|
151
|
+
elsif seconds < 60
|
152
|
+
"#{seconds.round(1)}s"
|
153
|
+
else
|
154
|
+
minutes = (seconds / 60).floor
|
155
|
+
remaining_seconds = (seconds % 60).round
|
156
|
+
"#{minutes}m #{remaining_seconds}s"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
private_class_method def self.has_sca_format?(result)
|
161
|
+
result.key?("title") && result.key?("description") &&
|
162
|
+
result.key?("vulnerable_version") && result.key?("fixed_version")
|
163
|
+
end
|
164
|
+
|
165
|
+
private_class_method def self.format_sca_result(result)
|
166
|
+
severity_icon = get_severity_icon(result['severity'])
|
167
|
+
puts " #{severity_icon} #{result["title"]} (#{result["vulnerable_version"]} → #{result["fixed_version"]})"
|
168
|
+
puts " 📁 #{result["file"]} | #{result["description"][0..80]}#{result["description"].length > 80 ? "..." : ""}"
|
169
|
+
end
|
170
|
+
|
171
|
+
private_class_method def self.format_default_result(result)
|
172
|
+
severity_icon = get_severity_icon(result["extra"]["severity"])
|
173
|
+
title = result["extra"]["message"].split(".")[0].strip
|
174
|
+
file_info = "#{File.basename(result["path"])}:#{result["start"]["line"]}"
|
175
|
+
|
176
|
+
puts " #{severity_icon} #{title}"
|
177
|
+
puts " 📁 #{file_info} | #{extract_short_description(result)}"
|
178
|
+
end
|
179
|
+
|
180
|
+
# Parses command-line arguments to build an options hash.
|
181
|
+
private_class_method def self.parse_args(args)
|
182
|
+
options = { command: nil, path: nil, sast: false, sca: false, iac: false, help: false, version: false }
|
183
|
+
|
184
|
+
args.each do |arg|
|
185
|
+
case arg
|
186
|
+
when "scan" then options[:command] = "scan"
|
187
|
+
when "report" then options[:command] = "report"
|
188
|
+
when "-s", "--sast" then options[:sast] = true
|
189
|
+
when "-c", "--sca" then options[:sca] = true
|
190
|
+
when "-i", "--iac" then options[:iac] = true
|
191
|
+
when "-h", "--help" then options[:help] = true
|
192
|
+
when "--version" then options[:version] = true
|
193
|
+
when /^[^-]/ then options[:path] = arg if options[:command] == "scan" && options[:path].nil?
|
194
|
+
end
|
195
|
+
end
|
196
|
+
options
|
197
|
+
end
|
198
|
+
|
199
|
+
# Displays the help message for the CLI tool.
|
200
|
+
private_class_method def self.show_help
|
201
|
+
puts <<~HELP
|
202
|
+
ast - A powerful command-line tool for Application Security Testing
|
203
|
+
|
204
|
+
Usage:
|
205
|
+
ast [command] [options]
|
206
|
+
|
207
|
+
Commands:
|
208
|
+
scan [path] Scans a directory for vulnerabilities. Defaults to the current directory.
|
209
|
+
report Generates a detailed report from the last scan.
|
210
|
+
help Shows this help message.
|
211
|
+
|
212
|
+
Options:
|
213
|
+
-s, --sast Run Static Application Security Testing (SAST) with Semgrep.
|
214
|
+
-c, --sca Run Software Composition Analysis (SCA) with OSV Scanner.
|
215
|
+
-i, --iac Run Infrastructure as Code (IaC) analysis with Semgrep.
|
216
|
+
-o, --output Specify the output format (e.g., json, sarif, console).
|
217
|
+
-h, --help Show this help message.
|
218
|
+
--version Show the ast version.
|
219
|
+
|
220
|
+
Examples:
|
221
|
+
# Scan the current directory for all types of vulnerabilities
|
222
|
+
ast scan
|
223
|
+
|
224
|
+
# Run only SAST and SCA on a specific project folder
|
225
|
+
ast scan /path/to/project --sast --sca
|
226
|
+
|
227
|
+
# Generate a report in SARIF format
|
228
|
+
ast report --output sarif
|
229
|
+
|
230
|
+
Description:
|
231
|
+
ast is an all-in-one command-line tool that automates security testing by
|
232
|
+
integrating popular open-source scanners for SAST, SCA, and IaC, helping you
|
233
|
+
find and fix vulnerabilities early in the development lifecycle.
|
234
|
+
HELP
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
data/sig/shield_ast.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shield_ast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jose Augusto
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
12
|
+
description: |-
|
13
|
+
Shield AST is an all-in-one command-line tool that automates security testing by integrating
|
14
|
+
popular open-source scanners for SAST, SCA, and IaC, helping you find and fix vulnerabilities
|
15
|
+
early in the development lifecycle.
|
16
|
+
email:
|
17
|
+
- joseaugusto.881@outlook.com
|
18
|
+
executables:
|
19
|
+
- ast
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".idea/.gitignore"
|
24
|
+
- ".idea/dictionaries/project.xml"
|
25
|
+
- ".idea/misc.xml"
|
26
|
+
- ".idea/modules.xml"
|
27
|
+
- ".idea/shield_ast.iml"
|
28
|
+
- ".idea/vcs.xml"
|
29
|
+
- CHANGELOG.md
|
30
|
+
- CODE_OF_CONDUCT.md
|
31
|
+
- LICENSE.txt
|
32
|
+
- README.md
|
33
|
+
- Rakefile
|
34
|
+
- exe/ast
|
35
|
+
- lib/shield_ast.rb
|
36
|
+
- lib/shield_ast/iac.rb
|
37
|
+
- lib/shield_ast/runner.rb
|
38
|
+
- lib/shield_ast/sast.rb
|
39
|
+
- lib/shield_ast/sca.rb
|
40
|
+
- lib/shield_ast/version.rb
|
41
|
+
- sig/shield_ast.rbs
|
42
|
+
homepage: https://github.com/JAugusto42/shield_ast
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata:
|
46
|
+
allowed_push_host: https://rubygems.org
|
47
|
+
homepage_uri: https://github.com/JAugusto42/shield_ast
|
48
|
+
source_code_uri: https://github.com/JAugusto42/shield_ast
|
49
|
+
changelog_uri: https://github.com/JAugusto42/shield_ast/blob/main/CHANGELOG.md
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 3.2.0
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.7.1
|
65
|
+
specification_version: 4
|
66
|
+
summary: A command-line tool for multi-scanner Application Security Testing.
|
67
|
+
test_files: []
|