pwn 0.5.442 → 0.5.444

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/README.md +3 -3
  4. data/bin/pwn_sast +1 -0
  5. data/lib/pwn/plugins/file_fu.rb +20 -22
  6. data/lib/pwn/sast/amqp_connect_as_guest.rb +12 -91
  7. data/lib/pwn/sast/apache_file_system_util_api.rb +11 -93
  8. data/lib/pwn/sast/aws.rb +13 -95
  9. data/lib/pwn/sast/banned_function_calls_c.rb +140 -219
  10. data/lib/pwn/sast/base64.rb +12 -92
  11. data/lib/pwn/sast/beef_hook.rb +10 -92
  12. data/lib/pwn/sast/cmd_execution_go_lang.rb +83 -0
  13. data/lib/pwn/sast/cmd_execution_java.rb +14 -93
  14. data/lib/pwn/sast/cmd_execution_python.rb +16 -95
  15. data/lib/pwn/sast/cmd_execution_ruby.rb +24 -103
  16. data/lib/pwn/sast/cmd_execution_scala.rb +14 -93
  17. data/lib/pwn/sast/csrf.rb +10 -92
  18. data/lib/pwn/sast/deserial_java.rb +19 -98
  19. data/lib/pwn/sast/emoticon.rb +17 -100
  20. data/lib/pwn/sast/eval.rb +10 -92
  21. data/lib/pwn/sast/factory.rb +15 -95
  22. data/lib/pwn/sast/http_authorization_header.rb +20 -102
  23. data/lib/pwn/sast/inner_html.rb +10 -92
  24. data/lib/pwn/sast/keystore.rb +10 -92
  25. data/lib/pwn/sast/local_storage.rb +11 -93
  26. data/lib/pwn/sast/location_hash.rb +10 -92
  27. data/lib/pwn/sast/log4j.rb +12 -91
  28. data/lib/pwn/sast/logger.rb +24 -106
  29. data/lib/pwn/sast/md5.rb +10 -92
  30. data/lib/pwn/sast/outer_html.rb +10 -92
  31. data/lib/pwn/sast/padding_oracle.rb +11 -93
  32. data/lib/pwn/sast/password.rb +15 -97
  33. data/lib/pwn/sast/php_input_mechanisms.rb +18 -97
  34. data/lib/pwn/sast/php_type_juggling.rb +16 -95
  35. data/lib/pwn/sast/pom_version.rb +1 -3
  36. data/lib/pwn/sast/port.rb +16 -98
  37. data/lib/pwn/sast/post_message.rb +10 -92
  38. data/lib/pwn/sast/private_key.rb +10 -92
  39. data/lib/pwn/sast/redirect.rb +13 -95
  40. data/lib/pwn/sast/redos.rb +16 -98
  41. data/lib/pwn/sast/shell.rb +18 -100
  42. data/lib/pwn/sast/signature.rb +10 -92
  43. data/lib/pwn/sast/sql.rb +19 -95
  44. data/lib/pwn/sast/ssl.rb +14 -96
  45. data/lib/pwn/sast/sudo.rb +10 -92
  46. data/lib/pwn/sast/task_tag.rb +23 -105
  47. data/lib/pwn/sast/test_case_engine.rb +188 -0
  48. data/lib/pwn/sast/throw_errors.rb +14 -96
  49. data/lib/pwn/sast/token.rb +12 -94
  50. data/lib/pwn/sast/type_script_type_juggling.rb +16 -95
  51. data/lib/pwn/sast/version.rb +12 -94
  52. data/lib/pwn/sast/window_location_hash.rb +10 -92
  53. data/lib/pwn/sast.rb +5 -0
  54. data/lib/pwn/version.rb +1 -1
  55. data/lib/pwn.rb +0 -2
  56. data/spec/lib/pwn/sast/cmd_execution_go_lang_spec.rb +25 -0
  57. data/spec/lib/pwn/sast/test_case_engine_spec.rb +20 -0
  58. data/third_party/pwn_rdoc.jsonl +1 -1
  59. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f41d05e60c7f650088bc283e5a06b7d098c97df33136978ec4cbdb153bfa2c16
4
- data.tar.gz: 93ba311fa530ba7bcf3622a581fc801d33aa600f7d266a554adc0473cf8ac5da
3
+ metadata.gz: ec6df63c1b99b28c53063a7a55160e3daf1b961fb5c9c65b13e522bb1011f54d
4
+ data.tar.gz: 384514b0c8e2fe6d11696a55e5e9fc04a3cf5af85218b6643a2009401da50188
5
5
  SHA512:
6
- metadata.gz: b65927abd14e08746efc021f7ce5ad6e66d96224e9a6007401853b11f62a0d18da00b1e02655e228041d63bed46202e1e8217f294f83bb824f9cfc15332ebf85
7
- data.tar.gz: 9ab2ee50ccba046c830a9b6120b491295c509d9962b64f1a77ca82b9e17ac98610d088ad78061c7afa4848d9313032764810880d54dd4e5b7ada5a0bd1c6a9b2
6
+ metadata.gz: 679c8b0262e600ae206e713ceec79d60de9ce91bf39b0eebb420c76316fd0cb7816a9bf96390bf5545e5c6063697809354fb52aa55aad962cd0b2c9c5373d123
7
+ data.tar.gz: f14604cb417bd26b745a4c311ed8614cc8ec3f13e07f622497efbb4037fda26ed767dc017ff2fa1e92eee4f47a731d4646ea76e05cf05628d4377a23e7cef460
data/Gemfile CHANGED
@@ -41,7 +41,7 @@ gem 'htmlentities', '4.3.4'
41
41
  gem 'ipaddress', '0.8.3'
42
42
  gem 'jenkins_api_client2', '1.9.0'
43
43
  gem 'js-beautify', '0.1.8'
44
- gem 'json', '2.15.0'
44
+ gem 'json', '2.15.1'
45
45
  gem 'jsonpath', '1.1.5'
46
46
  gem 'json_schemer', '2.4.0'
47
47
  gem 'jwt', '3.1.2'
data/README.md CHANGED
@@ -37,7 +37,7 @@ $ cd /opt/pwn
37
37
  $ ./install.sh
38
38
  $ ./install.sh ruby-gem
39
39
  $ pwn
40
- pwn[v0.5.442]:001 >>> PWN.help
40
+ pwn[v0.5.444]:001 >>> PWN.help
41
41
  ```
42
42
 
43
43
  [![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.4.4@pwn
52
52
  $ gem uninstall --all --executables pwn
53
53
  $ gem install --verbose pwn
54
54
  $ pwn
55
- pwn[v0.5.442]:001 >>> PWN.help
55
+ pwn[v0.5.444]:001 >>> PWN.help
56
56
  ```
57
57
 
58
58
  If you're using a multi-user install of RVM do:
@@ -62,7 +62,7 @@ $ rvm use ruby-3.4.4@pwn
62
62
  $ rvmsudo gem uninstall --all --executables pwn
63
63
  $ rvmsudo gem install --verbose pwn
64
64
  $ pwn
65
- pwn[v0.5.442]:001 >>> PWN.help
65
+ pwn[v0.5.444]:001 >>> PWN.help
66
66
  ```
67
67
 
68
68
  PWN periodically upgrades to the latest version of Ruby which is reflected in `/opt/pwn/.ruby-version`. The easiest way to upgrade to the latest version of Ruby from a previous PWN installation is to run the following script:
data/bin/pwn_sast CHANGED
@@ -102,6 +102,7 @@ begin
102
102
  BannedFunctionCallsC
103
103
  Base64
104
104
  BeefHook
105
+ CmdExecutionGoLang
105
106
  CmdExecutionJava
106
107
  CmdExecutionPython
107
108
  CmdExecutionRuby
@@ -14,7 +14,9 @@ module PWN
14
14
  module FileFu
15
15
  # Supported Method Parameters::
16
16
  # PWN::Plugins::FileFu.recurse_in_dir(
17
- # dir_path: 'optional path to dir defaults to .'
17
+ # dir_path: 'optional path to dir defaults to .',
18
+ # include_extensions: 'optional - array of file extensions to search for in scan (e.g. ['.js', '.php'])',
19
+ # exclude_extensions: 'optional - array of file extensions to exclude from scan (e.g. ['.log', '.txt', '.spec'])'
18
20
  # )
19
21
 
20
22
  public_class_method def self.recurse_in_dir(opts = {})
@@ -22,32 +24,24 @@ module PWN
22
24
  dir_path = dir_path.to_s.scrub unless dir_path.is_a?(String)
23
25
  raise "PWN Error: Invalid Directory #{dir_path}" unless Dir.exist?(dir_path)
24
26
 
27
+ include_extensions = opts[:include_extensions] ||= []
28
+ exclude_extensions = opts[:exclude_extensions] ||= []
29
+
25
30
  previous_dir = Dir.pwd
26
31
  Dir.chdir(dir_path)
27
32
  # Execute this like this:
28
33
  # recurse_in_dir(:dir_path => 'path to dir') {|entry| puts entry}
29
- Dir.glob('./**/*').each { |entry| yield Shellwords.escape(entry) }
30
- rescue StandardError => e
31
- raise e
32
- ensure
33
- Dir.chdir(previous_dir) if Dir.exist?(previous_dir)
34
- end
35
-
36
- # Supported Method Parameters::
37
- # PWN::Plugins::FileFu.recurse_dir(
38
- # dir_path: 'optional path to dir defaults to .'
39
- # )
34
+ Dir.glob('./**/*').each do |entry|
35
+ next if exclude_extensions.include?(File.extname(entry))
40
36
 
41
- public_class_method def self.recurse_dir(opts = {})
42
- dir_path = opts[:dir_path] ||= '.'
43
- dir_path = dir_path.to_s.scrub unless dir_path.is_a?(String)
44
- raise "PWN Error: Invalid Directory #{dir_path}" unless Dir.exist?(dir_path)
37
+ next unless include_extensions.empty? || include_extensions.include?(File.extname(entry))
45
38
 
46
- # Execute this like this:
47
- # recurse_dir(:dir_path => 'path to dir') {|entry| puts entry}
48
- Dir.glob("#{dir_path}/**/*").each { |entry| yield Shellwords.escape(entry) }
39
+ yield Shellwords.escape(entry)
40
+ end
49
41
  rescue StandardError => e
50
42
  raise e
43
+ ensure
44
+ Dir.chdir(previous_dir) if Dir.exist?(previous_dir)
51
45
  end
52
46
 
53
47
  # Supported Method Parameters::
@@ -78,9 +72,13 @@ module PWN
78
72
 
79
73
  public_class_method def self.help
80
74
  puts "USAGE:
81
- #{self}.recurse_in_dir(dir_path: 'optional path to dir defaults to .') {|entry| puts entry}
82
-
83
- #{self}.recurse_dir(dir_path: 'optional path to dir defaults to .') {|entry| puts entry}
75
+ #{self}.recurse_in_dir(
76
+ dir_path: 'optional path to dir defaults to .',
77
+ include_extensions: 'optional - array of file extensions to search for in scan (e.g. ['.js', '.php'])',
78
+ exclude_extensions: 'optional - array of file extensions to exclude from scan (e.g. ['.log', '.txt', '.spec'])'
79
+ ) do |entry|
80
+ puts entry
81
+ end
84
82
 
85
83
  #{self}.untar_gz_file(
86
84
  tar_gz_file: 'required - path to .tar.gz file',
@@ -9,8 +9,6 @@ module PWN
9
9
  # within source code to determine if connections to RabbitMQ servers
10
10
  # are using guest accounts.
11
11
  module AMQPConnectAsGuest
12
- @@logger = PWN::Plugins::PWNLogger.create
13
-
14
12
  # Supported Method Parameters::
15
13
  # PWN::SAST::AMQPConnectAsGuest.scan(
16
14
  # dir_path: 'optional path to dir defaults to .'
@@ -20,97 +18,20 @@ module PWN
20
18
  public_class_method def self.scan(opts = {})
21
19
  dir_path = opts[:dir_path]
22
20
  git_repo_root_uri = opts[:git_repo_root_uri].to_s.scrub
23
- result_arr = []
24
- ai_introspection = PWN::Env[:ai][:introspection]
25
- logger_results = "AI Introspection => #{ai_introspection} => "
26
-
27
- PWN::Plugins::FileFu.recurse_in_dir(dir_path: dir_path) do |entry|
28
- if File.file?(entry) && File.basename(entry) !~ /^pwn.+(html|json|db)$/ && File.basename(entry) !~ /\.JS-BEAUTIFIED$/ && entry !~ /test/i
29
- line_no_and_contents_arr = []
30
- entry_beautified = false
31
-
32
- if File.extname(entry) == '.js' && (`wc -l #{entry}`.split.first.to_i < 20 || entry.include?('.min.js') || entry.include?('-all.js'))
33
- js_beautify = `js-beautify #{entry} > #{entry}.JS-BEAUTIFIED 2> /dev/null`.to_s.scrub
34
- entry = "#{entry}.JS-BEAUTIFIED"
35
- entry_beautified = true
36
- end
37
-
38
- test_case_filter = "
39
- grep -in \
40
- -e amqp \
41
- -e rabbit #{entry} 2> /dev/null | \
42
- grep guest
43
- "
44
21
 
45
- str = `#{test_case_filter}`.to_s.scrub
46
- if str.to_s.empty?
47
- # If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
48
- logger_results = "#{logger_results}~" # Catching bugs is good :)
49
- else
50
- str = "1:Result larger than 64KB -> Size: #{str.to_s.length}. Please click the \"Path\" link for more details." if str.to_s.length >= 64_000
51
-
52
- hash_line = {
53
- timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
54
- security_references: security_references,
55
- filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
56
- line_no_and_contents: '',
57
- raw_content: str,
58
- test_case_filter: test_case_filter
59
- }
60
-
61
- # COMMMENT: Must be a better way to implement this (regex is kinda funky)
62
- line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
63
- line_no_count = line_contents_split.length # This should always be an even number
64
- current_count = 0
65
- while line_no_count > current_count
66
- line_no = line_contents_split[current_count]
67
- contents = line_contents_split[current_count + 1]
68
- if Dir.exist?('.git')
69
- repo_root = '.'
70
- author = PWN::Plugins::Git.get_author(
71
- repo_root: repo_root,
72
- from_line: line_no,
73
- to_line: line_no,
74
- target_file: entry,
75
- entry_beautified: entry_beautified
76
- )
77
- end
78
- author ||= 'N/A'
79
-
80
- ai_analysis = nil
81
- if ai_introspection
82
- request = {
83
- scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
84
- line_no: line_no,
85
- source_code_snippet: contents
86
- }.to_json
87
- response = PWN::AI::Introspection.reflect(request: request)
88
- if response.is_a?(Hash)
89
- ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
90
- ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
91
- end
92
- end
22
+ test_case_filter = "
23
+ grep -in \
24
+ -e amqp \
25
+ -e rabbit {PWN_SAST_SRC_TARGET} 2> /dev/null | \
26
+ grep guest
27
+ "
93
28
 
94
- hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
95
- line_no: line_no,
96
- contents: contents,
97
- author: author,
98
- ai_analysis: ai_analysis
99
- )
100
- current_count += 2
101
- end
102
- result_arr.push(hash_line)
103
- logger_results = "#{logger_results}x" # Seeing progress is good :)
104
- end
105
- end
106
- end
107
- logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
108
- if logger_results.empty?
109
- @@logger.info("#{logger_banner}: No files applicable to this test case.\n")
110
- else
111
- @@logger.info("#{logger_banner} => #{logger_results}complete.\n")
112
- end
113
- result_arr
29
+ PWN::SAST::TestCaseEngine.execute(
30
+ test_case_filter: test_case_filter,
31
+ security_references: security_references,
32
+ dir_path: dir_path,
33
+ git_repo_root_uri: git_repo_root_uri
34
+ )
114
35
  rescue StandardError => e
115
36
  raise e
116
37
  end
@@ -8,8 +8,6 @@ module PWN
8
8
  # SAST Module used to identify arbitrary command execution
9
9
  # within Apache Common's API Class, org.apache.commons.io.FileSystemUtils
10
10
  module ApacheFileSystemUtilAPI
11
- @@logger = PWN::Plugins::PWNLogger.create
12
-
13
11
  # Supported Method Parameters::
14
12
  # PWN::SAST::ApacheFileSystemUtilAPI.scan(
15
13
  # :dir_path => 'optional path to dir defaults to .'
@@ -19,99 +17,19 @@ module PWN
19
17
  public_class_method def self.scan(opts = {})
20
18
  dir_path = opts[:dir_path]
21
19
  git_repo_root_uri = opts[:git_repo_root_uri].to_s.scrub
22
- result_arr = []
23
- ai_introspection = PWN::Env[:ai][:introspection]
24
- logger_results = "AI Introspection => #{ai_introspection} => "
25
-
26
- PWN::Plugins::FileFu.recurse_in_dir(dir_path: dir_path) do |entry|
27
- if File.file?(entry) && File.basename(entry) !~ /^pwn.+(html|json|db)$/ && File.basename(entry) !~ /\.JS-BEAUTIFIED$/ && entry !~ /test/i
28
- line_no_and_contents_arr = []
29
- entry_beautified = false
30
-
31
- if File.extname(entry) == '.js' && (`wc -l #{entry}`.split.first.to_i < 20 || entry.include?('.min.js') || entry.include?('-all.js'))
32
- js_beautify = `js-beautify #{entry} > #{entry}.JS-BEAUTIFIED 2> /dev/null`.to_s.scrub
33
- entry = "#{entry}.JS-BEAUTIFIED"
34
- entry_beautified = true
35
- end
36
-
37
- test_case_filter = "
38
- grep -n \
39
- -e 'import org.apache.commons.io.FileSystemUtils' \
40
- -e 'freeSpaceKb' #{entry} 2> /dev/null
41
- "
42
-
43
- str = `#{test_case_filter}`.to_s.scrub
44
-
45
- if str.to_s.empty?
46
- # If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
47
- logger_results = "#{logger_results}~" # Catching bugs is good :)
48
- else
49
- str = "1:Result larger than 64KB -> Size: #{str.to_s.length}. Please click the \"Path\" link for more details." if str.to_s.length >= 64_000
50
20
 
51
- hash_line = {
52
- timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
53
- security_references: security_references,
54
- filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
55
- line_no_and_contents: '',
56
- raw_content: str,
57
- test_case_filter: test_case_filter
58
- }
59
-
60
- # COMMMENT: Must be a better way to implement this (regex is kinda funky)
61
- line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
62
- line_no_count = line_contents_split.length # This should always be an even number
63
- current_count = 0
64
- while line_no_count > current_count
65
- line_no = line_contents_split[current_count]
66
- contents = line_contents_split[current_count + 1]
67
- if Dir.exist?('.git')
68
- repo_root = '.'
69
-
70
- author = PWN::Plugins::Git.get_author(
71
- repo_root: repo_root,
72
- from_line: line_no,
73
- to_line: line_no,
74
- target_file: entry,
75
- entry_beautified: entry_beautified
76
- )
77
- end
78
- author ||= 'N/A'
79
-
80
- ai_analysis = nil
81
- if ai_introspection
82
- request = {
83
- scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
84
- line_no: line_no,
85
- source_code_snippet: contents
86
- }.to_json
87
- response = PWN::AI::Introspection.reflect(request: request)
88
- if response.is_a?(Hash)
89
- ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
90
- ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
91
- end
92
- end
93
-
94
- hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
95
- line_no: line_no,
96
- contents: contents,
97
- author: author,
98
- ai_analysis: ai_analysis
99
- )
21
+ test_case_filter = "
22
+ grep -n \
23
+ -e 'import org.apache.commons.io.FileSystemUtils' \
24
+ -e 'freeSpaceKb' {PWN_SAST_SRC_TARGET} 2> /dev/null
25
+ "
100
26
 
101
- current_count += 2
102
- end
103
- result_arr.push(hash_line)
104
- logger_results = "#{logger_results}x" # Seeing progress is good :)
105
- end
106
- end
107
- end
108
- logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
109
- if logger_results.empty?
110
- @@logger.info("#{logger_banner}: No files applicable to this test case.\n")
111
- else
112
- @@logger.info("#{logger_banner} => #{logger_results}complete.\n")
113
- end
114
- result_arr
27
+ PWN::SAST::TestCaseEngine.execute(
28
+ test_case_filter: test_case_filter,
29
+ security_references: security_references,
30
+ dir_path: dir_path,
31
+ git_repo_root_uri: git_repo_root_uri
32
+ )
115
33
  rescue StandardError => e
116
34
  raise e
117
35
  end
data/lib/pwn/sast/aws.rb CHANGED
@@ -7,8 +7,6 @@ module PWN
7
7
  module SAST
8
8
  # SAST Module used to identify sensitive AWS AuthN artifacts.
9
9
  module AWS
10
- @@logger = PWN::Plugins::PWNLogger.create
11
-
12
10
  # Supported Method Parameters::
13
11
  # PWN::SAST::Port.scan(
14
12
  # dir_path: 'optional path to dir defaults to .'
@@ -18,101 +16,21 @@ module PWN
18
16
  public_class_method def self.scan(opts = {})
19
17
  dir_path = opts[:dir_path]
20
18
  git_repo_root_uri = opts[:git_repo_root_uri].to_s.scrub
21
- result_arr = []
22
- ai_introspection = PWN::Env[:ai][:introspection]
23
- logger_results = "AI Introspection => #{ai_introspection} => "
24
-
25
- PWN::Plugins::FileFu.recurse_in_dir(dir_path: dir_path) do |entry|
26
- if File.file?(entry) && File.basename(entry) !~ /^pwn.+(html|json|db)$/ && File.basename(entry) !~ /\.JS-BEAUTIFIED$/ && entry !~ /test/i
27
- line_no_and_contents_arr = []
28
- entry_beautified = false
29
-
30
- if File.extname(entry) == '.js' && (`wc -l #{entry}`.split.first.to_i < 20 || entry.include?('.min.js') || entry.include?('-all.js'))
31
- js_beautify = `js-beautify #{entry} > #{entry}.JS-BEAUTIFIED 2> /dev/null`.to_s.scrub
32
- entry = "#{entry}.JS-BEAUTIFIED"
33
- entry_beautified = true
34
- end
35
-
36
- test_case_filter = "
37
- grep -niE \
38
- -e 'ec2-' \
39
- -e 'access.key' \
40
- -e 'secret.access' \
41
- -e 'secret.key' #{entry} 2> /dev/null
42
- "
43
-
44
- str = `#{test_case_filter}`.to_s.scrub
45
-
46
- if str.to_s.empty?
47
- # If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
48
- logger_results = "#{logger_results}~" # Catching bugs is good :)
49
- else
50
- str = "1:Result larger than 64KB -> Size: #{str.to_s.length}. Please click the \"Path\" link for more details." if str.to_s.length >= 64_000
51
19
 
52
- hash_line = {
53
- timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
54
- security_references: security_references,
55
- filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
56
- line_no_and_contents: '',
57
- raw_content: str,
58
- test_case_filter: test_case_filter
59
- }
60
-
61
- # COMMMENT: Must be a better way to implement this (regex is kinda funky)
62
- line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
63
- line_no_count = line_contents_split.length # This should always be an even number
64
- current_count = 0
65
- while line_no_count > current_count
66
- line_no = line_contents_split[current_count]
67
- contents = line_contents_split[current_count + 1]
68
- if Dir.exist?('.git')
69
- repo_root = '.'
70
-
71
- author = PWN::Plugins::Git.get_author(
72
- repo_root: repo_root,
73
- from_line: line_no,
74
- to_line: line_no,
75
- target_file: entry,
76
- entry_beautified: entry_beautified
77
- )
78
- end
79
- author ||= 'N/A'
80
-
81
- ai_analysis = nil
82
- if ai_introspection
83
- request = {
84
- scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
85
- line_no: line_no,
86
- source_code_snippet: contents
87
- }.to_json
88
- response = PWN::AI::Introspection.reflect(request: request)
89
- if response.is_a?(Hash)
90
- ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
91
- ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
92
- end
93
- end
94
-
95
- hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
96
- line_no: line_no,
97
- contents: contents,
98
- author: author,
99
- ai_analysis: ai_analysis
100
- )
20
+ test_case_filter = "
21
+ grep -niE \
22
+ -e 'ec2-' \
23
+ -e 'access.key' \
24
+ -e 'secret.access' \
25
+ -e 'secret.key' {PWN_SAST_SRC_TARGET} 2> /dev/null
26
+ "
101
27
 
102
- current_count += 2
103
- end
104
- result_arr.push(hash_line)
105
- logger_results = "#{logger_results}x" # Seeing progress is good :)
106
- end
107
- end
108
- end
109
- logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
110
- if logger_results.empty?
111
- @@logger.info("#{logger_banner}: No files applicable to this test case.\n")
112
- else
113
- @@logger.info("#{logger_banner} => #{logger_results}complete.\n")
114
- end
115
- result_arr
28
+ PWN::SAST::TestCaseEngine.execute(
29
+ test_case_filter: test_case_filter,
30
+ security_references: security_references,
31
+ dir_path: dir_path,
32
+ git_repo_root_uri: git_repo_root_uri
33
+ )
116
34
  rescue StandardError => e
117
35
  raise e
118
36
  end