Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JavaScript compatibility to Vuln Func #5

Open
wants to merge 65 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
1abddd1
Initial try at javascript action
TeodorBucht1729 Jun 30, 2021
f62996b
test diff
TeodorBucht1729 Jun 30, 2021
866cfea
test without version
TeodorBucht1729 Jun 30, 2021
a4f3b50
test without version
TeodorBucht1729 Jun 30, 2021
3a6c8af
test without version
TeodorBucht1729 Jun 30, 2021
732275b
change repo
TeodorBucht1729 Jun 30, 2021
7163054
fix path
TeodorBucht1729 Jun 30, 2021
693e80d
list dir
TeodorBucht1729 Jun 30, 2021
11febd7
list dir
TeodorBucht1729 Jun 30, 2021
f70b0aa
fix copy bug
TeodorBucht1729 Jun 30, 2021
1fc0c95
test fix
TeodorBucht1729 Jun 30, 2021
e43e943
test change
TeodorBucht1729 Jun 30, 2021
3625ae8
test fix
TeodorBucht1729 Jun 30, 2021
ed30881
test fix
TeodorBucht1729 Jun 30, 2021
c1a8d3c
test fix
TeodorBucht1729 Jun 30, 2021
ec18307
test fix
TeodorBucht1729 Jun 30, 2021
60db4df
fix typo
TeodorBucht1729 Jun 30, 2021
5bdcf34
test fix
TeodorBucht1729 Jun 30, 2021
c7e1102
test fix
TeodorBucht1729 Jun 30, 2021
9a05a50
test fix
TeodorBucht1729 Jun 30, 2021
9eadd15
small fix
TeodorBucht1729 Jun 30, 2021
f7a938b
small fix
TeodorBucht1729 Jun 30, 2021
9fd43a5
test ci install
TeodorBucht1729 Jun 30, 2021
b89ea7d
test ci install
TeodorBucht1729 Jun 30, 2021
b7269de
test fix
TeodorBucht1729 Jun 30, 2021
4f58673
Add tests, docstrings and comments
TeodorBucht1729 Jul 1, 2021
664fee3
Add javascript docker to docker.yml
TeodorBucht1729 Jul 1, 2021
109e769
set up automatic test
TeodorBucht1729 Jul 2, 2021
2bb1365
change access
TeodorBucht1729 Jul 2, 2021
f114aa7
change access
TeodorBucht1729 Jul 2, 2021
c564a74
modify test command
TeodorBucht1729 Jul 2, 2021
88c207d
update requirements and add package.json
TeodorBucht1729 Jul 2, 2021
6facd27
Change footprint and tests accordingly
TeodorBucht1729 Jul 13, 2021
574cff7
Move commonWrappoer to common folder
TeodorBucht1729 Jul 14, 2021
4963183
Add file-finding test and gitignore
TeodorBucht1729 Jul 14, 2021
6ec8937
Make output file names language specific
TeodorBucht1729 Jul 14, 2021
9887065
Change action repo
TeodorBucht1729 Jul 14, 2021
d15974e
Speed up call graph generation
TeodorBucht1729 Jul 16, 2021
297c642
Add tests and make gen_package_cg run in parallell
TeodorBucht1729 Aug 6, 2021
1de9d3b
Add dos2unix in test action
TeodorBucht1729 Aug 6, 2021
142fe9e
Add memory option
TeodorBucht1729 Aug 9, 2021
25abd1e
Add callgraph generation files
TeodorBucht1729 Aug 11, 2021
dd2c2d4
Test action
TeodorBucht1729 Aug 11, 2021
6fda5f8
Test fix
TeodorBucht1729 Aug 11, 2021
de6c89e
Test fix
TeodorBucht1729 Aug 11, 2021
02cd2db
test fix
TeodorBucht1729 Aug 11, 2021
719437d
test fix
TeodorBucht1729 Aug 11, 2021
e51af23
test fix
TeodorBucht1729 Aug 11, 2021
6c76502
test fix
TeodorBucht1729 Aug 11, 2021
f75e9a0
test fix
TeodorBucht1729 Aug 11, 2021
0d15df7
test fix
TeodorBucht1729 Aug 11, 2021
cb9e2dd
test fix
TeodorBucht1729 Aug 11, 2021
4b5a22e
test fix
TeodorBucht1729 Aug 11, 2021
248d2eb
Add automatic test for go
TeodorBucht1729 Aug 11, 2021
5b8c468
Install callgraph tool
TeodorBucht1729 Aug 11, 2021
15154d5
test new common path
TeodorBucht1729 Aug 11, 2021
4193c63
fix error
TeodorBucht1729 Aug 11, 2021
ff5691c
try to fix error
TeodorBucht1729 Aug 11, 2021
71d3249
Change js call graph generator to new format
TeodorBucht1729 Aug 12, 2021
88eb7ba
Change tests to new format
TeodorBucht1729 Aug 12, 2021
a8e413a
Fix format
TeodorBucht1729 Aug 13, 2021
bed0b1a
Fix output cg format
TeodorBucht1729 Aug 13, 2021
d797fc8
fix new format and change tests accordingly
TeodorBucht1729 Aug 13, 2021
5ca17f3
Merge pull request #1 from TeodorBucht1729/go-vuln-func
TeodorBucht1729 Aug 13, 2021
a6b81d9
Merge pull request #2 from TeodorBucht1729/new-js-format
TeodorBucht1729 Aug 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,71 @@ jobs:
tags: |
ghcr.io/debricked/vulnerable-functionality:gradle
debricked/vulnerable-functionality:gradle

docker-javascript:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: javascript/Dockerfile
platforms: linux/amd64
push: true
tags: |
ghcr.io/debricked/vulnerable-functionality:javascript
debricked/vulnerable-functionality:javascript

docker-golang:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: golang/Dockerfile
platforms: linux/amd64
push: true
tags: |
ghcr.io/debricked/vulnerable-functionality:golang
debricked/vulnerable-functionality:golang
31 changes: 31 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Golang test

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Set up Go 1.16.5
uses: actions/setup-go@v2
with:
go-version: '1.16.5'
- name: Display Golang version
run: go version
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
go get -u golang.org/x/tools/cmd/callgraph
cd golang/test && go install
- name: Test with pytest
run: |
pip install pytest
pytest golang/test/go_cg_test.py
27 changes: 27 additions & 0 deletions .github/workflows/javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: JavaScript test

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r javascript/src/requirements.txt
sudo npm install -g @persper/js-callgraph
sudo apt-get install dos2unix
- name: Test with pytest
run: |
pip install pytest
pytest
14 changes: 14 additions & 0 deletions .github/workflows/vulnfunc_go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Vulnerable Functionality test golang

on: [push]

jobs:
vulnfunc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: TeodorBucht1729/vulnerable-functionality/golang@go-vuln-func
with:
root-mainpackage-directory: 'golang/test'

14 changes: 14 additions & 0 deletions .github/workflows/vulnfunc_js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Vulnerable Functionality test javascript

on: [push]

jobs:
vulnfunc:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: debricked/vulnerable-functionality/javascript@master
with:
root-packagejson-directory: 'javascript/test/fresh_install'

10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Python
__pycache__/
*.py[cod]
*$py.class
.pytest_cache/

# results from generating js callgraph
final_cg.json
partial_cg.json
cg.json
File renamed without changes.
12 changes: 12 additions & 0 deletions golang/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# syntax=docker/dockerfile:1

FROM golang:1.16

COPY ./src /vulnfunc/golang/src

RUN apt-get update ; apt-get install --no-install-recommends -y zip
RUN add-apt-repository ppa:deadsnakes/ppa ; apt-get update ; apt-get install --no-install-recommends -y python3
RUN go get -u golang.org/x/tools/cmd/callgraph

COPY ./entrypoint.sh /vulnfunc/golang/entrypoint.sh
RUN chmod +x /vulnfunc/golang/entrypoint.sh
18 changes: 18 additions & 0 deletions golang/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Debricked Vulnerable Functionality for Golang
author: Debricked
description: Calculates the call graph for a Golang main package
inputs:
root-mainpackage-directory:
description: Directory containing the .go with the main package and function.
required: true

runs:
using: docker
# image: docker://debricked/vulnerable-functionality:golang
image: Dockerfile
entrypoint: /vulnfunc/golang/entrypoint.sh
args:
- ${{ inputs.root-mainpackage-directory }}
branding:
color: purple
icon: filter
36 changes: 36 additions & 0 deletions golang/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -e

# Check if the givet root directory exists
if ! [ -d "$1" ] ; then
echo "Root project dir not found."
echo "USAGE: "$0" <rootGoModDir>"
exit 1
fi

pathToCommonDirectory="./common"
. $pathToCommonDirectory"/commonWrapper.sh"

# Check that package.json is provided
if ! [ -e "$1/go.mod" ] ; then
echo "go.mod not found in $1"
exit 1
fi

module_dir="${1%/}"
module_dir="/github/workspace/$module_dir"

# install dependencies
cd $module_dir && go install

exitIfNotInstalled python3

exitIfNotInstalled go

outputFileName=".debricked-call-graph-golang"

# Run the actual script that generates the call graph
echo "Running call graph generator"
/vulnfunc/golang/src/gen_callgraph.sh "$module_dir" $outputFileName

formatOutput "/vulnfunc/golang/src/$outputFileName"
82 changes: 82 additions & 0 deletions golang/src/combine_ast_ssa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import json
import getopt
import sys
import os

def combine_ast_ssa(ast_symbols, ssa_dump, output_file):
""" combine_ast_ssa takes two lists of the same symbols (ast_symbols
and ssa_dump), combines the information and saves it in the given
output_file.

Paramaters:
ast_symbols (list[dict]): A list of all the symbols from the ast_parser.
ssa_dump (list[dict]): A list of all the symbols from the ssa build.
output_file (string): The file where the combined symbols list will
be saved.

Returns:
void
"""
# add easy access to the symbols in ssa_dump through the 'Location'
ssa_by_location = {}
for symbol in ssa_dump:
if 'Location' in symbol and 'Synthetic' not in symbol:
ssa_by_location[symbol['Location']] = symbol

# For each symbol in ast_symbols add a footprint given by the
# ssa_dump 'Name'
if ast_symbols != None:
for i in range(len(ast_symbols)):
Location = ast_symbols[i]['file'] + ":" + ast_symbols[i]['line_start'] + ":" + ast_symbols[i]['column_start']
if Location not in ssa_by_location:
if ast_symbols[i]['file'][-8:] != '_test.go':
# print a warning if a symbol was found in the AST-parser
# bit not in the ssa build.
print("Warning! " + Location + " not found when building")
else:
ast_symbols[i]['footprint'] = ssa_by_location[Location]['Name']
else:
ast_symbols = []

with open(output_file, "w") as f:
f.write(json.dumps(ast_symbols, indent=4, sort_keys=True))


def main(argv):
""" main takes command line arguments and calls combine_ast_ssa
accordingly.

Paramaters:
argv (list[string]) all the given command line arguments

Returns:
void
"""
try:
opts, args = getopt.getopt(argv, "ho:", ["parsed_ssadump=", "ast_symbols="])
except getopt.GetoptError:
print("combine_ast_ssa.py --parsed_ssadump=<parsed_ssadump_file> --ast_symbols=<parsed_ast_symbols> -o <symbols.json>")
sys.exit(2)

# set default values
ast_symbols = {}
ssa_dump = {}
output_file = "symbols.json"

# parse the flags
for opt, arg in opts:
if opt == '--parsed_ssadump':
with open(arg, "r") as f:
ssa_dump = json.load(f)
elif opt == '--ast_symbols':
with open(arg, "r") as f:
ast_symbols = json.load(f)
elif opt == '-o':
output_file = os.path.abspath(arg)
elif opt == '-h':
print("Usage: combine_ast_ssa.py --parsed_ssadump <parsed_ssadump_file> --ast_symbols <parsed_ast_symbols> -o <symbols.json>")

combine_ast_ssa(ast_symbols, ssa_dump, output_file)

if __name__ == "__main__":
main(sys.argv[1:])
Loading