Skip to content

Commit 69d8f5f

Browse files
committed
scanners: Add data flow based scanning
For multi lanaguge support. Current supports Python via inclusion of shoudli flows Signed-off-by: John Andersen <[email protected]>
1 parent 08b9a6f commit 69d8f5f

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

cve_bin_tool/scanners/__init__.py

Whitespace-only changes.

cve_bin_tool/scanners/dataflow.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
See doc/DATA_FLOW_SCANNER.rst for more information
3+
"""
4+
import sys
5+
import asyncio
6+
import pathlib
7+
import platform
8+
from typing import Dict, NewType
9+
10+
import dffml
11+
12+
import dffml_feature_git.feature.definitions
13+
import dffml_feature_git.feature.operations
14+
15+
16+
DirectoryToScan = NewType("DirectoryToScan", pathlib.Path)
17+
ScanResults = NewType("ScanResults", dict)
18+
InputOfUnknownType = NewType("InputOfUnknownType", str)
19+
20+
21+
@dffml.op(
22+
inputs={
23+
"repo": dffml_feature_git.feature.definitions.git_repository,
24+
},
25+
outputs={
26+
"result": DirectoryToScan,
27+
},
28+
)
29+
async def repo_to_directory(repo):
30+
return {"result": repo.directory}
31+
32+
33+
@dffml.op
34+
async def scan_directory(
35+
directory: DirectoryToScan,
36+
) -> ScanResults:
37+
pass
38+
39+
40+
@dffml.op
41+
async def scan_directory(
42+
arg: InputOfUnknownType,
43+
) -> ScanResults:
44+
pass
45+
46+
47+
COLLECTOR_DATAFLOW = dffml.DataFlow(
48+
*dffml.opimp_in(dffml_feature_git.feature.operations),
49+
*dffml.opimp_in(sys.modules[__name__]),
50+
)
51+
52+
# CVEBinToolDataFlow = dffml.SystemContext(
53+
# upstream=COLLECTOR_DATAFLOW,
54+
# )
55+
# scanner = CVEBinToolDataFlow.deployment()
56+
57+
58+
async def main():
59+
# async for results in scanner():
60+
async for _ctx, results in dffml.run(
61+
COLLECTOR_DATAFLOW,
62+
{
63+
arg: [
64+
dffml.Input(
65+
value=arg,
66+
definition=dffml_feature_git.feature.definitions.URL,
67+
# definition=InputOfUnknownType,
68+
),
69+
]
70+
for arg in sys.argv[1:]
71+
},
72+
):
73+
print(_ctx, results)
74+
75+
76+
if __name__ == "__main__":
77+
asyncio.run(main())

doc/DATA_FLOW_SCANNER.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Data Flow Based Scanner
2+
#######################
3+
4+
Implement multi language support in CVE Bin Tool via introduction of data flows
5+
to handle scanning. We'll then extend via overlays to add functionality such as
6+
shouldi were appropriate.
7+
8+
References:
9+
10+
- https://intel.github.io/dffml/shouldi.html
11+
- https://intel.github.io/dffml/examples/shouldi.html
12+
- https://intel.github.io/dffml/examples/dataflows.html
13+
14+
.. note::
15+
16+
Tested against development version of DFFML
17+
9ddcdfd6f8de743f87d41b74d53fde2c182861c7
18+
19+
20+
Install
21+
*******
22+
23+
Install with extra
24+
25+
.. code-block:: console
26+
27+
$ python -m pip install cve-bin-tool[dataflow]
28+
29+
Examples
30+
********
31+
32+
Scan files as usual
33+
34+
.. code-block:: console
35+
:test:
36+
37+
$ python -m cve_bin_tool.scanners.dataflow .
38+
39+
Scan a git repo. Currently runs ``shoudli`` scanning. (In future we can add
40+
overlays to run the build then scan).
41+
42+
.. code-block:: console
43+
:test:
44+
45+
$ python -m cve_bin_tool.scanners.dataflow https://github.com/intel/cve-bin-tool

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
install_requires=requirements,
4848
extras_require={
4949
"PDF": ["reportlab"],
50+
"dataflow": ["dffml", "dffml-feature-git"],
5051
},
5152
packages=find_packages(
5253
exclude=["locales", "presentation"],

0 commit comments

Comments
 (0)