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.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +3 -3
- data/bin/pwn_sast +1 -0
- data/lib/pwn/plugins/file_fu.rb +20 -22
- data/lib/pwn/sast/amqp_connect_as_guest.rb +12 -91
- data/lib/pwn/sast/apache_file_system_util_api.rb +11 -93
- data/lib/pwn/sast/aws.rb +13 -95
- data/lib/pwn/sast/banned_function_calls_c.rb +140 -219
- data/lib/pwn/sast/base64.rb +12 -92
- data/lib/pwn/sast/beef_hook.rb +10 -92
- data/lib/pwn/sast/cmd_execution_go_lang.rb +83 -0
- data/lib/pwn/sast/cmd_execution_java.rb +14 -93
- data/lib/pwn/sast/cmd_execution_python.rb +16 -95
- data/lib/pwn/sast/cmd_execution_ruby.rb +24 -103
- data/lib/pwn/sast/cmd_execution_scala.rb +14 -93
- data/lib/pwn/sast/csrf.rb +10 -92
- data/lib/pwn/sast/deserial_java.rb +19 -98
- data/lib/pwn/sast/emoticon.rb +17 -100
- data/lib/pwn/sast/eval.rb +10 -92
- data/lib/pwn/sast/factory.rb +15 -95
- data/lib/pwn/sast/http_authorization_header.rb +20 -102
- data/lib/pwn/sast/inner_html.rb +10 -92
- data/lib/pwn/sast/keystore.rb +10 -92
- data/lib/pwn/sast/local_storage.rb +11 -93
- data/lib/pwn/sast/location_hash.rb +10 -92
- data/lib/pwn/sast/log4j.rb +12 -91
- data/lib/pwn/sast/logger.rb +24 -106
- data/lib/pwn/sast/md5.rb +10 -92
- data/lib/pwn/sast/outer_html.rb +10 -92
- data/lib/pwn/sast/padding_oracle.rb +11 -93
- data/lib/pwn/sast/password.rb +15 -97
- data/lib/pwn/sast/php_input_mechanisms.rb +18 -97
- data/lib/pwn/sast/php_type_juggling.rb +16 -95
- data/lib/pwn/sast/pom_version.rb +1 -3
- data/lib/pwn/sast/port.rb +16 -98
- data/lib/pwn/sast/post_message.rb +10 -92
- data/lib/pwn/sast/private_key.rb +10 -92
- data/lib/pwn/sast/redirect.rb +13 -95
- data/lib/pwn/sast/redos.rb +16 -98
- data/lib/pwn/sast/shell.rb +18 -100
- data/lib/pwn/sast/signature.rb +10 -92
- data/lib/pwn/sast/sql.rb +19 -95
- data/lib/pwn/sast/ssl.rb +14 -96
- data/lib/pwn/sast/sudo.rb +10 -92
- data/lib/pwn/sast/task_tag.rb +23 -105
- data/lib/pwn/sast/test_case_engine.rb +188 -0
- data/lib/pwn/sast/throw_errors.rb +14 -96
- data/lib/pwn/sast/token.rb +12 -94
- data/lib/pwn/sast/type_script_type_juggling.rb +16 -95
- data/lib/pwn/sast/version.rb +12 -94
- data/lib/pwn/sast/window_location_hash.rb +10 -92
- data/lib/pwn/sast.rb +5 -0
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn.rb +0 -2
- data/spec/lib/pwn/sast/cmd_execution_go_lang_spec.rb +25 -0
- data/spec/lib/pwn/sast/test_case_engine_spec.rb +20 -0
- data/third_party/pwn_rdoc.jsonl +1 -1
- metadata +7 -3
data/lib/pwn/sast/sql.rb
CHANGED
@@ -9,8 +9,6 @@ module PWN
|
|
9
9
|
# reference within source code that may contain SQL to
|
10
10
|
# determine if SQL injeciton is possible.
|
11
11
|
module SQL
|
12
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
13
|
-
|
14
12
|
# Supported Method Parameters::
|
15
13
|
# PWN::SAST::SQL.scan(
|
16
14
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -20,101 +18,27 @@ 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 'select .*from ' \
|
41
|
-
-e 'insert into .*values' \
|
42
|
-
-e 'update .*set ' \
|
43
|
-
-e 'delete from ' #{entry} 2> /dev/null
|
44
|
-
"
|
45
|
-
|
46
|
-
str = `#{test_case_filter}`.to_s.scrub
|
47
|
-
|
48
|
-
if str.to_s.empty?
|
49
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
50
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
51
|
-
else
|
52
|
-
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
|
53
21
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
while line_no_count > current_count
|
68
|
-
line_no = line_contents_split[current_count]
|
69
|
-
contents = line_contents_split[current_count + 1]
|
70
|
-
if Dir.exist?('.git')
|
71
|
-
repo_root = '.'
|
72
|
-
|
73
|
-
author = PWN::Plugins::Git.get_author(
|
74
|
-
repo_root: repo_root,
|
75
|
-
from_line: line_no,
|
76
|
-
to_line: line_no,
|
77
|
-
target_file: entry,
|
78
|
-
entry_beautified: entry_beautified
|
79
|
-
)
|
80
|
-
end
|
81
|
-
author ||= 'N/A'
|
82
|
-
|
83
|
-
ai_analysis = nil
|
84
|
-
if ai_introspection
|
85
|
-
request = {
|
86
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
87
|
-
line_no: line_no,
|
88
|
-
source_code_snippet: contents
|
89
|
-
}.to_json
|
90
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
91
|
-
if response.is_a?(Hash)
|
92
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
93
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
98
|
-
line_no: line_no,
|
99
|
-
contents: contents,
|
100
|
-
author: author,
|
101
|
-
ai_analysis: ai_analysis
|
102
|
-
)
|
22
|
+
test_case_filter = "
|
23
|
+
grep -in \
|
24
|
+
-e 'select .*from ' \
|
25
|
+
-e 'insert into .*values' \
|
26
|
+
-e 'update .*set ' \
|
27
|
+
-e 'delete from ' {PWN_SAST_SRC_TARGET} 2> /dev/null | \
|
28
|
+
grep -ivE \
|
29
|
+
-e '^[0-9]:.*\\?.*$' \
|
30
|
+
-e '^[0-9]:.*@.*$' \
|
31
|
+
-e '^[0-9]:.*\\$[0-9].*$' \
|
32
|
+
-e '^[0-9]:.*:[0-9].*$' \
|
33
|
+
-e '^[0-9]:.*:[a-zA-Z_][a-zA-Z0-9_].*$'
|
34
|
+
"
|
103
35
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
|
112
|
-
if logger_results.empty?
|
113
|
-
@@logger.info("#{logger_banner}: No files applicable to this test case.\n")
|
114
|
-
else
|
115
|
-
@@logger.info("#{logger_banner} => #{logger_results}complete.\n")
|
116
|
-
end
|
117
|
-
result_arr
|
36
|
+
PWN::SAST::TestCaseEngine.execute(
|
37
|
+
test_case_filter: test_case_filter,
|
38
|
+
security_references: security_references,
|
39
|
+
dir_path: dir_path,
|
40
|
+
git_repo_root_uri: git_repo_root_uri
|
41
|
+
)
|
118
42
|
rescue StandardError => e
|
119
43
|
raise e
|
120
44
|
end
|
data/lib/pwn/sast/ssl.rb
CHANGED
@@ -8,8 +8,6 @@ module PWN
|
|
8
8
|
# SAST Module used to identify any SSL/TLS
|
9
9
|
# reference within source code.
|
10
10
|
module SSL
|
11
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
12
|
-
|
13
11
|
# Supported Method Parameters::
|
14
12
|
# PWN::SAST::SSL.scan(
|
15
13
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -19,102 +17,22 @@ 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 -Fin \
|
39
|
-
-e 'ssl' \
|
40
|
-
-e 'tls' \
|
41
|
-
-e 'trustAll' \
|
42
|
-
-e 'trustmanager' \
|
43
|
-
-e 'ssl_version' #{entry} 2> /dev/null
|
44
|
-
"
|
45
|
-
|
46
|
-
str = `#{test_case_filter}`.to_s.scrub
|
47
|
-
|
48
|
-
if str.to_s.empty?
|
49
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
50
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
51
|
-
else
|
52
|
-
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
|
53
20
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
# COMMMENT: Must be a better way to implement this (regex is kinda funky)
|
64
|
-
line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
|
65
|
-
line_no_count = line_contents_split.length # This should always be an even number
|
66
|
-
current_count = 0
|
67
|
-
while line_no_count > current_count
|
68
|
-
line_no = line_contents_split[current_count]
|
69
|
-
contents = line_contents_split[current_count + 1]
|
70
|
-
if Dir.exist?('.git')
|
71
|
-
repo_root = '.'
|
72
|
-
|
73
|
-
author = PWN::Plugins::Git.get_author(
|
74
|
-
repo_root: repo_root,
|
75
|
-
from_line: line_no,
|
76
|
-
to_line: line_no,
|
77
|
-
target_file: entry,
|
78
|
-
entry_beautified: entry_beautified
|
79
|
-
)
|
80
|
-
end
|
81
|
-
author ||= 'N/A'
|
82
|
-
|
83
|
-
ai_analysis = nil
|
84
|
-
if ai_introspection
|
85
|
-
request = {
|
86
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
87
|
-
line_no: line_no,
|
88
|
-
source_code_snippet: contents
|
89
|
-
}.to_json
|
90
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
91
|
-
if response.is_a?(Hash)
|
92
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
93
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
98
|
-
line_no: line_no,
|
99
|
-
contents: contents,
|
100
|
-
author: author,
|
101
|
-
ai_analysis: ai_analysis
|
102
|
-
)
|
21
|
+
test_case_filter = "
|
22
|
+
grep -Fin \
|
23
|
+
-e 'ssl' \
|
24
|
+
-e 'tls' \
|
25
|
+
-e 'trustAll' \
|
26
|
+
-e 'trustmanager' \
|
27
|
+
-e 'ssl_version' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
28
|
+
"
|
103
29
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
111
|
-
logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
|
112
|
-
if logger_results.empty?
|
113
|
-
@@logger.info("#{logger_banner}: No files applicable to this test case.\n")
|
114
|
-
else
|
115
|
-
@@logger.info("#{logger_banner} => #{logger_results}complete.\n")
|
116
|
-
end
|
117
|
-
result_arr
|
30
|
+
PWN::SAST::TestCaseEngine.execute(
|
31
|
+
test_case_filter: test_case_filter,
|
32
|
+
security_references: security_references,
|
33
|
+
dir_path: dir_path,
|
34
|
+
git_repo_root_uri: git_repo_root_uri
|
35
|
+
)
|
118
36
|
rescue StandardError => e
|
119
37
|
raise e
|
120
38
|
end
|
data/lib/pwn/sast/sudo.rb
CHANGED
@@ -8,8 +8,6 @@ module PWN
|
|
8
8
|
# SAST Module used to identify if cmd execution and/or
|
9
9
|
# privilege escalation is possible.
|
10
10
|
module Sudo
|
11
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
12
|
-
|
13
11
|
# Supported Method Parameters::
|
14
12
|
# PWN::SAST::Sudo.scan(
|
15
13
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -19,98 +17,18 @@ 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 -niE \
|
39
|
-
-e 'sudo' #{entry} 2> /dev/null
|
40
|
-
"
|
41
|
-
|
42
|
-
str = `#{test_case_filter}`.to_s.scrub
|
43
|
-
|
44
|
-
if str.to_s.empty?
|
45
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
46
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
47
|
-
else
|
48
|
-
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
|
49
20
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
line_no_and_contents: '',
|
55
|
-
raw_content: str,
|
56
|
-
test_case_filter: test_case_filter
|
57
|
-
}
|
58
|
-
|
59
|
-
# COMMMENT: Must be a better way to implement this (regex is kinda funky)
|
60
|
-
line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
|
61
|
-
line_no_count = line_contents_split.length # This should always be an even number
|
62
|
-
current_count = 0
|
63
|
-
while line_no_count > current_count
|
64
|
-
line_no = line_contents_split[current_count]
|
65
|
-
contents = line_contents_split[current_count + 1]
|
66
|
-
if Dir.exist?('.git')
|
67
|
-
repo_root = '.'
|
68
|
-
|
69
|
-
author = PWN::Plugins::Git.get_author(
|
70
|
-
repo_root: repo_root,
|
71
|
-
from_line: line_no,
|
72
|
-
to_line: line_no,
|
73
|
-
target_file: entry,
|
74
|
-
entry_beautified: entry_beautified
|
75
|
-
)
|
76
|
-
end
|
77
|
-
author ||= 'N/A'
|
78
|
-
|
79
|
-
ai_analysis = nil
|
80
|
-
if ai_introspection
|
81
|
-
request = {
|
82
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
83
|
-
line_no: line_no,
|
84
|
-
source_code_snippet: contents
|
85
|
-
}.to_json
|
86
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
87
|
-
if response.is_a?(Hash)
|
88
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
89
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
94
|
-
line_no: line_no,
|
95
|
-
contents: contents,
|
96
|
-
author: author,
|
97
|
-
ai_analysis: ai_analysis
|
98
|
-
)
|
21
|
+
test_case_filter = "
|
22
|
+
grep -niE \
|
23
|
+
-e 'sudo' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
24
|
+
"
|
99
25
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
26
|
+
PWN::SAST::TestCaseEngine.execute(
|
27
|
+
test_case_filter: test_case_filter,
|
28
|
+
security_references: security_references,
|
29
|
+
dir_path: dir_path,
|
30
|
+
git_repo_root_uri: git_repo_root_uri
|
31
|
+
)
|
114
32
|
rescue StandardError => e
|
115
33
|
raise e
|
116
34
|
end
|
data/lib/pwn/sast/task_tag.rb
CHANGED
@@ -9,8 +9,6 @@ module PWN
|
|
9
9
|
# such as TODO, SECURITY, FIXME, etc to ensure developers
|
10
10
|
# aren't introducing security-related bugs into source code.
|
11
11
|
module TaskTag
|
12
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
13
|
-
|
14
12
|
# Supported Method Parameters::
|
15
13
|
# PWN::SAST::TaskTag.scan(
|
16
14
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -20,111 +18,31 @@ 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 -Fin \
|
40
|
-
-e '//' \
|
41
|
-
-e '<!--' \
|
42
|
-
-e '/**' \
|
43
|
-
-e '#' #{entry} 2> /dev/null | \
|
44
|
-
grep -i \
|
45
|
-
-e SECURITY \
|
46
|
-
-e TODO \
|
47
|
-
-e FIXME \
|
48
|
-
-e XXX \
|
49
|
-
-e CHECKME \
|
50
|
-
-e DOCME \
|
51
|
-
-e TESTME \
|
52
|
-
-e PENDING \
|
53
|
-
-e DISCUSS | grep -v '://'
|
54
|
-
"
|
55
|
-
|
56
|
-
str = `#{test_case_filter}`.to_s.scrub
|
57
|
-
|
58
|
-
if str.to_s.empty?
|
59
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
60
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
61
|
-
else
|
62
|
-
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
|
63
21
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
repo_root = '.'
|
82
|
-
|
83
|
-
author = PWN::Plugins::Git.get_author(
|
84
|
-
repo_root: repo_root,
|
85
|
-
from_line: line_no,
|
86
|
-
to_line: line_no,
|
87
|
-
target_file: entry,
|
88
|
-
entry_beautified: entry_beautified
|
89
|
-
)
|
90
|
-
end
|
91
|
-
author ||= 'N/A'
|
92
|
-
|
93
|
-
ai_analysis = nil
|
94
|
-
if ai_introspection
|
95
|
-
request = {
|
96
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
97
|
-
line_no: line_no,
|
98
|
-
source_code_snippet: contents
|
99
|
-
}.to_json
|
100
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
101
|
-
if response.is_a?(Hash)
|
102
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
103
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
108
|
-
line_no: line_no,
|
109
|
-
contents: contents,
|
110
|
-
author: author,
|
111
|
-
ai_analysis: ai_analysis
|
112
|
-
)
|
22
|
+
test_case_filter = "
|
23
|
+
grep -Fin \
|
24
|
+
-e '//' \
|
25
|
+
-e '<!--' \
|
26
|
+
-e '/**' \
|
27
|
+
-e '#' {PWN_SAST_SRC_TARGET} 2> /dev/null | \
|
28
|
+
grep -i \
|
29
|
+
-e SECURITY \
|
30
|
+
-e TODO \
|
31
|
+
-e FIXME \
|
32
|
+
-e XXX \
|
33
|
+
-e CHECKME \
|
34
|
+
-e DOCME \
|
35
|
+
-e TESTME \
|
36
|
+
-e PENDING \
|
37
|
+
-e DISCUSS | grep -v '://'
|
38
|
+
"
|
113
39
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
|
122
|
-
if logger_results.empty?
|
123
|
-
@@logger.info("#{logger_banner}: No files applicable to this test case.\n")
|
124
|
-
else
|
125
|
-
@@logger.info("#{logger_banner} => #{logger_results}complete.\n")
|
126
|
-
end
|
127
|
-
result_arr
|
40
|
+
PWN::SAST::TestCaseEngine.execute(
|
41
|
+
test_case_filter: test_case_filter,
|
42
|
+
security_references: security_references,
|
43
|
+
dir_path: dir_path,
|
44
|
+
git_repo_root_uri: git_repo_root_uri
|
45
|
+
)
|
128
46
|
rescue StandardError => e
|
129
47
|
raise e
|
130
48
|
end
|