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
@@ -8,8 +8,6 @@ module PWN
|
|
8
8
|
# SAST Module used to identify hard-code/plain-text
|
9
9
|
# passwords within source code.
|
10
10
|
module HTTPAuthorizationHeader
|
11
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
12
|
-
|
13
11
|
# Supported Method Parameters::
|
14
12
|
# PWN::SAST::HTTPAuthorizationHeader.scan(
|
15
13
|
# :dir_path => 'optional path to dir defaults to .'
|
@@ -19,107 +17,27 @@ 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 -Ein \
|
39
|
-
-e "Authorization:(\\sBasic|Basic)" \
|
40
|
-
-e "Authorization:(\\sBearer|Bearer)" \
|
41
|
-
-e "Authorization:(\\sDigest|Digest)" \
|
42
|
-
-e "Authorization:(\\sHOBA|HOBA)" \
|
43
|
-
-e "Authorization:(\\sMutual|Mutual)" \
|
44
|
-
-e "Authorization:(\\sNegotiate|Negotiate)" \
|
45
|
-
-e "Authorization:(\\sVapid|Vapid)" \
|
46
|
-
-e "Authorization:(\\sSCRAM|SCRAM)" \
|
47
|
-
-e "Authorization:(\\sAWS|AWS)" \
|
48
|
-
-e "authorization(\\s=|=)" #{entry} 2> /dev/null
|
49
|
-
)
|
50
|
-
|
51
|
-
str = `#{test_case_filter}`.to_s.scrub
|
52
|
-
|
53
|
-
if str.to_s.empty?
|
54
|
-
# If str length is >= 64 KB do not include results. (Due to Mongo Document Size Restrictions)
|
55
|
-
logger_results = "#{logger_results}~" # Catching bugs is good :)
|
56
|
-
else
|
57
|
-
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
|
58
|
-
|
59
|
-
hash_line = {
|
60
|
-
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S.%9N %z').to_s,
|
61
|
-
security_references: security_references,
|
62
|
-
filename: { git_repo_root_uri: git_repo_root_uri, entry: entry },
|
63
|
-
line_no_and_contents: '',
|
64
|
-
raw_content: str,
|
65
|
-
test_case_filter: test_case_filter
|
66
|
-
}
|
67
|
-
|
68
|
-
# COMMMENT: Must be a better way to implement this (regex is kinda funky)
|
69
|
-
line_contents_split = str.split(/^(\d{1,}):|\n(\d{1,}):/)[1..-1]
|
70
|
-
line_no_count = line_contents_split.length # This should always be an even number
|
71
|
-
current_count = 0
|
72
|
-
while line_no_count > current_count
|
73
|
-
line_no = line_contents_split[current_count]
|
74
|
-
contents = line_contents_split[current_count + 1]
|
75
|
-
if Dir.exist?('.git')
|
76
|
-
repo_root = '.'
|
77
|
-
|
78
|
-
author = PWN::Plugins::Git.get_author(
|
79
|
-
repo_root: repo_root,
|
80
|
-
from_line: line_no,
|
81
|
-
to_line: line_no,
|
82
|
-
target_file: entry,
|
83
|
-
entry_beautified: entry_beautified
|
84
|
-
)
|
85
|
-
end
|
86
|
-
author ||= 'N/A'
|
87
|
-
|
88
|
-
ai_analysis = nil
|
89
|
-
if ai_introspection
|
90
|
-
request = {
|
91
|
-
scm_uri: "#{hash_line[:filename][:git_repo_root_uri]}/#{hash_line[:filename][:entry]}",
|
92
|
-
line_no: line_no,
|
93
|
-
source_code_snippet: contents
|
94
|
-
}.to_json
|
95
|
-
response = PWN::AI::Introspection.reflect(request: request)
|
96
|
-
if response.is_a?(Hash)
|
97
|
-
ai_analysis = response[:choices].last[:text] if response[:choices].last.keys.include?(:text)
|
98
|
-
ai_analysis = response[:choices].last[:content] if response[:choices].last.keys.include?(:content)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
hash_line[:line_no_and_contents] = line_no_and_contents_arr.push(
|
103
|
-
line_no: line_no,
|
104
|
-
contents: contents,
|
105
|
-
author: author,
|
106
|
-
ai_analysis: ai_analysis
|
107
|
-
)
|
108
20
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
21
|
+
test_case_filter = %(
|
22
|
+
grep -Ein \
|
23
|
+
-e "Authorization:(\\sBasic|Basic)" \
|
24
|
+
-e "Authorization:(\\sBearer|Bearer)" \
|
25
|
+
-e "Authorization:(\\sDigest|Digest)" \
|
26
|
+
-e "Authorization:(\\sHOBA|HOBA)" \
|
27
|
+
-e "Authorization:(\\sMutual|Mutual)" \
|
28
|
+
-e "Authorization:(\\sNegotiate|Negotiate)" \
|
29
|
+
-e "Authorization:(\\sVapid|Vapid)" \
|
30
|
+
-e "Authorization:(\\sSCRAM|SCRAM)" \
|
31
|
+
-e "Authorization:(\\sAWS|AWS)" \
|
32
|
+
-e "authorization(\\s=|=)" {PWN_SAST_SRC_TARGET} 2> /dev/null
|
33
|
+
)
|
34
|
+
|
35
|
+
PWN::SAST::TestCaseEngine.execute(
|
36
|
+
test_case_filter: test_case_filter,
|
37
|
+
security_references: security_references,
|
38
|
+
dir_path: dir_path,
|
39
|
+
git_repo_root_uri: git_repo_root_uri
|
40
|
+
)
|
123
41
|
end
|
124
42
|
|
125
43
|
# Used primarily to map NIST 800-53 Revision 4 Security Controls
|
data/lib/pwn/sast/inner_html.rb
CHANGED
@@ -9,8 +9,6 @@ module PWN
|
|
9
9
|
# declarations within source code in an effort to
|
10
10
|
# determine if XSS is possible
|
11
11
|
module InnerHTML
|
12
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
13
|
-
|
14
12
|
# Supported Method Parameters::
|
15
13
|
# PWN::SAST::InnerHTML.scan(
|
16
14
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -20,98 +18,18 @@ 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 -n \
|
40
|
-
-e 'innerHTML' #{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
21
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
)
|
22
|
+
test_case_filter = "
|
23
|
+
grep -n \
|
24
|
+
-e 'innerHTML' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
25
|
+
"
|
100
26
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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/keystore.rb
CHANGED
@@ -8,8 +8,6 @@ module PWN
|
|
8
8
|
# SAST Module used to identify weak
|
9
9
|
# passwords/configurations around key stores.
|
10
10
|
module Keystore
|
11
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
12
|
-
|
13
11
|
# Supported Method Parameters::
|
14
12
|
# PWN::SAST::Keystore.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 -Fin \
|
39
|
-
-e 'keystore' #{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 -Fin \
|
23
|
+
-e 'keystore' {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.mesasge
|
116
34
|
end
|
@@ -9,8 +9,6 @@ module PWN
|
|
9
9
|
# declarations within source code in an effort to
|
10
10
|
# determine if XSS is possible
|
11
11
|
module LocalStorage
|
12
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
13
|
-
|
14
12
|
# Supported Method Parameters::
|
15
13
|
# PWN::SAST::LocalStorage.scan(
|
16
14
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -20,99 +18,19 @@ 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 -n \
|
40
|
-
-e 'localStorage.getItem(' \
|
41
|
-
-e 'localStorage.setItem(' #{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
21
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
)
|
22
|
+
test_case_filter = "
|
23
|
+
grep -n \
|
24
|
+
-e 'localStorage.getItem(' \
|
25
|
+
-e 'localStorage.setItem(' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
26
|
+
"
|
101
27
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
@@ -9,8 +9,6 @@ module PWN
|
|
9
9
|
# declarations within source code in an effort to
|
10
10
|
# determine if XSS is possible
|
11
11
|
module LocationHash
|
12
|
-
@@logger = PWN::Plugins::PWNLogger.create
|
13
|
-
|
14
12
|
# Supported Method Parameters::
|
15
13
|
# PWN::SAST::LocationHash.scan(
|
16
14
|
# dir_path: 'optional path to dir defaults to .'
|
@@ -20,98 +18,18 @@ 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 -n \
|
40
|
-
-e 'location.hash' #{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
21
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
)
|
22
|
+
test_case_filter = "
|
23
|
+
grep -n \
|
24
|
+
-e 'location.hash' {PWN_SAST_SRC_TARGET} 2> /dev/null
|
25
|
+
"
|
100
26
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|