Module: PWN::SAST::BannedFunctionCallsC

Defined in:
lib/pwn/sast/banned_function_calls_c.rb

Overview

SAST Module used to identify banned function calls in C & C++ code per: msdn.microsoft.com/en-us/library/bb288454.aspx

Class Method Summary collapse

Class Method Details

.authorsObject

Author(s)

0day Inc. <[email protected]>



187
188
189
190
191
# File 'lib/pwn/sast/banned_function_calls_c.rb', line 187

public_class_method def self.authors
  "AUTHOR(S):
    0day Inc. <[email protected]>
  "
end

.helpObject

Display Usage for this Module



195
196
197
198
199
200
201
202
203
204
# File 'lib/pwn/sast/banned_function_calls_c.rb', line 195

public_class_method def self.help
  puts "USAGE:
    sast_arr = #{self}.scan(
      :dir_path => 'optional path to dir defaults to .',
      :git_repo_root_uri => 'optional http uri of git repo scanned'
    )

    #{self}.authors
  "
end

.scan(opts = {}) ⇒ Object

Supported Method Parameters

PWN::SAST::BannedFunctionCallsC.scan(

:dir_path => 'optional path to dir defaults to .'
:git_repo_root_uri => 'optional http uri of git repo scanned'

)



18
19
20
21
22
23
24
25
26
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
160
161
162
163
164
165
166
# File 'lib/pwn/sast/banned_function_calls_c.rb', line 18

public_class_method def self.scan(opts = {})
  dir_path = opts[:dir_path]
  git_repo_root_uri = opts[:git_repo_root_uri].to_s.scrub

  test_case_filter = "
    grep -Fn \
    -e 'strcpy' \
    -e 'strcpyA' \
    -e 'strcpyW' \
    -e 'wcscpy' \
    -e '_tcscpy' \
    -e '_mbscpy' \
    -e 'StrCpy' \
    -e 'StrCpyA' \
    -e 'StrCpyW' \
    -e 'lstrcpy' \
    -e 'lstrcpyA' \
    -e 'lstrcpyW' \
    -e '_tccpy' \
    -e '_mbccpy' \
    -e '_ftcscpy' \
    -e 'strncpy' \
    -e 'wcsncpy' \
    -e '_tcsncpy' \
    -e '_mbsncpy' \
    -e '_mbsnbcpy' \
    -e 'StrCpyN' \
    -e 'StrCpyNA' \
    -e 'StrCpyNW' \
    -e 'StrNCpy' \
    -e 'strcpynA' \
    -e 'StrNCpyA' \
    -e 'StrNCpyW' \
    -e 'lstrcpyn' \
    -e 'lstrcpynA' \
    -e 'lstrcpynW' \
    -e 'strcat' \
    -e 'strcatA' \
    -e 'strcatW' \
    -e 'wcscat' \
    -e '_tcscat' \
    -e '_mbscat' \
    -e 'StrCat' \
    -e 'StrCatA' \
    -e 'StrCatW' \
    -e 'lstrcat' \
    -e 'lstrcatA' \
    -e 'lstrcatW' \
    -e 'StrCatBuff' \
    -e 'StrCatBuffA' \
    -e 'StrCatBuffW' \
    -e 'StrCatChainW' \
    -e '_tccat' \
    -e '_mbccat' \
    -e '_ftcscat' \
    -e 'strncat' \
    -e 'wcsncat' \
    -e '_tcsncat' \
    -e '_mbsncat' \
    -e '_mbsnbcat' \
    -e 'StrCatN' \
    -e 'StrCatNA' \
    -e 'StrCatNW' \
    -e 'StrNCat' \
    -e 'StrNCatA' \
    -e 'StrNCatW' \
    -e 'lstrncat' \
    -e 'lstrcatnA' \
    -e 'lstrcatnW' \
    -e 'lstrcatn' \
    -e 'sprintfW' \
    -e 'sprintfA' \
    -e 'wsprintf' \
    -e 'wsprintfW' \
    -e 'wsprintfA' \
    -e 'sprintf' \
    -e 'swprintf' \
    -e '_stprintf' \
    -e 'wvsprintf' \
    -e 'wvsprintfA' \
    -e 'wvsprintfW' \
    -e 'vsprintf' \
    -e '_vstprintf' \
    -e 'vswprintf' \
    -e 'wvsprintf' \
    -e 'wvsprintfA' \
    -e 'wvsprintfW' \
    -e 'vsprintf' \
    -e '_vstprintf' \
    -e 'vswprintf' \
    -e 'strncpy' \
    -e 'wcsncpy' \
    -e '_tcsncpy' \
    -e '_mbsncpy' \
    -e '_mbsnbcpy' \
    -e 'StrCpyN' \
    -e 'StrCpyNA' \
    -e 'StrCpyNW' \
    -e 'StrNCpy' \
    -e 'strcpynA' \
    -e 'StrNCpyA' \
    -e 'StrNCpyW' \
    -e 'lstrcpyn' \
    -e 'lstrcpynA' \
    -e 'lstrcpynW' \
    -e '_fstrncpy' \
    -e 'strncat' \
    -e 'wcsncat' \
    -e '_tcsncat' \
    -e '_mbsncat' \
    -e '_mbsnbcat' \
    -e 'StrCatN' \
    -e 'StrCatNA' \
    -e 'StrCatNW' \
    -e 'StrNCat' \
    -e 'StrNCatA' \
    -e 'StrNCatW' \
    -e 'lstrncat' \
    -e 'lstrcatnA' \
    -e 'lstrcatnW' \
    -e 'lstrcatn' \
    -e '_fstrncat' \
    -e 'gets' \
    -e '_getts' \
    -e '_gettws' \
    -e 'IsBadWritePtr' \
    -e 'IsBadHugeWritePtr' \
    -e 'IsBadReadPtr' \
    -e 'IsBadHugeReadPtr' \
    -e 'IsBadCodePtr' \
    -e 'IsBadStringPtr' \
    -e 'memcpy' \
    -e 'RtlCopyMemory' \
    -e 'CopyMemory' \
    -e 'wmemcpy' {PWN_SAST_SRC_TARGET} 2> /dev/null
  "

  include_extensions = %w[.c .cats .idc .cpp .cc .cxx .c++ .cp .CPP .C .cppm .ixx .h .hpp .hxx .hh .h++ .inc .inl .ipp .tcc .tpp .txx .i .s .asm .o .obj .a .so .lib .dll .exe .pdb .vcxproj .sln .dsp .dsw .cbp .cmake .make .mk]

  PWN::SAST::TestCaseEngine.execute(
    test_case_filter: test_case_filter,
    security_references: security_references,
    dir_path: dir_path,
    include_extensions: include_extensions,
    git_repo_root_uri: git_repo_root_uri
  )
rescue StandardError => e
  raise e
end

.security_referencesObject

Used primarily to map NIST 800-53 Revision 4 Security Controls web.nvd.nist.gov/view/800-53/Rev4/impact?impactName=HIGH to PWN Exploit & Static Code Anti-Pattern Matching Modules to Determine the level of Testing Coverage w/ PWN.



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/pwn/sast/banned_function_calls_c.rb', line 173

public_class_method def self.security_references
  {
    sast_module: self,
    section: 'INFORMATION INPUT VALIDATION',
    nist_800_53_uri: 'https://csrc.nist.gov/projects/cprt/catalog#/cprt/framework/version/SP_800_53_5_1_1/home?element=SI-10',
    cwe_id: '676',
    cwe_uri: 'https://cwe.mitre.org/data/definitions/676.html'
  }
rescue StandardError => e
  raise e
end