pwn 0.5.441 → 0.5.443
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/lib/pwn/plugins/repl.rb +3 -5
- data/lib/pwn/sast/amqp_connect_as_guest.rb +12 -89
- data/lib/pwn/sast/apache_file_system_util_api.rb +11 -91
- data/lib/pwn/sast/aws.rb +13 -93
- data/lib/pwn/sast/banned_function_calls_c.rb +138 -218
- data/lib/pwn/sast/base64.rb +12 -90
- data/lib/pwn/sast/beef_hook.rb +10 -90
- data/lib/pwn/sast/cmd_execution_java.rb +12 -92
- data/lib/pwn/sast/cmd_execution_python.rb +14 -94
- data/lib/pwn/sast/cmd_execution_ruby.rb +22 -102
- data/lib/pwn/sast/cmd_execution_scala.rb +12 -92
- data/lib/pwn/sast/csrf.rb +10 -90
- data/lib/pwn/sast/deserial_java.rb +17 -97
- data/lib/pwn/sast/emoticon.rb +17 -98
- data/lib/pwn/sast/eval.rb +10 -90
- data/lib/pwn/sast/factory.rb +12 -92
- data/lib/pwn/sast/http_authorization_header.rb +20 -100
- data/lib/pwn/sast/inner_html.rb +10 -90
- data/lib/pwn/sast/keystore.rb +10 -90
- data/lib/pwn/sast/local_storage.rb +11 -91
- data/lib/pwn/sast/location_hash.rb +10 -90
- data/lib/pwn/sast/log4j.rb +10 -90
- data/lib/pwn/sast/logger.rb +24 -104
- data/lib/pwn/sast/md5.rb +10 -90
- data/lib/pwn/sast/outer_html.rb +10 -90
- data/lib/pwn/sast/padding_oracle.rb +11 -91
- data/lib/pwn/sast/password.rb +15 -95
- data/lib/pwn/sast/php_input_mechanisms.rb +16 -96
- data/lib/pwn/sast/php_type_juggling.rb +14 -94
- data/lib/pwn/sast/pom_version.rb +1 -1
- data/lib/pwn/sast/port.rb +16 -96
- data/lib/pwn/sast/post_message.rb +10 -90
- data/lib/pwn/sast/private_key.rb +10 -90
- data/lib/pwn/sast/redirect.rb +13 -93
- data/lib/pwn/sast/redos.rb +16 -96
- data/lib/pwn/sast/shell.rb +18 -98
- data/lib/pwn/sast/signature.rb +10 -90
- data/lib/pwn/sast/sql.rb +19 -93
- data/lib/pwn/sast/ssl.rb +14 -94
- data/lib/pwn/sast/sudo.rb +10 -90
- data/lib/pwn/sast/task_tag.rb +23 -103
- data/lib/pwn/sast/test_case_engine.rb +147 -0
- data/lib/pwn/sast/throw_errors.rb +14 -94
- data/lib/pwn/sast/token.rb +12 -92
- data/lib/pwn/sast/type_script_type_juggling.rb +14 -94
- data/lib/pwn/sast/version.rb +12 -92
- data/lib/pwn/sast/window_location_hash.rb +10 -90
- data/lib/pwn/sast.rb +4 -0
- data/lib/pwn/version.rb +1 -1
- data/lib/pwn.rb +0 -2
- data/spec/lib/pwn/sast/test_case_engine_spec.rb +20 -0
- data/third_party/pwn_rdoc.jsonl +1 -1
- metadata +5 -3
@@ -20,226 +20,146 @@ module PWN
|
|
20
20
|
public_class_method def self.scan(opts = {})
|
21
21
|
dir_path = opts[:dir_path]
|
22
22
|
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
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
-e 'IsBadWritePtr' \
|
160
|
-
-e 'IsBadHugeWritePtr' \
|
161
|
-
-e 'IsBadReadPtr' \
|
162
|
-
-e 'IsBadHugeReadPtr' \
|
163
|
-
-e 'IsBadCodePtr' \
|
164
|
-
-e 'IsBadStringPtr' \
|
165
|
-
-e 'memcpy' \
|
166
|
-
-e 'RtlCopyMemory' \
|
167
|
-
-e 'CopyMemory' \
|
168
|
-
-e 'wmemcpy' #{entry} 2> /dev/null
|
169
|
-
"
|
170
|
-
|
171
|
-
str = `#{test_case_filter}`.to_s.scrub
|
172
|
-
|
173
|
-
if str.to_s.empty?
|
174
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
175
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
176
|
-
else
|
177
|
-
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
|
178
|
-
|
179
|
-
hash_line = {
|
180
|
-
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
|
181
|
-
security_references: security_references,
|
182
|
-
filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
|
183
|
-
line_no_and_contents: '',
|
184
|
-
raw_content: str,
|
185
|
-
test_case_filter: test_case_filter
|
186
|
-
}
|
187
|
-
|
188
|
-
# COMMMENT: Must be a better way to implement this (regex is kinda funky)
|
189
|
-
line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
|
190
|
-
line_no_count = line_contents_split.length # This should always be an even number
|
191
|
-
current_count = 0
|
192
|
-
while line_no_count > current_count
|
193
|
-
line_no = line_contents_split[current_count]
|
194
|
-
contents = line_contents_split[current_count + 1]
|
195
|
-
if Dir.exist?('.git')
|
196
|
-
repo_root = '.'
|
197
|
-
|
198
|
-
author = PWN::Plugins::Git.get_author(
|
199
|
-
repo_root: repo_root,
|
200
|
-
from_line: line_no,
|
201
|
-
to_line: line_no,
|
202
|
-
target_file: entry,
|
203
|
-
entry_beautified: entry_beautified
|
204
|
-
)
|
205
|
-
end
|
206
|
-
author ||= 'N/A'
|
207
|
-
|
208
|
-
ai_analysis = nil
|
209
|
-
if ai_introspection
|
210
|
-
request = {
|
211
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
212
|
-
line_no: line_no,
|
213
|
-
source_code_snippet: contents
|
214
|
-
}.to_json
|
215
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
216
|
-
if response.is_a?(Hash)
|
217
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
218
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
223
|
-
line_no: line_no,
|
224
|
-
contents: contents,
|
225
|
-
author: author,
|
226
|
-
ai_analysis: ai_analysis
|
227
|
-
)
|
24
|
+
test_case_filter = "
|
25
|
+
grep -Fn \
|
26
|
+
-e 'strcpy' \
|
27
|
+
-e 'strcpyA' \
|
28
|
+
-e 'strcpyW' \
|
29
|
+
-e 'wcscpy' \
|
30
|
+
-e '_tcscpy' \
|
31
|
+
-e '_mbscpy' \
|
32
|
+
-e 'StrCpy' \
|
33
|
+
-e 'StrCpyA' \
|
34
|
+
-e 'StrCpyW' \
|
35
|
+
-e 'lstrcpy' \
|
36
|
+
-e 'lstrcpyA' \
|
37
|
+
-e 'lstrcpyW' \
|
38
|
+
-e '_tccpy' \
|
39
|
+
-e '_mbccpy' \
|
40
|
+
-e '_ftcscpy' \
|
41
|
+
-e 'strncpy' \
|
42
|
+
-e 'wcsncpy' \
|
43
|
+
-e '_tcsncpy' \
|
44
|
+
-e '_mbsncpy' \
|
45
|
+
-e '_mbsnbcpy' \
|
46
|
+
-e 'StrCpyN' \
|
47
|
+
-e 'StrCpyNA' \
|
48
|
+
-e 'StrCpyNW' \
|
49
|
+
-e 'StrNCpy' \
|
50
|
+
-e 'strcpynA' \
|
51
|
+
-e 'StrNCpyA' \
|
52
|
+
-e 'StrNCpyW' \
|
53
|
+
-e 'lstrcpyn' \
|
54
|
+
-e 'lstrcpynA' \
|
55
|
+
-e 'lstrcpynW' \
|
56
|
+
-e 'strcat' \
|
57
|
+
-e 'strcatA' \
|
58
|
+
-e 'strcatW' \
|
59
|
+
-e 'wcscat' \
|
60
|
+
-e '_tcscat' \
|
61
|
+
-e '_mbscat' \
|
62
|
+
-e 'StrCat' \
|
63
|
+
-e 'StrCatA' \
|
64
|
+
-e 'StrCatW' \
|
65
|
+
-e 'lstrcat' \
|
66
|
+
-e 'lstrcatA' \
|
67
|
+
-e 'lstrcatW' \
|
68
|
+
-e 'StrCatBuff' \
|
69
|
+
-e 'StrCatBuffA' \
|
70
|
+
-e 'StrCatBuffW' \
|
71
|
+
-e 'StrCatChainW' \
|
72
|
+
-e '_tccat' \
|
73
|
+
-e '_mbccat' \
|
74
|
+
-e '_ftcscat' \
|
75
|
+
-e 'strncat' \
|
76
|
+
-e 'wcsncat' \
|
77
|
+
-e '_tcsncat' \
|
78
|
+
-e '_mbsncat' \
|
79
|
+
-e '_mbsnbcat' \
|
80
|
+
-e 'StrCatN' \
|
81
|
+
-e 'StrCatNA' \
|
82
|
+
-e 'StrCatNW' \
|
83
|
+
-e 'StrNCat' \
|
84
|
+
-e 'StrNCatA' \
|
85
|
+
-e 'StrNCatW' \
|
86
|
+
-e 'lstrncat' \
|
87
|
+
-e 'lstrcatnA' \
|
88
|
+
-e 'lstrcatnW' \
|
89
|
+
-e 'lstrcatn' \
|
90
|
+
-e 'sprintfW' \
|
91
|
+
-e 'sprintfA' \
|
92
|
+
-e 'wsprintf' \
|
93
|
+
-e 'wsprintfW' \
|
94
|
+
-e 'wsprintfA' \
|
95
|
+
-e 'sprintf' \
|
96
|
+
-e 'swprintf' \
|
97
|
+
-e '_stprintf' \
|
98
|
+
-e 'wvsprintf' \
|
99
|
+
-e 'wvsprintfA' \
|
100
|
+
-e 'wvsprintfW' \
|
101
|
+
-e 'vsprintf' \
|
102
|
+
-e '_vstprintf' \
|
103
|
+
-e 'vswprintf' \
|
104
|
+
-e 'wvsprintf' \
|
105
|
+
-e 'wvsprintfA' \
|
106
|
+
-e 'wvsprintfW' \
|
107
|
+
-e 'vsprintf' \
|
108
|
+
-e '_vstprintf' \
|
109
|
+
-e 'vswprintf' \
|
110
|
+
-e 'strncpy' \
|
111
|
+
-e 'wcsncpy' \
|
112
|
+
-e '_tcsncpy' \
|
113
|
+
-e '_mbsncpy' \
|
114
|
+
-e '_mbsnbcpy' \
|
115
|
+
-e 'StrCpyN' \
|
116
|
+
-e 'StrCpyNA' \
|
117
|
+
-e 'StrCpyNW' \
|
118
|
+
-e 'StrNCpy' \
|
119
|
+
-e 'strcpynA' \
|
120
|
+
-e 'StrNCpyA' \
|
121
|
+
-e 'StrNCpyW' \
|
122
|
+
-e 'lstrcpyn' \
|
123
|
+
-e 'lstrcpynA' \
|
124
|
+
-e 'lstrcpynW' \
|
125
|
+
-e '_fstrncpy' \
|
126
|
+
-e 'strncat' \
|
127
|
+
-e 'wcsncat' \
|
128
|
+
-e '_tcsncat' \
|
129
|
+
-e '_mbsncat' \
|
130
|
+
-e '_mbsnbcat' \
|
131
|
+
-e 'StrCatN' \
|
132
|
+
-e 'StrCatNA' \
|
133
|
+
-e 'StrCatNW' \
|
134
|
+
-e 'StrNCat' \
|
135
|
+
-e 'StrNCatA' \
|
136
|
+
-e 'StrNCatW' \
|
137
|
+
-e 'lstrncat' \
|
138
|
+
-e 'lstrcatnA' \
|
139
|
+
-e 'lstrcatnW' \
|
140
|
+
-e 'lstrcatn' \
|
141
|
+
-e '_fstrncat' \
|
142
|
+
-e 'gets' \
|
143
|
+
-e '_getts' \
|
144
|
+
-e '_gettws' \
|
145
|
+
-e 'IsBadWritePtr' \
|
146
|
+
-e 'IsBadHugeWritePtr' \
|
147
|
+
-e 'IsBadReadPtr' \
|
148
|
+
-e 'IsBadHugeReadPtr' \
|
149
|
+
-e 'IsBadCodePtr' \
|
150
|
+
-e 'IsBadStringPtr' \
|
151
|
+
-e 'memcpy' \
|
152
|
+
-e 'RtlCopyMemory' \
|
153
|
+
-e 'CopyMemory' \
|
154
|
+
-e 'wmemcpy' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
155
|
+
"
|
228
156
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
236
|
-
logger_banner = "http://#{Socket.gethostname}:8808/doc_root/pwn-#{PWN::VERSION.to_s.scrub}/#{to_s.scrub.gsub('::', '/')}.html"
|
237
|
-
if logger_results.empty?
|
238
|
-
@@logger.info("#{logger_banner}: No files applicable to this test case.\n")
|
239
|
-
else
|
240
|
-
@@logger.info("#{logger_banner} => #{logger_results}complete.\n")
|
241
|
-
end
|
242
|
-
result_arr
|
157
|
+
PWN::SAST::TestCaseEngine.execute(
|
158
|
+
test_case_filter: test_case_filter,
|
159
|
+
security_references: security_references,
|
160
|
+
dir_path: dir_path,
|
161
|
+
git_repo_root_uri: git_repo_root_uri
|
162
|
+
)
|
243
163
|
rescue StandardError => e
|
244
164
|
raise e
|
245
165
|
end
|
data/lib/pwn/sast/base64.rb
CHANGED
@@ -19,98 +19,20 @@ module PWN
|
|
19
19
|
public_class_method def self.scan(opts = {})
|
20
20
|
dir_path = opts[:dir_path]
|
21
21
|
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
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
# TODO: Include regex to search for Base64 strings
|
38
|
-
test_case_filter = "
|
39
|
-
grep -Ein \
|
40
|
-
-e 'BASE64' #{entry} 2> /dev/null
|
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
|
-
|
50
|
-
hash_line = {
|
51
|
-
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
|
52
|
-
security_references: security_references,
|
53
|
-
filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
|
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
|
-
)
|
23
|
+
test_case_filter = "
|
24
|
+
grep -Ein \
|
25
|
+
-e 'BASE64' \
|
26
|
+
-e '^[A-Za-z0-9+/]{4}([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$' \
|
27
|
+
{PWN_SAST_SRC_TARGET} 2> /dev/null
|
28
|
+
"
|
99
29
|
|
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
|
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
|
+
)
|
114
36
|
rescue StandardError => e
|
115
37
|
raise e
|
116
38
|
end
|
data/lib/pwn/sast/beef_hook.rb
CHANGED
@@ -19,98 +19,18 @@ module PWN
|
|
19
19
|
public_class_method def self.scan(opts = {})
|
20
20
|
dir_path = opts[:dir_path]
|
21
21
|
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
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 'hook.js' #{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
|
-
|
50
|
-
hash_line = {
|
51
|
-
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
|
52
|
-
security_references: security_references,
|
53
|
-
filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
|
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
|
-
)
|
23
|
+
test_case_filter = "
|
24
|
+
grep -Fin \
|
25
|
+
-e 'hook.js' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
26
|
+
"
|
99
27
|
|
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
|
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
|
+
)
|
114
34
|
rescue StandardError => e
|
115
35
|
raise e
|
116
36
|
end
|