omamori 0.1.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/Gemfile +9 -0
- data/Gemfile.lock +97 -0
- data/LICENSE +21 -0
- data/README.md +172 -0
- data/README_ja.md +175 -0
- data/demo/ai_analysis_vulnerability.rb +28 -0
- data/demo/csrf_vulnerability.rb +31 -0
- data/demo/eval_vulnerability.rb +29 -0
- data/demo/idor_vulnerability.rb +39 -0
- data/demo/insecure_cookie_vulnerability.rb +25 -0
- data/demo/open_redirect_vulnerability.rb +22 -0
- data/demo/static_analysis_vulnerability.rb +18 -0
- data/demo/xss_vulnerability.rb +21 -0
- data/exe/omamori +16 -0
- data/lib/omamori/ai_analysis_engine/diff_splitter.rb +62 -0
- data/lib/omamori/ai_analysis_engine/gemini_client.rb +70 -0
- data/lib/omamori/ai_analysis_engine/prompt_manager.rb +76 -0
- data/lib/omamori/config.rb +144 -0
- data/lib/omamori/core_runner.rb +431 -0
- data/lib/omamori/report_generator/console_formatter.rb +132 -0
- data/lib/omamori/report_generator/html_formatter.rb +31 -0
- data/lib/omamori/report_generator/json_formatter.rb +19 -0
- data/lib/omamori/report_generator/report_template.erb +104 -0
- data/lib/omamori/static_analysers/brakeman_runner.rb +51 -0
- data/lib/omamori/static_analysers/bundler_audit_runner.rb +53 -0
- data/lib/omamori/version.rb +5 -0
- data/lib/omamori.rb +16 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98648919f99277d6023e0d6639b4d3c012b5efb901b8a7db485c1333470f9ff8
|
4
|
+
data.tar.gz: 943da793baa121c246f48083ee4630bc881c70209e4e5e0a73dd3342d63ee690
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 763f89ef7db133c5871fe8cdecb712df7ba881f754e2fb815b1f64622ff1974711c81316f06a92734232f2c3753403e0f2508146cff73aba87f07926b8a49a40
|
7
|
+
data.tar.gz: 3f0a079cd48d064ae1dc383948de694b2afcfbea51823042bec387e164e4f7dfcbe7aca373948c72b8568c1f3f1941f019ee5822f431776b28089b6adda1727a
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omamori (0.1.0)
|
5
|
+
colorize (~> 0.8)
|
6
|
+
dotenv (~> 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.3)
|
12
|
+
brakeman (7.0.2)
|
13
|
+
racc
|
14
|
+
bundler-audit (0.9.2)
|
15
|
+
bundler (>= 1.2.0, < 3)
|
16
|
+
thor (~> 1.0)
|
17
|
+
colorize (0.8.1)
|
18
|
+
diff-lcs (1.6.1)
|
19
|
+
dotenv (2.8.1)
|
20
|
+
faraday (2.13.1)
|
21
|
+
faraday-net_http (>= 2.0, < 3.5)
|
22
|
+
json
|
23
|
+
logger
|
24
|
+
faraday-multipart (1.1.0)
|
25
|
+
multipart-post (~> 2.0)
|
26
|
+
faraday-net_http (3.4.0)
|
27
|
+
net-http (>= 0.5.0)
|
28
|
+
json (2.11.3)
|
29
|
+
language_server-protocol (3.17.0.4)
|
30
|
+
lint_roller (1.1.0)
|
31
|
+
logger (1.7.0)
|
32
|
+
multipart-post (2.4.1)
|
33
|
+
net-http (0.6.0)
|
34
|
+
uri
|
35
|
+
parallel (1.27.0)
|
36
|
+
parser (3.3.8.0)
|
37
|
+
ast (~> 2.4.1)
|
38
|
+
racc
|
39
|
+
prism (1.4.0)
|
40
|
+
racc (1.8.1)
|
41
|
+
rainbow (3.1.1)
|
42
|
+
rake (13.2.1)
|
43
|
+
regexp_parser (2.10.0)
|
44
|
+
rspec (3.13.0)
|
45
|
+
rspec-core (~> 3.13.0)
|
46
|
+
rspec-expectations (~> 3.13.0)
|
47
|
+
rspec-mocks (~> 3.13.0)
|
48
|
+
rspec-core (3.13.3)
|
49
|
+
rspec-support (~> 3.13.0)
|
50
|
+
rspec-expectations (3.13.3)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.13.0)
|
53
|
+
rspec-mocks (3.13.2)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.13.0)
|
56
|
+
rspec-support (3.13.2)
|
57
|
+
rubocop (1.75.3)
|
58
|
+
json (~> 2.3)
|
59
|
+
language_server-protocol (~> 3.17.0.2)
|
60
|
+
lint_roller (~> 1.1.0)
|
61
|
+
parallel (~> 1.10)
|
62
|
+
parser (>= 3.3.0.2)
|
63
|
+
rainbow (>= 2.2.2, < 4.0)
|
64
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
65
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
68
|
+
rubocop-ast (1.44.1)
|
69
|
+
parser (>= 3.3.7.2)
|
70
|
+
prism (~> 1.4)
|
71
|
+
ruby-gemini-api (0.1.0)
|
72
|
+
faraday (~> 2.0)
|
73
|
+
faraday-multipart (~> 1.0)
|
74
|
+
json (~> 2.0)
|
75
|
+
ruby-progressbar (1.13.0)
|
76
|
+
thor (1.3.2)
|
77
|
+
unicode-display_width (3.1.4)
|
78
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
79
|
+
unicode-emoji (4.0.4)
|
80
|
+
uri (1.0.3)
|
81
|
+
|
82
|
+
PLATFORMS
|
83
|
+
ruby
|
84
|
+
x86_64-linux
|
85
|
+
|
86
|
+
DEPENDENCIES
|
87
|
+
brakeman (~> 7.0)
|
88
|
+
bundler (~> 2.0)
|
89
|
+
bundler-audit (~> 0.9.2)
|
90
|
+
omamori!
|
91
|
+
rake (~> 13.0)
|
92
|
+
rspec (~> 3.0)
|
93
|
+
rubocop (~> 1.0)
|
94
|
+
ruby-gemini-api (~> 0.1.0)
|
95
|
+
|
96
|
+
BUNDLED WITH
|
97
|
+
2.5.17
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 rira
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
[README(日本語)](https://github.com/rira100000000/omamori/blob/main/README_ja.md)
|
2
|
+
# Omamori Gem
|
3
|
+
|
4
|
+
Omamori is a Ruby gem designed to detect potential security vulnerabilities in Ruby code and its dependencies.
|
5
|
+
It aims to diagnose common vulnerabilities often introduced by beginner programmers.
|
6
|
+
By combining static analysis tools with AI-powered code analysis, Omamori provides flexible diagnostic capabilities.
|
7
|
+
|
8
|
+
However, please note that this gem is merely a "protective charm" and does not guarantee the safety of your programs.
|
9
|
+
It might help prevent vulnerabilities that could occur even after human review.
|
10
|
+
|
11
|
+
Caution:
|
12
|
+
AI analysis can uncover vulnerabilities that static analysis alone might miss, but the accuracy of diagnostics may vary depending on the AI model’s "mood."
|
13
|
+
Running the analysis multiple times may help reduce false negatives.
|
14
|
+
|
15
|
+
|
16
|
+
## Features
|
17
|
+
|
18
|
+
- Scan staged changes (`git diff --staged`) or the entire codebase for security risks.
|
19
|
+
- Integrates with static analysis tools like Brakeman and Bundler-Audit.
|
20
|
+
- Utilizes the Gemini API for advanced code analysis to detect vulnerabilities.
|
21
|
+
- Supports multiple report formats (console, HTML, JSON).
|
22
|
+
- Configurable via a `.omamorirc` file.
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'omamori'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
```bash
|
35
|
+
bundle install
|
36
|
+
```
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
gem install omamori
|
42
|
+
```
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
### Initialization
|
47
|
+
|
48
|
+
To generate an initial configuration file (`.omamorirc`), run:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
omamori init
|
52
|
+
```
|
53
|
+
|
54
|
+
Edit the generated `.omamorirc` file to configure your Gemini API key, preferred model, checks to perform, and other settings.
|
55
|
+
|
56
|
+
### Scanning
|
57
|
+
|
58
|
+
Scan staged changes (default):
|
59
|
+
|
60
|
+
```bash
|
61
|
+
omamori scan
|
62
|
+
```
|
63
|
+
|
64
|
+
Scan the entire codebase:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
omamori scan --all
|
68
|
+
```
|
69
|
+
|
70
|
+
Specify output format (console, html, json):
|
71
|
+
|
72
|
+
```bash
|
73
|
+
bundle exec omamori scan --format html
|
74
|
+
bundle exec omamori scan --all --format json
|
75
|
+
```
|
76
|
+
|
77
|
+
### AI Analysis Only
|
78
|
+
|
79
|
+
To perform only AI analysis without running static analysis tools, use the `--ai` option:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
omamori scan --ai
|
83
|
+
```
|
84
|
+
|
85
|
+
## Configuration
|
86
|
+
|
87
|
+
The `.omamorirc` file in the project root directory allows you to customize Omamori's behavior.
|
88
|
+
|
89
|
+
Here's a detailed breakdown of the configuration options:
|
90
|
+
|
91
|
+
```yaml
|
92
|
+
# .omamorirc
|
93
|
+
# Configuration file for omamori gem
|
94
|
+
|
95
|
+
# Gemini API Key (required for AI analysis)
|
96
|
+
# You can also set this via the GEMINI_API_KEY environment variable
|
97
|
+
api_key: YOUR_GEMINI_API_KEY # Replace with your actual API key
|
98
|
+
|
99
|
+
# Gemini Model to use (optional, default: gemini-1.5-pro-latest)
|
100
|
+
model: gemini-2.5-flash-preview-04-17
|
101
|
+
|
102
|
+
# Security checks to enable (optional, default: all implemented checks)
|
103
|
+
# checks:
|
104
|
+
# xss: true
|
105
|
+
# csrf: true
|
106
|
+
# idor: true
|
107
|
+
# ... # Add other checks as they become available
|
108
|
+
|
109
|
+
# Custom prompt templates (optional)
|
110
|
+
# prompt_templates:
|
111
|
+
# default: |
|
112
|
+
# Your custom prompt template here...
|
113
|
+
|
114
|
+
# Report output settings (optional)
|
115
|
+
# report:
|
116
|
+
# output_path: ./omamori_report # Output directory/prefix for html/json reports
|
117
|
+
# html_template: path/to/custom/template.erb # Custom HTML template
|
118
|
+
|
119
|
+
# Static analyser options (optional)
|
120
|
+
# static_analysers:
|
121
|
+
# brakeman:
|
122
|
+
# options: "--force" # Additional Brakeman options
|
123
|
+
# bundler_audit:
|
124
|
+
# options: "--quiet" # Additional Bundler-Audit options
|
125
|
+
|
126
|
+
# Language setting for AI analysis details (optional, default: en)
|
127
|
+
# language: ja
|
128
|
+
```
|
129
|
+
|
130
|
+
* `api_key`: Your API key for accessing the Gemini API. Can also be set via the `GEMINI_API_KEY` environment variable.
|
131
|
+
* `model`: The Gemini model to use for AI analysis. Defaults to `gemini-1.5-pro-latest`.
|
132
|
+
* `checks`: Configure which types of security checks to enable. By default, all implemented checks are enabled. You can selectively enable/disable checks here (e.g., `xss: true`, `csrf: false`).
|
133
|
+
* `prompt_templates`: Define custom prompt templates for AI analysis.
|
134
|
+
* `report`: Configure report output settings.
|
135
|
+
* `output_path`: The output directory or prefix for HTML and JSON reports.
|
136
|
+
* `html_template`: Path to a custom ERB template for HTML reports.
|
137
|
+
* `static_analysers`: Configure options for integrated static analysis tools.
|
138
|
+
* `brakeman`: Additional command-line options for Brakeman.
|
139
|
+
* `bundler_audit`: Additional command-line options for Bundler-Audit.
|
140
|
+
* `language`: Language setting for the details provided in AI analysis reports. Defaults to English (`en`).
|
141
|
+
|
142
|
+
## Demo Files
|
143
|
+
|
144
|
+
The `demo` directory contains example files with known vulnerabilities that can be used to demonstrate Omamori's capabilities.
|
145
|
+
|
146
|
+
To run Omamori on the demo files, you need to stage the changes in the `demo` directory. Since the `demo` directory might be ignored by git, follow these steps:
|
147
|
+
|
148
|
+
1. Ensure the `demo` directory is not ignored by git. If it is listed in your `.gitignore` file, remove or comment out the line.
|
149
|
+
2. Rename the `demo` directory to `demo_`:
|
150
|
+
```bash
|
151
|
+
mv demo demo_
|
152
|
+
```
|
153
|
+
3. Stage the `demo` directory again:
|
154
|
+
```bash
|
155
|
+
git add demo_
|
156
|
+
```
|
157
|
+
4. Now you can run Omamori on the staged demo files:
|
158
|
+
```bash
|
159
|
+
omamori scan
|
160
|
+
```
|
161
|
+
Or to scan all files in the demo directory (after staging them):
|
162
|
+
```bash
|
163
|
+
omamori scan --all
|
164
|
+
```
|
165
|
+
|
166
|
+
## Contributing
|
167
|
+
|
168
|
+
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
|
169
|
+
|
170
|
+
## License
|
171
|
+
|
172
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/README_ja.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
# Omamori Gem(お守りジェム)
|
2
|
+
|
3
|
+
Omamoriは、Rubyコードおよび依存関係に潜む潜在的なセキュリティ脆弱性を検出するRuby製のGemです。
|
4
|
+
初心者プログラマーが作りがちな脆弱性を診断することを目的としています。
|
5
|
+
静的解析ツールとAIによるコード解析を組み合わせることで柔軟な診断を可能とします。
|
6
|
+
|
7
|
+
ただし、このgemはあくまでも「お守り」であり、プログラムの安全を保証するものではありません。
|
8
|
+
人間がチェックした上で万が一に発生した脆弱性を、防いでくれる"かもしれません"。
|
9
|
+
|
10
|
+
注意:
|
11
|
+
AI解析は静的解析で診断できない脆弱性を発見することができますが、モデルの気分によって診断の精度にブレが生じやすいです。
|
12
|
+
複数回実行することで偽陰性を防ぐことができるかもしれません。
|
13
|
+
|
14
|
+
## 特徴
|
15
|
+
|
16
|
+
- ステージされた変更(`git diff --staged`)またはコードベース全体をスキャンしてセキュリティリスクを検出
|
17
|
+
- BrakemanやBundler-Auditなどの静的解析ツールと連携
|
18
|
+
- Gemini APIを活用し、AIによる高度なコード脆弱性検出
|
19
|
+
- 複数のレポート形式に対応(コンソール、HTML、JSON)
|
20
|
+
- `.omamorirc`ファイルによる柔軟な設定が可能
|
21
|
+
|
22
|
+
## インストール
|
23
|
+
|
24
|
+
アプリケーションのGemfileに以下を追加します:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'omamori'
|
28
|
+
```
|
29
|
+
|
30
|
+
その後、以下を実行します:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
bundle install
|
34
|
+
```
|
35
|
+
|
36
|
+
または、個別にインストールする場合は:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
gem install omamori
|
40
|
+
```
|
41
|
+
|
42
|
+
## 使い方
|
43
|
+
|
44
|
+
### 初期化
|
45
|
+
|
46
|
+
初期設定ファイル(`.omamorirc`)を生成するには、以下を実行します:
|
47
|
+
|
48
|
+
```bash
|
49
|
+
omamori init
|
50
|
+
```
|
51
|
+
|
52
|
+
生成された`.omamorirc`ファイルを編集して、Gemini APIキー、使用するモデル、実行するチェック項目などを設定します。
|
53
|
+
|
54
|
+
### スキャン
|
55
|
+
|
56
|
+
ステージされた変更をスキャン(デフォルト):
|
57
|
+
|
58
|
+
```bash
|
59
|
+
omamori scan
|
60
|
+
```
|
61
|
+
|
62
|
+
コードベース全体をスキャン:
|
63
|
+
|
64
|
+
```bash
|
65
|
+
omamori scan --all
|
66
|
+
```
|
67
|
+
|
68
|
+
出力形式を指定(コンソール、HTML、JSON):
|
69
|
+
|
70
|
+
```bash
|
71
|
+
bundle exec omamori scan --format html
|
72
|
+
bundle exec omamori scan --all --format json
|
73
|
+
```
|
74
|
+
|
75
|
+
### AI解析のみ実施
|
76
|
+
|
77
|
+
静的解析ツールを使わず、AI解析のみを実行するには、`--ai`オプションを使用します:
|
78
|
+
|
79
|
+
```bash
|
80
|
+
omamori scan --ai
|
81
|
+
```
|
82
|
+
|
83
|
+
## 設定
|
84
|
+
|
85
|
+
プロジェクトルートにある`.omamorirc`ファイルで、Omamoriの動作をカスタマイズできます。
|
86
|
+
|
87
|
+
設定項目の詳細は以下の通りです:
|
88
|
+
|
89
|
+
```yaml
|
90
|
+
# .omamorirc
|
91
|
+
# omamori用設定ファイル
|
92
|
+
|
93
|
+
# Gemini APIキー(AI解析に必須)
|
94
|
+
# 環境変数GEMINI_API_KEYで設定することも可能
|
95
|
+
api_key: YOUR_GEMINI_API_KEY # 実際のAPIキーに置き換えてください
|
96
|
+
|
97
|
+
# 使用するGeminiモデル(任意、デフォルト: gemini-1.5-pro-latest)
|
98
|
+
model: gemini-2.5-flash-preview-04-17
|
99
|
+
|
100
|
+
# 有効化するセキュリティチェック(任意、デフォルトは全チェック)
|
101
|
+
# checks:
|
102
|
+
# xss: true
|
103
|
+
# csrf: true
|
104
|
+
# idor: true
|
105
|
+
# ... # 他のチェック項目も追加可能
|
106
|
+
|
107
|
+
# カスタムプロンプトテンプレート(任意)
|
108
|
+
# prompt_templates:
|
109
|
+
# default: |
|
110
|
+
# ここにカスタムプロンプトを記述...
|
111
|
+
|
112
|
+
# レポート出力設定(任意)
|
113
|
+
# report:
|
114
|
+
# output_path: ./omamori_report # HTML/JSONレポートの出力先ディレクトリまたは接頭辞
|
115
|
+
# html_template: path/to/custom/template.erb # カスタムHTMLテンプレートのパス
|
116
|
+
|
117
|
+
# 静的解析ツールのオプション設定(任意)
|
118
|
+
# static_analysers:
|
119
|
+
# brakeman:
|
120
|
+
# options: "--force" # Brakemanに渡す追加オプション
|
121
|
+
# bundler_audit:
|
122
|
+
# options: "--quiet" # Bundler-Auditに渡す追加オプション
|
123
|
+
|
124
|
+
# AI解析時の詳細出力言語設定(任意、デフォルト: en)
|
125
|
+
# language: ja
|
126
|
+
```
|
127
|
+
|
128
|
+
- `api_key`: Gemini APIへのアクセスキー。環境変数`GEMINI_API_KEY`でも設定可能。
|
129
|
+
- `model`: AI解析に使用するGeminiモデル。デフォルトは`gemini-1.5-pro-latest`。
|
130
|
+
- `checks`: 実行するセキュリティチェックの設定。特定のチェックを有効/無効にできます(例:`xss: true`, `csrf: false`)。
|
131
|
+
- `prompt_templates`: AI解析用のカスタムプロンプトテンプレートを設定。
|
132
|
+
- `report`: レポート出力に関する設定。
|
133
|
+
- `output_path`: HTMLおよびJSONレポートの出力先ディレクトリまたはプレフィックス。
|
134
|
+
- `html_template`: カスタムHTMLテンプレート(ERB形式)のパス。
|
135
|
+
- `static_analysers`: 静的解析ツール(Brakeman、Bundler-Auditなど)の追加オプション設定。
|
136
|
+
- `language`: AI解析結果の詳細説明文の言語設定。デフォルトは英語(`en`)。
|
137
|
+
|
138
|
+
## デモファイル
|
139
|
+
|
140
|
+
`demo`ディレクトリには、Omamoriの機能をデモンストレーションするための既知の脆弱性を含むサンプルファイルが置かれています。
|
141
|
+
|
142
|
+
デモファイルを対象にOmamoriを実行するには、以下の手順を実施してください:
|
143
|
+
|
144
|
+
1. `demo`ディレクトリがgitで無視されていないことを確認します。`.gitignore`に記載されている場合は、コメントアウトまたは削除します。
|
145
|
+
2. `demo`ディレクトリ名を変更します:
|
146
|
+
|
147
|
+
```bash
|
148
|
+
mv demo demo_
|
149
|
+
```
|
150
|
+
|
151
|
+
3. 変更後の`demo_`ディレクトリをステージします:
|
152
|
+
|
153
|
+
```bash
|
154
|
+
git add demo_
|
155
|
+
```
|
156
|
+
|
157
|
+
4. ステージしたデモファイルに対してOmamoriを実行します:
|
158
|
+
|
159
|
+
```bash
|
160
|
+
omamori scan
|
161
|
+
```
|
162
|
+
|
163
|
+
または、ステージ後にすべてのファイルをスキャンする場合:
|
164
|
+
|
165
|
+
```bash
|
166
|
+
omamori scan --all
|
167
|
+
```
|
168
|
+
|
169
|
+
## 貢献について
|
170
|
+
|
171
|
+
バグ報告やプルリクエストはGitHubで歓迎しています。このプロジェクトは、安全かつ協力的なコラボレーションの場を目指しています。
|
172
|
+
|
173
|
+
## ライセンス
|
174
|
+
|
175
|
+
このGemは、[MITライセンス](https://opensource.org/licenses/MIT)のもとでオープンソースとして公開されています。
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# This file contains vulnerabilities that AI analysis can help detect.
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
API_KEY = "HARDCODED_SECRET_API_KEY_12345" # Hardcoded sensitive information
|
7
|
+
|
8
|
+
def fetch_data(user_input)
|
9
|
+
# Insufficient input validation
|
10
|
+
if user_input.length > 100
|
11
|
+
puts "Input too long, truncating."
|
12
|
+
user_input = user_input[0..99]
|
13
|
+
end
|
14
|
+
|
15
|
+
uri = URI("https://api.example.com/data?query=#{user_input}&api_key=#{API_KEY}")
|
16
|
+
response = Net::HTTP.get_response(uri)
|
17
|
+
|
18
|
+
if response.is_a?(Net::HTTPSuccess)
|
19
|
+
puts "Data fetched successfully: #{response.body}"
|
20
|
+
else
|
21
|
+
# Poor error handling - reveals internal details
|
22
|
+
puts "Error fetching data: #{response.code} - #{response.message}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Example usage
|
27
|
+
# fetch_data("some data")
|
28
|
+
# fetch_data("a" * 200) # Long input
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
|
5
|
+
# CSRF (Cross-Site Request Forgery) の脆弱性を含むデモコード
|
6
|
+
# フォーム送信時にCSRFトークンによる検証を行っていない例
|
7
|
+
|
8
|
+
# ユーザー情報を更新する想定のPOSTエンドポイント
|
9
|
+
post '/update_profile' do
|
10
|
+
# 本来はここでCSRFトークンの検証が必要だが、省略されている
|
11
|
+
user_id = params['user_id']
|
12
|
+
new_email = params['email']
|
13
|
+
|
14
|
+
# ユーザー情報の更新処理 (実際には行わない)
|
15
|
+
puts "ユーザー #{user_id} のメールアドレスを #{new_email} に更新しました。"
|
16
|
+
|
17
|
+
"Profile updated for user #{user_id}."
|
18
|
+
end
|
19
|
+
|
20
|
+
# 実行方法:
|
21
|
+
# 1. このファイルを保存
|
22
|
+
# 2. ターミナルで `ruby demo/csrf_vulnerability.rb` を実行
|
23
|
+
# 3. 攻撃者は、このエンドポイントへのPOSTリクエストをユーザーに意図せず実行させるような細工を施したページを作成し、ユーザーを誘導する。
|
24
|
+
# 例えば、以下のようなHTMLを含むページを別のサイトに用意する:
|
25
|
+
# <form action="http://localhost:4567/update_profile" method="post">
|
26
|
+
# <input type="hidden" name="user_id" value="123">
|
27
|
+
# <input type="hidden" name="email" value="attacker@example.com">
|
28
|
+
# <input type="submit" value="Click me!">
|
29
|
+
# </form>
|
30
|
+
# または、JavaScriptを使って自動的にPOSTリクエストを送信させる。
|
31
|
+
# ユーザーがログインした状態でこのページを閲覧すると、意図せずプロファイルが更新される可能性がある。
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
|
5
|
+
# 危険な eval/動的コード実行の脆弱性を含むデモコード
|
6
|
+
# ユーザーからの入力を eval で直接評価している例
|
7
|
+
|
8
|
+
get '/calculate' do
|
9
|
+
# ユーザーからの入力 (expression) を取得
|
10
|
+
expression = params['expression']
|
11
|
+
|
12
|
+
# 取得した入力を eval で評価
|
13
|
+
# ここにコードインジェクションの脆弱性がある
|
14
|
+
# 攻撃者は任意のRubyコードを実行させることが可能になる
|
15
|
+
begin
|
16
|
+
result = eval(expression)
|
17
|
+
"Result: #{result}"
|
18
|
+
rescue StandardError => e
|
19
|
+
status 500
|
20
|
+
"Error: #{e.message}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# 実行方法:
|
25
|
+
# 1. このファイルを保存
|
26
|
+
# 2. ターミナルで `ruby demo/eval_vulnerability.rb` を実行
|
27
|
+
# 3. ブラウザで `http://localhost:4567/calculate?expression=2%2B2` にアクセスすると "Result: 4" が表示される。
|
28
|
+
# 4. 悪意のある入力を与える例: `http://localhost:4567/calculate?expression=system('ls%20-l')`
|
29
|
+
# サーバー側で `ls -l` コマンドが実行されてしまう可能性がある。
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
|
5
|
+
# IDOR (Insecure Direct Object Reference) の脆弱性を含むデモコード
|
6
|
+
# ユーザーからの入力(ID)を直接使用してリソースにアクセスし、認可チェックを行っていない例
|
7
|
+
|
8
|
+
# ユーザー情報を表示する想定のエンドポイント
|
9
|
+
get '/user_info/:user_id' do
|
10
|
+
user_id = params['user_id']
|
11
|
+
|
12
|
+
# 本来はここで、リクエストを行ったユーザーが、指定された user_id の情報にアクセスする権限があるかチェックが必要だが、省略されている
|
13
|
+
user_data = fetch_user_data(user_id) # ユーザーIDに基づいてデータを取得する関数を想定
|
14
|
+
|
15
|
+
if user_data
|
16
|
+
"User Info for ID #{user_id}: #{user_data}"
|
17
|
+
else
|
18
|
+
status 404
|
19
|
+
"User not found."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# ダミーのユーザーデータ取得関数
|
24
|
+
def fetch_user_data(user_id)
|
25
|
+
# 実際にはデータベースなどからデータを取得する
|
26
|
+
users = {
|
27
|
+
'101' => 'Alice',
|
28
|
+
'102' => 'Bob',
|
29
|
+
'103' => 'Charlie'
|
30
|
+
}
|
31
|
+
users[user_id]
|
32
|
+
end
|
33
|
+
|
34
|
+
# 実行方法:
|
35
|
+
# 1. このファイルを保存
|
36
|
+
# 2. ターミナルで `ruby demo/idor_vulnerability.rb` を実行
|
37
|
+
# 3. ブラウザで `http://localhost:4567/user_info/101` にアクセスすると Alice の情報が表示される。
|
38
|
+
# 4. ログインしていない、または権限のないユーザーが `http://localhost:4567/user_info/102` にアクセスすると、
|
39
|
+
# 本来アクセス権限がないはずの Bob の情報が表示されてしまう可能性がある。
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
|
5
|
+
# 不適切なクッキー属性(HttpOnly, Secure, SameSite 未設定)の脆弱性を含むデモコード
|
6
|
+
# セキュリティ関連の属性が設定されていないクッキーを発行する例
|
7
|
+
|
8
|
+
# ログイン成功時にセッションクッキーを発行する想定のエンドポイント
|
9
|
+
get '/login' do
|
10
|
+
user_id = params['user_id'] # ダミーのユーザーID取得
|
11
|
+
|
12
|
+
# セッションIDをクッキーに設定
|
13
|
+
# HttpOnly, Secure, SameSite 属性が設定されていない
|
14
|
+
# これにより、XSS攻撃によるクッキー情報の窃盗や、CSRF攻撃のリスクが高まる
|
15
|
+
response.set_cookie('session_id', value: "user_#{user_id}_#{Time.now.to_i}")
|
16
|
+
|
17
|
+
"Logged in as user #{user_id}. Session cookie set."
|
18
|
+
end
|
19
|
+
|
20
|
+
# 実行方法:
|
21
|
+
# 1. このファイルを保存
|
22
|
+
# 2. ターミナルで `ruby demo/insecure_cookie_vulnerability.rb` を実行
|
23
|
+
# 3. ブラウザで `http://localhost:4567/login?user_id=test_user` にアクセス
|
24
|
+
# 開発者ツールなどでクッキーを確認すると、session_id クッキーに HttpOnly, Secure, SameSite 属性が付与されていないことがわかる。
|
25
|
+
# HTTPSでアクセスした場合でもSecure属性が付かない。
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
|
5
|
+
# オープンリダイレクトの脆弱性を含むデモコード
|
6
|
+
# ユーザーからの入力(URL)を検証せずにリダイレクト先に指定している例
|
7
|
+
|
8
|
+
get '/redirect' do
|
9
|
+
# ユーザーからの入力 (url) を取得
|
10
|
+
redirect_url = params['url']
|
11
|
+
|
12
|
+
# 取得した入力をそのままリダイレクト先に指定
|
13
|
+
# ここにオープンリダイレクトの脆弱性がある
|
14
|
+
redirect redirect_url
|
15
|
+
end
|
16
|
+
|
17
|
+
# 実行方法:
|
18
|
+
# 1. このファイルを保存
|
19
|
+
# 2. ターミナルで `ruby demo/open_redirect_vulnerability.rb` を実行
|
20
|
+
# 3. ブラウザで `http://localhost:4567/redirect?url=https://malicious-site.example.com` にアクセス
|
21
|
+
# 悪意のあるサイトにリダイレクトされてしまう。
|
22
|
+
# フィッシング詐欺などに悪用される可能性がある。
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# This file contains a vulnerability detectable by static analysis tools like Brakeman.
|
2
|
+
|
3
|
+
require 'sqlite3'
|
4
|
+
|
5
|
+
def find_user(username)
|
6
|
+
db = SQLite3::Database.open 'users.db'
|
7
|
+
# Vulnerable to SQL injection
|
8
|
+
query = "SELECT * FROM users WHERE username = '#{username}'"
|
9
|
+
puts "Executing query: #{query}"
|
10
|
+
db.execute query
|
11
|
+
rescue SQLite3::Exception => e
|
12
|
+
puts "Exception occurred: #{e}"
|
13
|
+
ensure
|
14
|
+
db.close if db
|
15
|
+
end
|
16
|
+
|
17
|
+
# Example usage (vulnerable)
|
18
|
+
# find_user("' OR '1'='1")
|