appsec-discovery 0.4.0__tar.gz

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 (34) hide show
  1. appsec_discovery-0.4.0/LICENSE +21 -0
  2. appsec_discovery-0.4.0/PKG-INFO +311 -0
  3. appsec_discovery-0.4.0/README.md +279 -0
  4. appsec_discovery-0.4.0/appsec_discovery/__init__.py +4 -0
  5. appsec_discovery-0.4.0/appsec_discovery/cli.py +20 -0
  6. appsec_discovery-0.4.0/appsec_discovery/models/__init__.py +4 -0
  7. appsec_discovery-0.4.0/appsec_discovery/models/code_object.py +33 -0
  8. appsec_discovery-0.4.0/appsec_discovery/models/config.py +88 -0
  9. appsec_discovery-0.4.0/appsec_discovery/models/reports.py +19 -0
  10. appsec_discovery-0.4.0/appsec_discovery/models/uploads.py +20 -0
  11. appsec_discovery-0.4.0/appsec_discovery/parsers/__init__.py +2 -0
  12. appsec_discovery-0.4.0/appsec_discovery/parsers/base_parser.py +69 -0
  13. appsec_discovery-0.4.0/appsec_discovery/parsers/client/parser.py +35 -0
  14. appsec_discovery-0.4.0/appsec_discovery/parsers/db/parser.py +35 -0
  15. appsec_discovery-0.4.0/appsec_discovery/parsers/golang/parser.py +96 -0
  16. appsec_discovery-0.4.0/appsec_discovery/parsers/golang/scanner_rules/dto.yaml +20 -0
  17. appsec_discovery-0.4.0/appsec_discovery/parsers/graphql/parser.py +210 -0
  18. appsec_discovery-0.4.0/appsec_discovery/parsers/java/parser.py +105 -0
  19. appsec_discovery-0.4.0/appsec_discovery/parsers/java/scanner_rules/dto.yaml +43 -0
  20. appsec_discovery-0.4.0/appsec_discovery/parsers/parser_factory.py +71 -0
  21. appsec_discovery-0.4.0/appsec_discovery/parsers/protobuf/parser.py +308 -0
  22. appsec_discovery-0.4.0/appsec_discovery/parsers/python/parser.py +150 -0
  23. appsec_discovery-0.4.0/appsec_discovery/parsers/python/scanner_rules/dto.yaml +66 -0
  24. appsec_discovery-0.4.0/appsec_discovery/parsers/python/scanner_rules/route.yaml +77 -0
  25. appsec_discovery-0.4.0/appsec_discovery/parsers/swagger/parser.py +172 -0
  26. appsec_discovery-0.4.0/appsec_discovery/parsers/swagger/scanner_rules/rules.yaml +148 -0
  27. appsec_discovery-0.4.0/appsec_discovery/parsers/terraform/parser.py +150 -0
  28. appsec_discovery-0.4.0/appsec_discovery/parsers/terraform/scanner_rules/rules.yaml +192 -0
  29. appsec_discovery-0.4.0/appsec_discovery/services/__init__.py +2 -0
  30. appsec_discovery-0.4.0/appsec_discovery/services/ai_service.py +136 -0
  31. appsec_discovery-0.4.0/appsec_discovery/services/report_service.py +157 -0
  32. appsec_discovery-0.4.0/appsec_discovery/services/scan_service.py +212 -0
  33. appsec_discovery-0.4.0/appsec_discovery/services/upload_service.py +8 -0
  34. appsec_discovery-0.4.0/pyproject.toml +46 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Dmitrii Mariushkin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,311 @@
1
+ Metadata-Version: 2.1
2
+ Name: appsec-discovery
3
+ Version: 0.4.0
4
+ Summary: Discover sensitive objects in project code
5
+ License: MIT
6
+ Keywords: security,assets,discovery,scanning,appsec
7
+ Author: Dmitrii Mariushkin
8
+ Author-email: d.v.marushkin@gmail.com
9
+ Requires-Python: >=3.12,<4.0
10
+ Classifier: Environment :: Console
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Security
17
+ Requires-Dist: click (>=8.1.7,<9.0.0)
18
+ Requires-Dist: graphql-core (>=3.2.5,<4.0.0)
19
+ Requires-Dist: huggingface-hub (>=0.26.2,<0.27.0)
20
+ Requires-Dist: jschema-to-python (>=1.2.3,<2.0.0)
21
+ Requires-Dist: llama-cpp-python (>=0.3.1,<0.4.0)
22
+ Requires-Dist: mkdocs-material (>=9.5.44,<10.0.0)
23
+ Requires-Dist: proto-schema-parser (>=1.4.2,<2.0.0)
24
+ Requires-Dist: pydantic (==1.9.0)
25
+ Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
26
+ Requires-Dist: sarif-om (>=1.0.4,<2.0.0)
27
+ Requires-Dist: semgrep (>=1.58.0,<2.0.0)
28
+ Project-URL: Bug Tracker, https://github.com/dmarushkin/appsec-discovery/issues
29
+ Project-URL: Homepage, https://github.com/dmarushkin/appsec-discovery
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Appsec Discovery
33
+
34
+ Appsec Discovery cli tool scan provided code projects and extract structured protobuf, graphql, swaggers, database schemas, python, go and java object DTOs, used api clients and methods, and other kinds of external contracts. It scores risk level for found object fields with provided in config static keywords ruleset and store results in own format json or sarif reports for fast integration with exist vuln management systems like Defectdojo.
35
+
36
+ Cli tool can also use local LLM model Llama 3.2 3B from Huggingface and provided prompt to score objects without pre-existing knowledge about assets in code. Small open source models work fast on common hardware and are just enouth for such classification tasks.
37
+
38
+ Appsec Discovery service continuosly fetch changes from local Gitlab via api, clone code for particular projects, scan for objects in code and score them with provided via UI rules, store result objects with projects, branches and MRs from Gitlab in local db and alert about critical changes via messenger or comments to MR in Gitlab.
39
+
40
+ Under the hood tool powered by Semgrep OSS engine and specialy crafted discovery rules and parsers that extract particular objects from semgrep report meta variables.
41
+
42
+ ## Cli mode
43
+
44
+ Install cli tool:
45
+
46
+ ```
47
+ pip install appsec-discovery
48
+ ```
49
+
50
+ Provided rules in conf.yaml or leave it empty for default list:
51
+
52
+ ```
53
+ score_tags:
54
+ pii:
55
+ high:
56
+ - '(first_name|firstname)'
57
+ - 'last_name'
58
+ - 'phone'
59
+ - 'passport'
60
+ medium:
61
+ - 'address'
62
+ low:
63
+ - 'city'
64
+ finance:
65
+ high:
66
+ - 'pan'
67
+ - 'card_number'
68
+ medium:
69
+ - 'amount'
70
+ - 'balance'
71
+ auth:
72
+ high:
73
+ - 'password'
74
+ - 'pincode'
75
+ - 'codeword'
76
+ - 'token'
77
+ medium:
78
+ - 'login'
79
+ ```
80
+
81
+ Run on code project folder with swaggers, protobuf and other structured contracts in code and get parsed objects and fields marked with severity and category tags:
82
+
83
+ ```
84
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/conf.yaml
85
+
86
+ - hash: e491e2905199e066aa9fb37e05b82197
87
+ object_name: Swagger route /user (POST)
88
+ object_type: route
89
+ parser: swagger
90
+ severity: high
91
+ tags:
92
+ - pii
93
+ - auth
94
+ file: /swagger.yaml
95
+ line: 63
96
+ properties:
97
+ path:
98
+ prop_name: path
99
+ prop_value: /user
100
+ method:
101
+ prop_name: method
102
+ prop_value: post
103
+ fields:
104
+ ...
105
+ Output.User.id:
106
+ field_name: Output.User.id
107
+ field_type: integer
108
+ file: /swagger.yaml
109
+ line: 63
110
+ Output.User.lastName:
111
+ field_name: Output.User.lastName
112
+ field_type: string
113
+ file: /swagger.yaml
114
+ line: 63
115
+ severity: high
116
+ tags:
117
+ - pii
118
+ Output.User.password:
119
+ field_name: Output.User.password
120
+ field_type: string
121
+ file: /swagger.yaml
122
+ line: 63
123
+ severity: high
124
+ tags:
125
+ - auth
126
+ Output.User.phone:
127
+ field_name: Output.User.phone
128
+ field_type: string
129
+ file: /swagger.yaml
130
+ line: 63
131
+ severity: high
132
+ tags:
133
+ - pii
134
+ ...
135
+ - hash: 2e20a348a612aa28d24c1bd0498eebf0
136
+ object_name: Swagger route /user/login (GET)
137
+ object_type: route
138
+ parser: swagger
139
+ severity: high
140
+ tags:
141
+ - auth
142
+ file: /swagger.yaml
143
+ line: 83
144
+ ...
145
+ fields:
146
+ Input.password:
147
+ field_name: Input.password
148
+ field_type: string
149
+ file: /swagger.yaml
150
+ line: 83
151
+ severity: high
152
+ tags:
153
+ - auth
154
+ ...
155
+ ```
156
+
157
+ ## Score object fields with local LLM model
158
+
159
+ Replace or combine exist static keyword ruleset with LLM, fill conf.yaml with choosed LLM and prompt:
160
+
161
+ ```
162
+ ai_params:
163
+ model_id: "mradermacher/Llama-3.2-3B-Instruct-uncensored-GGUF"
164
+ gguf_file: "Llama-3.2-3B-Instruct-uncensored.Q8_0.gguf"
165
+ model_folder: "/app/tests/ai_samples/hf_home"
166
+ prompt: "You are security bot, for provided objects select only field names that contain personally identifiable information (pii), finance, authentication and other sensitive data. You return json list of selected critical field names like [\"field1\", \"field2\", ... ] or empty json list."
167
+ ```
168
+
169
+ Run scan with new settings and get objects and fields severity from local AI engine:
170
+
171
+ ```
172
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/ai_conf_llama.yaml
173
+
174
+ - hash: 6ad58c7da41fc968c1de76f9233d645d
175
+ object_name: Swagger route /pet/{petId} (GET)
176
+ object_type: route
177
+ parser: swagger
178
+ file: /swagger.yaml
179
+ line: 41
180
+ properties:
181
+ path:
182
+ prop_name: path
183
+ prop_value: /pet/{petId}
184
+ method:
185
+ prop_name: method
186
+ prop_value: get
187
+ fields:
188
+ Input.petId:
189
+ field_name: Input.petId
190
+ field_type: integer
191
+ file: /swagger.yaml
192
+ line: 41
193
+ Output.Pet.id:
194
+ field_name: Output.Pet.id
195
+ field_type: integer
196
+ file: /swagger.yaml
197
+ line: 41
198
+ Output.Pet.name:
199
+ field_name: Output.Pet.name
200
+ field_type: string
201
+ file: /swagger.yaml
202
+ line: 41
203
+ ...
204
+ - hash: 2e20a348a612aa28d24c1bd0498eebf0
205
+ object_name: Swagger route /user/login (GET)
206
+ object_type: route
207
+ parser: swagger
208
+ severity: medium
209
+ tags:
210
+ - llm
211
+ file: /swagger.yaml
212
+ line: 83
213
+ properties:
214
+ path:
215
+ prop_name: path
216
+ prop_value: /user/login
217
+ method:
218
+ prop_name: method
219
+ prop_value: get
220
+ fields:
221
+ ...
222
+ Input.password:
223
+ field_name: Input.password
224
+ field_type: string
225
+ file: /swagger.yaml
226
+ line: 83
227
+ severity: medium
228
+ tags:
229
+ - llm
230
+ ...
231
+
232
+ ```
233
+
234
+ At first run tool with download provided model from Huggingface into local cache dir, for next offline scans use this dir with pre downloaded models.
235
+
236
+ Play around with with various [models](https://huggingface.co/models?search=llama-3.2) from Huggingface and prompts for best results.
237
+
238
+
239
+ ## Integrate scans into CI/CD
240
+
241
+ Run scan with sarif output format:
242
+
243
+ ```
244
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/conf.yaml --output report.json --output-type sarif
245
+ ```
246
+
247
+ Load result reports into vuln management system like Defectdojo:
248
+
249
+ ![dojo1](https://github.com/dmarushkin/appsec-discovery/blob/main/dojo1.png?raw=true)
250
+
251
+ ![dojo2](https://github.com/dmarushkin/appsec-discovery/blob/main/dojo2.png?raw=true)
252
+
253
+ ## Service mode
254
+
255
+ Clone code to local folder:
256
+
257
+ ```
258
+ git clone https://github.com/dmarushkin/appsec-discovery
259
+ cd appsec-discovery/appsec_discovery_service
260
+ ```
261
+
262
+ Fillout .env file with your gitlab url and token, change passwords for local db and ui user, for alerts register new telegram bot or use exist one, or just leave TG args empty to only store objects:
263
+
264
+ ```
265
+ POSTGRES_HOST=discovery_postgres
266
+ POSTGRES_DB=discovery_db
267
+ POSTGRES_USER=discovery_user
268
+ POSTGRES_PASSWORD=some_secret_str
269
+ GITLAB_PRIVATE_TOKEN=some_secret_str
270
+ GITLAB_URL=https://gitlab.examle.com
271
+ GITLAB_PROJECTS_PREFIX=backend/,frontend/,test/
272
+ UI_ADMIN_EMAIL=admin@example.com
273
+ UI_ADMIN_PASSWORD=admin
274
+ UI_JWT_KEY=some_secret_str
275
+ MAX_WORKERS=5
276
+ MR_ALERTS=1
277
+ TG_ALERT_TOKEN=test
278
+ TG_CHAT_ID=0000000000
279
+ ```
280
+
281
+ Run service localy with docker compose:
282
+
283
+ ```
284
+ docker-compose up --build
285
+ ```
286
+
287
+ Service will continuosly fetch new projects and MRs for provided prefixes from Gitlab api, clone code and scan it for objects, score found ones and save into local postgres db for any analysis.
288
+
289
+ If sensitive fields in objects added on Merge requests service will alert via provided channel.
290
+
291
+ To ajust default rule list authorize in Rules Management UI at http://127.0.0.1/ and make some new rules or make exclude rules for false positives:
292
+
293
+ ![service_ui](https://github.com/dmarushkin/appsec-discovery/blob/main/service_ui.png?raw=true)
294
+
295
+ For now service does not provide any local UI for parsed and scored objects, so we recomend to use any kind of external analytic systems like Apache Superset, Grafana, Tableu etc.
296
+
297
+ For prod environments bake Docker images in your k8s env, use external db.
298
+
299
+ ![Logic schema](https://github.com/dmarushkin/appsec-discovery/blob/main/discovery.png?raw=true)
300
+
301
+
302
+ ## Usage examples
303
+
304
+ - Appsec specialists can monitor codebase for critical changes and review them manualy, also sum scores for particular fields and get overall risk score for entire projects, and use it for prioritization of any kind of appsec rutines (triage vulns, plan security audits).
305
+
306
+ - Governance, Risk, and Compliance (GRC) specialists can use discovered data schemas for any kind of data governance (localize PII, payment and other critical data, dataflows), restricting access to and between critical services, focus on hardening environments that contain critical data.
307
+
308
+ - Monitoring or Incident Response specialists can focus attention on logs and anomalies in critical services or even particular routes in clients traffic.
309
+
310
+ - Infrastructure security specialists can use same approach to extract structured data about assets from IaC repositories like terraform or ansible (service now extracts VMs from terraform files).
311
+
@@ -0,0 +1,279 @@
1
+ # Appsec Discovery
2
+
3
+ Appsec Discovery cli tool scan provided code projects and extract structured protobuf, graphql, swaggers, database schemas, python, go and java object DTOs, used api clients and methods, and other kinds of external contracts. It scores risk level for found object fields with provided in config static keywords ruleset and store results in own format json or sarif reports for fast integration with exist vuln management systems like Defectdojo.
4
+
5
+ Cli tool can also use local LLM model Llama 3.2 3B from Huggingface and provided prompt to score objects without pre-existing knowledge about assets in code. Small open source models work fast on common hardware and are just enouth for such classification tasks.
6
+
7
+ Appsec Discovery service continuosly fetch changes from local Gitlab via api, clone code for particular projects, scan for objects in code and score them with provided via UI rules, store result objects with projects, branches and MRs from Gitlab in local db and alert about critical changes via messenger or comments to MR in Gitlab.
8
+
9
+ Under the hood tool powered by Semgrep OSS engine and specialy crafted discovery rules and parsers that extract particular objects from semgrep report meta variables.
10
+
11
+ ## Cli mode
12
+
13
+ Install cli tool:
14
+
15
+ ```
16
+ pip install appsec-discovery
17
+ ```
18
+
19
+ Provided rules in conf.yaml or leave it empty for default list:
20
+
21
+ ```
22
+ score_tags:
23
+ pii:
24
+ high:
25
+ - '(first_name|firstname)'
26
+ - 'last_name'
27
+ - 'phone'
28
+ - 'passport'
29
+ medium:
30
+ - 'address'
31
+ low:
32
+ - 'city'
33
+ finance:
34
+ high:
35
+ - 'pan'
36
+ - 'card_number'
37
+ medium:
38
+ - 'amount'
39
+ - 'balance'
40
+ auth:
41
+ high:
42
+ - 'password'
43
+ - 'pincode'
44
+ - 'codeword'
45
+ - 'token'
46
+ medium:
47
+ - 'login'
48
+ ```
49
+
50
+ Run on code project folder with swaggers, protobuf and other structured contracts in code and get parsed objects and fields marked with severity and category tags:
51
+
52
+ ```
53
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/conf.yaml
54
+
55
+ - hash: e491e2905199e066aa9fb37e05b82197
56
+ object_name: Swagger route /user (POST)
57
+ object_type: route
58
+ parser: swagger
59
+ severity: high
60
+ tags:
61
+ - pii
62
+ - auth
63
+ file: /swagger.yaml
64
+ line: 63
65
+ properties:
66
+ path:
67
+ prop_name: path
68
+ prop_value: /user
69
+ method:
70
+ prop_name: method
71
+ prop_value: post
72
+ fields:
73
+ ...
74
+ Output.User.id:
75
+ field_name: Output.User.id
76
+ field_type: integer
77
+ file: /swagger.yaml
78
+ line: 63
79
+ Output.User.lastName:
80
+ field_name: Output.User.lastName
81
+ field_type: string
82
+ file: /swagger.yaml
83
+ line: 63
84
+ severity: high
85
+ tags:
86
+ - pii
87
+ Output.User.password:
88
+ field_name: Output.User.password
89
+ field_type: string
90
+ file: /swagger.yaml
91
+ line: 63
92
+ severity: high
93
+ tags:
94
+ - auth
95
+ Output.User.phone:
96
+ field_name: Output.User.phone
97
+ field_type: string
98
+ file: /swagger.yaml
99
+ line: 63
100
+ severity: high
101
+ tags:
102
+ - pii
103
+ ...
104
+ - hash: 2e20a348a612aa28d24c1bd0498eebf0
105
+ object_name: Swagger route /user/login (GET)
106
+ object_type: route
107
+ parser: swagger
108
+ severity: high
109
+ tags:
110
+ - auth
111
+ file: /swagger.yaml
112
+ line: 83
113
+ ...
114
+ fields:
115
+ Input.password:
116
+ field_name: Input.password
117
+ field_type: string
118
+ file: /swagger.yaml
119
+ line: 83
120
+ severity: high
121
+ tags:
122
+ - auth
123
+ ...
124
+ ```
125
+
126
+ ## Score object fields with local LLM model
127
+
128
+ Replace or combine exist static keyword ruleset with LLM, fill conf.yaml with choosed LLM and prompt:
129
+
130
+ ```
131
+ ai_params:
132
+ model_id: "mradermacher/Llama-3.2-3B-Instruct-uncensored-GGUF"
133
+ gguf_file: "Llama-3.2-3B-Instruct-uncensored.Q8_0.gguf"
134
+ model_folder: "/app/tests/ai_samples/hf_home"
135
+ prompt: "You are security bot, for provided objects select only field names that contain personally identifiable information (pii), finance, authentication and other sensitive data. You return json list of selected critical field names like [\"field1\", \"field2\", ... ] or empty json list."
136
+ ```
137
+
138
+ Run scan with new settings and get objects and fields severity from local AI engine:
139
+
140
+ ```
141
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/ai_conf_llama.yaml
142
+
143
+ - hash: 6ad58c7da41fc968c1de76f9233d645d
144
+ object_name: Swagger route /pet/{petId} (GET)
145
+ object_type: route
146
+ parser: swagger
147
+ file: /swagger.yaml
148
+ line: 41
149
+ properties:
150
+ path:
151
+ prop_name: path
152
+ prop_value: /pet/{petId}
153
+ method:
154
+ prop_name: method
155
+ prop_value: get
156
+ fields:
157
+ Input.petId:
158
+ field_name: Input.petId
159
+ field_type: integer
160
+ file: /swagger.yaml
161
+ line: 41
162
+ Output.Pet.id:
163
+ field_name: Output.Pet.id
164
+ field_type: integer
165
+ file: /swagger.yaml
166
+ line: 41
167
+ Output.Pet.name:
168
+ field_name: Output.Pet.name
169
+ field_type: string
170
+ file: /swagger.yaml
171
+ line: 41
172
+ ...
173
+ - hash: 2e20a348a612aa28d24c1bd0498eebf0
174
+ object_name: Swagger route /user/login (GET)
175
+ object_type: route
176
+ parser: swagger
177
+ severity: medium
178
+ tags:
179
+ - llm
180
+ file: /swagger.yaml
181
+ line: 83
182
+ properties:
183
+ path:
184
+ prop_name: path
185
+ prop_value: /user/login
186
+ method:
187
+ prop_name: method
188
+ prop_value: get
189
+ fields:
190
+ ...
191
+ Input.password:
192
+ field_name: Input.password
193
+ field_type: string
194
+ file: /swagger.yaml
195
+ line: 83
196
+ severity: medium
197
+ tags:
198
+ - llm
199
+ ...
200
+
201
+ ```
202
+
203
+ At first run tool with download provided model from Huggingface into local cache dir, for next offline scans use this dir with pre downloaded models.
204
+
205
+ Play around with with various [models](https://huggingface.co/models?search=llama-3.2) from Huggingface and prompts for best results.
206
+
207
+
208
+ ## Integrate scans into CI/CD
209
+
210
+ Run scan with sarif output format:
211
+
212
+ ```
213
+ appsec-discovery --source tests/swagger_samples --config tests/config_samples/conf.yaml --output report.json --output-type sarif
214
+ ```
215
+
216
+ Load result reports into vuln management system like Defectdojo:
217
+
218
+ ![dojo1](https://github.com/dmarushkin/appsec-discovery/blob/main/dojo1.png?raw=true)
219
+
220
+ ![dojo2](https://github.com/dmarushkin/appsec-discovery/blob/main/dojo2.png?raw=true)
221
+
222
+ ## Service mode
223
+
224
+ Clone code to local folder:
225
+
226
+ ```
227
+ git clone https://github.com/dmarushkin/appsec-discovery
228
+ cd appsec-discovery/appsec_discovery_service
229
+ ```
230
+
231
+ Fillout .env file with your gitlab url and token, change passwords for local db and ui user, for alerts register new telegram bot or use exist one, or just leave TG args empty to only store objects:
232
+
233
+ ```
234
+ POSTGRES_HOST=discovery_postgres
235
+ POSTGRES_DB=discovery_db
236
+ POSTGRES_USER=discovery_user
237
+ POSTGRES_PASSWORD=some_secret_str
238
+ GITLAB_PRIVATE_TOKEN=some_secret_str
239
+ GITLAB_URL=https://gitlab.examle.com
240
+ GITLAB_PROJECTS_PREFIX=backend/,frontend/,test/
241
+ UI_ADMIN_EMAIL=admin@example.com
242
+ UI_ADMIN_PASSWORD=admin
243
+ UI_JWT_KEY=some_secret_str
244
+ MAX_WORKERS=5
245
+ MR_ALERTS=1
246
+ TG_ALERT_TOKEN=test
247
+ TG_CHAT_ID=0000000000
248
+ ```
249
+
250
+ Run service localy with docker compose:
251
+
252
+ ```
253
+ docker-compose up --build
254
+ ```
255
+
256
+ Service will continuosly fetch new projects and MRs for provided prefixes from Gitlab api, clone code and scan it for objects, score found ones and save into local postgres db for any analysis.
257
+
258
+ If sensitive fields in objects added on Merge requests service will alert via provided channel.
259
+
260
+ To ajust default rule list authorize in Rules Management UI at http://127.0.0.1/ and make some new rules or make exclude rules for false positives:
261
+
262
+ ![service_ui](https://github.com/dmarushkin/appsec-discovery/blob/main/service_ui.png?raw=true)
263
+
264
+ For now service does not provide any local UI for parsed and scored objects, so we recomend to use any kind of external analytic systems like Apache Superset, Grafana, Tableu etc.
265
+
266
+ For prod environments bake Docker images in your k8s env, use external db.
267
+
268
+ ![Logic schema](https://github.com/dmarushkin/appsec-discovery/blob/main/discovery.png?raw=true)
269
+
270
+
271
+ ## Usage examples
272
+
273
+ - Appsec specialists can monitor codebase for critical changes and review them manualy, also sum scores for particular fields and get overall risk score for entire projects, and use it for prioritization of any kind of appsec rutines (triage vulns, plan security audits).
274
+
275
+ - Governance, Risk, and Compliance (GRC) specialists can use discovered data schemas for any kind of data governance (localize PII, payment and other critical data, dataflows), restricting access to and between critical services, focus on hardening environments that contain critical data.
276
+
277
+ - Monitoring or Incident Response specialists can focus attention on logs and anomalies in critical services or even particular routes in clients traffic.
278
+
279
+ - Infrastructure security specialists can use same approach to extract structured data about assets from IaC repositories like terraform or ansible (service now extracts VMs from terraform files).
@@ -0,0 +1,4 @@
1
+ __version__ = '0.1.0'
2
+
3
+ def some_function(name="world"):
4
+ return name
@@ -0,0 +1,20 @@
1
+ import click
2
+
3
+ from appsec_discovery.services import ScanService, ReportService
4
+
5
+ @click.command()
6
+ @click.option('--source', required=True, type=click.Path(exists=True), help='Source code folder')
7
+ @click.option('--config', required=False, show_default=True, default=None, type=click.File('r'), help='Scoring config file')
8
+ @click.option('--output', required=False, show_default=True, default=None, type=click.File('w'), help='Output file')
9
+ @click.option('--output-type', required=False, show_default=True, default='yaml', type=click.Choice(['json', 'sarif', 'yaml'], case_sensitive=False), help='Report type')
10
+ @click.option("--only-scored-objects", is_flag=True, show_default=True, default=False, help="Show only scored objects")
11
+ def main(source, config, output, output_type, only_scored_objects):
12
+
13
+ scan_service = ScanService(source_folder=source, conf_file=config, only_scored_objects=only_scored_objects)
14
+ scanned_objects = scan_service.scan_folder()
15
+
16
+ report_service = ReportService(code_objects=scanned_objects, report_type=output_type, report_file=output)
17
+ report_service.save_report_to_disk()
18
+
19
+ if __name__ == '__main__':
20
+ main()
@@ -0,0 +1,4 @@
1
+ from appsec_discovery.models.code_object import CodeObject, CodeObjectProp, CodeObjectField
2
+ from appsec_discovery.models.config import ScoreConfig, ExcludeScoring, AiParams
3
+ from appsec_discovery.models.reports import JsonReport, DiffReport, SarifReport
4
+ from appsec_discovery.models.uploads import DefectdojoImportScanRequest, DefectdojoProjectTypeRequest, DiscoveryImportScanRequest
@@ -0,0 +1,33 @@
1
+ from pydantic import BaseModel
2
+ from typing import List, Dict, Optional
3
+
4
+
5
+ class CodeObjectField(BaseModel):
6
+ field_name: str
7
+ field_type: str
8
+ file: Optional[str]
9
+ line: Optional[int]
10
+ severity: Optional[str]
11
+ tags: Optional[List[str]]
12
+
13
+ class CodeObjectProp(BaseModel):
14
+ prop_name: str
15
+ prop_value: str
16
+ file: Optional[str]
17
+ line: Optional[int]
18
+ severity: Optional[str]
19
+ tags: Optional[List[str]]
20
+
21
+ class CodeObject(BaseModel):
22
+ hash: str
23
+ object_name: str
24
+ object_type: str
25
+ parser: str
26
+ severity: Optional[str]
27
+ tags: Optional[List[str]]
28
+ file: str
29
+ line: int
30
+ properties: Dict[str, CodeObjectProp]
31
+ fields: Dict[str, CodeObjectField]
32
+
33
+