secchecker 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c2afd56529d49c34ab552c83f2a95d4d595d13a50c9b73008665db6b6748c4ed
4
+ data.tar.gz: 64dde885c618b6a2789b26de29c15c814ee725db5ef9e3ffcc3e40319662ea1e
5
+ SHA512:
6
+ metadata.gz: 61abdc873a30f5c750969b11f7d79fdffe0064121f5ac4d2620ec6373b30b21ae59ae04a28fe8c362defc99067e32913ac28a856f25fbb3fea49f0f1b4a0c057
7
+ data.tar.gz: 0f4f09e3d194fc890d87cc076afce7f94e9cbeb2779f3497bedbee3abbdb00296b8976a2a5852198145b9b050fa0ddc883887b4857e679d34eb75bc43ff298bd
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /out/
10
+ /vendor/
11
+ .DS_Store
12
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.6
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at src@srcw.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in secchecker.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ secchecker (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.4)
10
+ rake (12.3.3)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ minitest (~> 5.0)
17
+ rake (~> 12.0)
18
+ secchecker!
19
+
20
+ BUNDLED WITH
21
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 src
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,30 @@
1
+ # Secchecker
2
+
3
+ Check passwords and other sensitive information.
4
+
5
+ ## Installation
6
+
7
+
8
+ ```ruby
9
+ gem 'secchecker'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle install
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install secchecker
19
+
20
+ ## Usage
21
+
22
+ $ gsecchecker ~/myrepository
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
27
+
28
+ ## Code of Conduct
29
+
30
+ Everyone interacting in the Secchecker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/secchecker/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "secchecker"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/config.yml ADDED
@@ -0,0 +1,10 @@
1
+ patterns:
2
+ - !ruby/regexp /[A-Z0-9]{20}/
3
+ - !ruby/regexp /(\"|')?(AWS|aws|Aws)?_?(SECRET|secret|Secret)?_?(ACCESS|access|Access)?_?(KEY|key|Key)(\"|')?\s*(:|=>|=)\s*(\"|')?[A-Za-z0-9\/\+=]{40}(\"|')?/
4
+ - !ruby/regexp /(\"|')?(AWS|aws|Aws)?_?(ACCOUNT|account|Account)_?(ID|id|Id)?(\"|')?\s*(:|=>|=)\s*(\"|')?[0-9]{4}\-?[0-9]{4}\-?[0-9]{4}(\"|')?/
5
+ allowed:
6
+ - !ruby/regexp /AKIAIOSFODNN7EXAMPLE/
7
+ - !ruby/regexp /wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY/
8
+
9
+
10
+
@@ -0,0 +1,9 @@
1
+ [default]
2
+ #許可される
3
+ aws_access_key = AKIAIOSFODNN7EXAMPLE
4
+ #許可される
5
+ aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
6
+
7
+
8
+
9
+
data/exe/secchecker ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "secchecker"
4
+
5
+ Secchecker::Command.run(ARGV)
6
+
data/lib/secchecker.rb ADDED
@@ -0,0 +1,181 @@
1
+ require "secchecker/version"
2
+ require "yaml"
3
+ require "optparse"
4
+ require 'find'
5
+ require 'fileutils'
6
+
7
+ module Secchecker
8
+ class Error < StandardError; end
9
+
10
+ class Config
11
+ def initialize(config)
12
+ @config = config
13
+ @patterns = config_value("patterns", false) || []
14
+ @allowed = config_value("allowed", false) || []
15
+ end
16
+ attr_reader :patterns, :allowed
17
+
18
+ def match_patterns(line)
19
+ begin
20
+ @patterns.each do |pat|
21
+ return pat if pat =~ line
22
+ end
23
+ rescue
24
+ # puts $!
25
+ end
26
+ nil
27
+ end
28
+
29
+ def match_allowed(line)
30
+ @allowed.each do |pat|
31
+ return pat if pat =~ line
32
+ end
33
+ nil
34
+ end
35
+
36
+ def unmatch_allowd(line)
37
+ end
38
+
39
+ private
40
+ def config_value(key, require)
41
+ value = @config[key]
42
+ if require && (value.nil? || value.empty?)
43
+ raise RuntimeError, "{key}: is empty"
44
+ end
45
+ value
46
+ end
47
+ end
48
+
49
+ class MatchLine
50
+ def initialize(line, lineno, pattern)
51
+ @line = line
52
+ @lineno = lineno
53
+ @pattern = pattern
54
+ end
55
+ attr_reader :line, :lineno, :pattern
56
+ end
57
+
58
+ class Command
59
+ def self.run(argv)
60
+ STDOUT.sync = true
61
+ opts = {}
62
+ opt = OptionParser.new(argv)
63
+ opt.version = VERSION
64
+ opt.banner = "Usage: #{opt.program_name} [-h|--help] <dir>"
65
+ opt.separator('')
66
+ opt.separator("Examples:")
67
+ opt.separator(" #{opt.program_name} ~/project")
68
+ opt.separator('')
69
+ opt.separator("Options:")
70
+ opt.on_head('-h', '--help', 'Show this message') do |v|
71
+ puts opt.help
72
+ exit
73
+ end
74
+ opt.on('-s SETTINGFILE', '--setting=SETTINGFILE', 'setting file') {|v| opts[:s] = v}
75
+ # commands = ['scan']
76
+ # opt.on('-c COMMAND', '--command=COMMAND', commands, commands.join('|')) {|v| opts[:c] = v}
77
+ opt.on('-v', '--verbose', 'verbose message') {|v| opts[:v] = v}
78
+ opt.on('--dry-run', 'message only') {|v| opts[:dry_run] = v}
79
+ opt.on('-a', '--all', 'check all files') {|v| opts[:a]}
80
+ opt.parse!(argv)
81
+
82
+ settings = opts[:s] || File.expand_path("~/.seccheckerrc")
83
+ unless FileTest.file?(settings)
84
+ puts opt.help
85
+ exit
86
+ end
87
+ config = Config.new(YAML.load_file(settings))
88
+ command = Command.new(opts, config)
89
+ dir = argv[0]
90
+ if dir.nil? || !FileTest.directory?(dir)
91
+ puts opt.help
92
+ exit
93
+ end
94
+ command.run(dir)
95
+ end
96
+
97
+ def initialize(opts, config)
98
+ @opts = opts
99
+ @config = config
100
+ end
101
+
102
+
103
+ def run(dir)
104
+ puts "secchecker #{dir}"
105
+ dir = File.expand_path(dir)
106
+ all_matchlines = []
107
+ Dir.chdir(dir) do
108
+ ls_files(dir) do |f|
109
+ matchlines = process_file(dir, f)
110
+ if matchlines.size > 0
111
+ all_matchlines << matchlines
112
+ end
113
+ end
114
+ end
115
+ if all_matchlines.size > 0
116
+ puts ""
117
+ puts "[ERROR] Matched one or more prohibited patterns"
118
+ puts ""
119
+ end
120
+ end
121
+
122
+ private
123
+ def git_repository?(dir)
124
+ repodir = File.join(dir, ".git")
125
+ puts repodir
126
+ FileTest.directory?(repodir)
127
+ end
128
+
129
+ def ls_files(dir)
130
+ if git_repository?(dir) && !@opts[:a]
131
+ `git ls-files`.each_line do |f|
132
+ f.chomp!
133
+ yield f
134
+ end
135
+ else
136
+ Find.find('.') {|f|
137
+ yield f
138
+ }
139
+ end
140
+ end
141
+
142
+ def process_file(dir, f)
143
+ path = File.expand_path(File.join(dir, f))
144
+ return [] unless FileTest.file?(path)
145
+ if is_file_binary(path)
146
+ puts "skip binary file: #{path}" if @opts[:v]
147
+ return []
148
+ end
149
+ puts "#{path}" if @opts[:v]
150
+
151
+
152
+ matchlines = check_pattern(f)
153
+ if matchlines.size > 0
154
+ matchlines.each do |ml|
155
+ puts "#{f}:#{ml.lineno}:#{ml.line}\##### #{ml.pattern} #####"
156
+ end
157
+ end
158
+ matchlines
159
+ end
160
+
161
+
162
+ def check_pattern(filename)
163
+ # puts filename
164
+ matchlines = []
165
+ lines = IO.readlines(filename, mode: "r:utf-8")
166
+ lines.each_with_index do |line, index|
167
+ line.chomp!
168
+ pat = @config.match_patterns(line)
169
+ if pat && !@config.match_allowed(line)
170
+ matchlines << MatchLine.new(line, index + 1, pat)
171
+ end
172
+ end
173
+ matchlines
174
+ end
175
+
176
+ def is_file_binary(file)
177
+ s = (File.read(file, File.stat(file).blksize) || "").split(//)
178
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,3 @@
1
+ module Secchecker
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/secchecker/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "secchecker"
5
+ spec.version = Secchecker::VERSION
6
+ spec.authors = ["src"]
7
+ spec.email = ["src@srcw.net"]
8
+
9
+ spec.summary = %q{Check passwords and other sensitive information.}
10
+ spec.description = %q{Check passwords and other sensitive information.}
11
+ spec.homepage = "https://github.com/src256/secchecker"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
data/secchecker.sh ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/secchecker $*
3
+
4
+
5
+
6
+
data/test_config.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/secchecker -s config/config.yml ./data
3
+
4
+
5
+
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: secchecker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - src
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Check passwords and other sensitive information.
14
+ email:
15
+ - src@srcw.net
16
+ executables:
17
+ - secchecker
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".ruby-version"
23
+ - ".travis.yml"
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - config/config.yml
33
+ - data/aws_credentials.txt
34
+ - exe/secchecker
35
+ - lib/secchecker.rb
36
+ - lib/secchecker/version.rb
37
+ - secchecker.gemspec
38
+ - secchecker.sh
39
+ - test_config.sh
40
+ homepage: https://github.com/src256/secchecker
41
+ licenses:
42
+ - MIT
43
+ metadata:
44
+ homepage_uri: https://github.com/src256/secchecker
45
+ source_code_uri: https://github.com/src256/secchecker
46
+ changelog_uri: https://github.com/src256/secchecker
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.3.0
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: Check passwords and other sensitive information.
66
+ test_files: []