https://github.com/cgcl-codes/dissectvuldetection
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
✓Academic publication links
Links to: ieee.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.7%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: CGCL-codes
- Language: Python
- Default Branch: main
- Size: 115 MB
Statistics
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
DissectVulDetection
Contents
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
Install the necessary dependencies before running the project. All these softwares and libraries are needed in our project during implementing the graph processing and model training module.
Softwares
Python Libraries
For graph-based method, please reference
Graph-based Method/requirements.txtfor more details.
Setup
Clone this project, deploy on your own local machine, and get ready for your first running.
1) Clone this Repo
$
2) Install Prerequisites
$ pip install -r requirements.txt
3) Compile Java Source Code
$ cd EdgeProcessing/slicec_7edges_funcblock
$ javac -cp lib/org/eclipse/cdt.core/5.6.0.201402142303/*:lib/org/eclipse/equinox.common/3.6.200.v20130402-1505/*:lib/com.ibm.icu-4.4.2.jar -d bin src/main/java/slice/*.java src/main/java/sevenEdges/*.java src/main/java/sevenEdges/treeview/*.java src/main/java/sevenEdges/treeview/ast/*.java src/main/java/sevenEdges/nodeTraversal/*.java
Graph-based Method
This part is an instruction of our graph-based model, which leverages the advances in graph neural networks(GNNs) to develop a learning method to capture the potential code patterns under composite graph structures.
The basic idea of this part is to combine different types of code graph structures, to find out if the composite graphs outperform single graph structures and how much. We selected AST, CFG, PDG and their various combinations as our experimental targets, and we extract these graph structures from C/C++ source code utilizing the code analysis tool Joern.
Basic Structure
README.md <- The top-level README for developers using this project.
requirements.txt <- The necessary python environments.
|
GraphModelClient <- The model training module
cli
train.py <- The entrance of training models.
test.py <- Testing the specified model using data.
__init__.py
cli_utils
default_hypers
dataset_utils.py
model_utils.py
param_helpers.py
task_utils.py
training_utils.py
__init__.py
data
data
data_preprocess.py
our_map_all.txt
__init__.py
graph_dataset.py
jsonl_graph_dataset.py
jsonl_graph_property_dataset.py
__init__.py
layers
message_passing
ggnn.py
gnn_edge_mlp.py
gnn_film.py
message_passing.py
__init__.py
gnn.py
graph_global_exchange.py
nodes_to_graph_representation.py
__init__.py
models
graph_binary_classification_task.py
graph_regression_task.py
graph_task_model.py
node_multiclass_task.py
__init__.py
utils
activation.py
constants.py
gather_dense_gradient.py
param_helpers.py
__init__.py
__init__.py
|
EdgeProcessing <- The graph processing module.
README.md <- The README for developers extracting various graphs.
joern-cli <- Use Joern library to extract different graph edges.
bin
lib
graph <- Scripts to generate various graphs.
ast.sc <- Scripts to generate AST graph.
ast+cfg.sc <- Scripts to generate AST+CFG combined graph.
all.sc <- Scripts to generate AST+CFG+PDG composite graph.
joern
joern-parse
slicec_7edges_funcblock <- Utils for extracting graphs.
bin
lib
src
Graph Processing
To construct various graph structures form C/C++, we use Eclipse CDT library and Joern to extract and integrate different graphs.
For more details, please reference EdgeProcessing/README.
1) Slice Data
We use CDT library to extract the target functions in sample files.
$ cd EdgeProcessing/slicec_7edges_funcblock
- Run slice.ClassifyFileOfProject to extract all the C file from the SARD dataset / Run slice.NvdClassifyFile for the NVD dataset.
- Run slice.Main to slice SARD data in function level / slice.NvdMain for the NVD dataset.
2) Extract different edge relationships
We use Joern to extract edges of specific graphs and classify them by types. Then we traverse the source codes' AST nodes parsed by CDT library, and integrate edges with AST nodes to generate target graphs.
$ cd EdgeProcessing/joern-cli
- Use Joern to get all the specific edge relationships(i.e. control flows and data flows)
$ cd EdgeProcessing/slicec_7edges_funcblock
- Run sevenEdges.Main to extract source codes' AST nodes from SARD / sevenEdges.NvdMain for the NVD dataset.
- Run sevenEdges.concateJoern to integrate nodes with edges.
Model Training
This part of the code provides a user-friendly interface. For a quick start, you can simply run the command below:
$ cd GraphModelClient/cli
$ CUDA_VISIBLE_DEVICES=0 python train.py GGNN GraphBinaryClassification ../data/data/ast_graph
Results
Train/Val/Test ratios - 0.8/0.1/0.1
Example results of training on the SARD dataset with composite AST+CFG+PDG graph.
Saved Model checkpoint at 78 epochs.
Dataset parameters used: {
"max_nodes_per_batch": 128, "num_fwd_edge_types": 7, "add_self_loop_edges": true, "tie_fwd_bkwd_edges": true, "threshold_for_classification": 0.5
}
Model parameters used: {
"gnn_aggregation_function": "sum", "gnn_message_activation_function": "ReLU", "gnn_hidden_dim": 128, "gnn_use_target_state_as_input": false, "gnn_normalize_by_num_incoming": true, "gnn_num_edge_MLP_hidden_layers": 1, "gnn_message_calculation_class": "GGNN", "gnn_initial_node_representation_activation": "tanh", "gnn_dense_intermediate_layer_activation": "tanh", "gnn_num_layers": 4, "gnn_dense_every_num_layers": 10000, "gnn_residual_every_num_layers": 2, "gnn_use_inter_layer_layernorm": true, "gnn_layer_input_dropout_rate": 0.2, "gnn_global_exchange_mode": "gru", "gnn_global_exchange_every_num_layers": 10000, "gnn_global_exchange_weighting_fun": "softmax", "gnn_global_exchange_num_heads": 4, "gnn_global_exchange_dropout_rate": 0.2, "optimizer": "Adam", "learning_rate": 0.001, "learning_rate_decay": 0.98, "momentum": 0.85, "gradient_clip_value": 1.0, "use_intermediate_gnn_results": false, "graph_aggregation_num_heads": 128, "graph_aggregation_hidden_layers": [4], "graph_aggregation_dropout_rate": 0.1, "gnn_num_aggr_MLP_hidden_layers": null
}
== Running on test dataset
Loading data from ../data/data/tem_all_graph/new/ast.
Restoring best model state from trained_model/GGNN_GraphBinaryClassification__2022-03-21_12-38-21_best.pkl.
CP_test Accuracy = 0.750|precision = 0.583 | recall = 0.875 | f1 = 0.700 |TPR = 0.875 | FPR = 0.312 | TNR = 0.688 | FNR = 0.125 |
Contact
Acknowledgements
Guidance and ideas for some parts from:
Graph-based method project based on:
Owner
- Name: CGCL-codes
- Login: CGCL-codes
- Kind: organization
- Website: http://grid.hust.edu.cn/
- Repositories: 35
- Profile: https://github.com/CGCL-codes
CGCL/SCTS/BDTS Lab
GitHub Events
Total
Last Year
Dependencies
- Jinja2 ==2.11.1
- Keras-Applications ==1.0.8
- Keras-Preprocessing ==1.1.0
- Markdown ==3.2.1
- MarkupSafe ==1.1.1
- Pillow ==6.2.2
- Pygments ==2.6.1
- QtPy ==1.9.0
- Send2Trash ==1.5.0
- SetSimilaritySearch ==0.1.7
- Werkzeug ==1.0.1
- absl-py ==0.9.0
- astor ==0.8.1
- attrs ==19.3.0
- azure-common ==1.1.25
- azure-nspkg ==3.0.2
- azure-storage ==0.36.0
- azureml ==0.2.7
- backcall ==0.1.0
- bleach ==3.1.4
- boto3 ==1.12.37
- botocore ==1.15.37
- bypy ==1.6.8
- cachetools ==4.0.0
- certifi ==2020.6.20
- cffi ==1.14.0
- chardet ==3.0.4
- colorama ==0.4.3
- contextlib2 ==0.5.5
- coverage ==5.0.4
- cryptography ==2.9
- cycler ==0.10.0
- decorator ==4.4.2
- defusedxml ==0.6.0
- dill ==0.3.1.1
- docopt ==0.6.2
- docutils ==0.15.2
- dpu-utils ==0.2.11
- entrypoints ==0.3
- et-xmlfile ==1.0.1
- future ==0.18.2
- gast ==0.2.2
- gensim ==3.8.1
- google-api-core ==1.16.0
- google-auth ==1.13.1
- google-auth-oauthlib ==0.4.1
- google-cloud-core ==1.3.0
- google-cloud-storage ==1.27.0
- google-pasta ==0.2.0
- google-resumable-media ==0.5.0
- googleapis-common-protos ==1.51.0
- grpcio ==1.28.1
- h5py ==2.10.0
- hyperopt ==0.1.2
- idna ==2.9
- importlib-metadata ==1.6.0
- ipykernel ==5.2.0
- ipython ==7.9.0
- ipython-genutils ==0.2.0
- ipywidgets ==7.5.1
- jdcal ==1.4.1
- jedi ==0.16.0
- jmespath ==0.9.5
- joblib ==0.14.1
- json-tricks ==3.15.0
- jsonlines ==1.2.0
- jsonschema ==3.2.0
- jupyter ==1.0.0
- jupyter-client ==6.1.2
- jupyter-console ==6.1.0
- jupyter-core ==4.6.3
- kiwisolver ==1.2.0
- matplotlib ==3.3.2
- mistune ==0.8.4
- multiprocess ==0.70.9
- nbconvert ==5.6.1
- nbformat ==5.0.5
- networkx ==2.4
- notebook ==6.0.3
- numpy ==1.18.2
- oauthlib ==3.1.0
- openpyxl ==3.0.5
- opt-einsum ==3.2.1
- pandas ==1.0.5
- pandocfilters ==1.4.2
- parso ==0.6.2
- pexpect ==4.8.0
- pickleshare ==0.7.5
- prometheus-client ==0.7.1
- prompt-toolkit ==2.0.10
- protobuf ==3.11.3
- psutil ==5.7.0
- ptyprocess ==0.6.0
- pyasn1 ==0.4.8
- pyasn1-modules ==0.2.8
- pycparser ==2.20
- pymongo ==3.10.1
- pyparsing ==2.1.10
- pyrsistent ==0.16.0
- python-dateutil ==2.8.1
- pytz ==2019.3
- pyzmq ==19.0.0
- qtconsole ==4.7.2
- requests ==2.23.0
- requests-oauthlib ==1.3.0
- requests-toolbelt ==0.9.1
- rsa ==4.0
- s3transfer ==0.3.3
- scikit-learn ==0.23.1
- scipy ==1.4.1
- six ==1.14.0
- sklearn ==0.0
- smart-open ==1.10.0
- tensorboard ==2.0.2
- tensorflow-estimator ==2.0.1
- tensorflow-gpu ==2.0.0
- termcolor ==1.1.0
- terminado ==0.8.3
- testpath ==0.4.4
- threadpoolctl ==2.1.0
- tornado ==6.0.4
- tqdm ==4.45.0
- traitlets ==4.3.3
- urllib3 ==1.25.8
- wcwidth ==0.1.9
- webencodings ==0.5.1
- widgetsnbextension ==3.5.1
- wrapt ==1.12.1
- zipp ==1.2.0