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

Acceptance tests #7

Merged
merged 5 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,6 @@ test/run_real_world_samples.sh
.project
.pydevproject

src/cwe_checker.plugin
src/cwe_checker.plugin

.#*
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Refactoring: Unification of cwe_checker function interface
- Refactoring: Created utils module for JSON functionality
- Added check for CWE 248: Uncaught Exception
- Added automated test suite (run with make test)

0.1 (2018-10-08)
=====
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
.phony: all
.PHONY: all clean test uninstall
all:
cd src; bapbuild -r -Is checkers,utils -pkgs yojson,unix cwe_checker.plugin; bapbundle install cwe_checker.plugin; cd ..

test:
bapbuild -r -Is src,src/checkers,src/utils,test -pkgs yojson,unix,alcotest test/test_cwe_checker.byte
./test/test_cwe_checker.byte
pytest -v

clean:
bapbuild -clean
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ The three way is to build it using the provided `Makefile`. In this case you mus
- Ocaml 4.05.0
- Opam 2.0.2
- BAP 1.5 (and its dependencies)
- yojson <= 1.4.1
- alcotest <= 0.8.3
- yojson >= 1.4.1
- alcotest >= 0.8.3
- Sark for IDA Pro annotations
Just run `make all` to compile and register the plugin with BAP.
- pytest >= 3.5.1

Just run `make all` to compile and register the plugin with BAP. You can run the test suite via `make test`.
## How to use cwe_checker? ##
The usage is straight forward: adjust the `config.json` (if needed) and call BAP with *cwe_checker* as a pass.
``` bash
Expand Down
14 changes: 14 additions & 0 deletions test/acceptance/cwe_checker_testlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import subprocess

def build_bap_cmd(filename, target, arch):
cmd = 'bap test/artificial_samples/build/cwe_%s_%s.out --pass=callsites,cwe-checker --cwe-checker-partial=CWE%s --cwe-checker-config=src/config.json' % (filename, arch, target)
return cmd.split()

def execute_and_check_occurence(filename, target, arch, string):
occurence = 0
bap_cmd = build_bap_cmd(filename, target, arch)
output = subprocess.check_output(bap_cmd)
for l in output.splitlines():
if string in l:
occurence += 1
return occurence
35 changes: 35 additions & 0 deletions test/acceptance/test_cwe190.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
import cwe_checker_testlib

class TestCwe190(unittest.TestCase):

def setUp(self):
self.target = '190'
self.string = b'Integer Overflow or Wraparound'

def test_cwe190_01_arm(self):
expect_res = 3
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

def test_cwe190_01_x86(self):
expect_res = 3
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe190_01_x64(self):
expect_res = 3
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe190_01_mips(self):
expect_res = 3
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe190_01_ppc(self):
expect_res = 3
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

34 changes: 34 additions & 0 deletions test/acceptance/test_cwe215.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import unittest
import cwe_checker_testlib

class TestCwe215(unittest.TestCase):

def setUp(self):
self.target = '215'
self.filename = '476'
self.string = b'Information Exposure Through Debug Information'

def test_cwe215_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'arm', self.string)
assert res == expect_res

def test_cwe215_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe215_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'x64', self.string)
assert res == expect_res

def test_cwe215_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'ppc', self.string)
assert res == expect_res

def test_cwe215_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.filename, self.target, 'mips', self.string)
assert res == expect_res
61 changes: 61 additions & 0 deletions test/acceptance/test_cwe243.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import unittest
import cwe_checker_testlib

class TestCwe243(unittest.TestCase):

def setUp(self):
self.target = '243'
self.string = b'The program utilizes chroot without dropping privileges and/or changing the directory'

def test_cwe243_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

def test_cwe243_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe243_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

def test_cwe243_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe243_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe243_02_arm(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'arm', self.string)
assert res == expect_res

@unittest.skip("Investigate and fix this issue")
def test_cwe243_02_x86(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'x86', self.string)
assert res == expect_res

def test_cwe243_02_x64(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'x64', self.string)
assert res == expect_res

def test_cwe243_02_ppc(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'ppc', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe476_02_mips(self):
expect_res = 0
res = cwe_checker_testlib.execute_and_check_occurence(self.target + "_clean", self.target, 'mips', self.string)
assert res == expect_res
36 changes: 36 additions & 0 deletions test/acceptance/test_cwe248.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
import cwe_checker_testlib

class TestCwe248(unittest.TestCase):

def setUp(self):
self.target = '248'
self.string = b'Possibly Uncaught Exception'

def test_cwe248_01_arm(self):
expect_res = 2
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

@unittest.skip("Fix CPP compilation issue for x86")
def test_cwe248_01_x86(self):
expect_res = 2
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe248_01_x64(self):
expect_res = 2
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe248_01_mips(self):
expect_res = 2
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe248_01_ppc(self):
expect_res = 2
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

35 changes: 35 additions & 0 deletions test/acceptance/test_cwe332.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
import cwe_checker_testlib

class TestCwe332(unittest.TestCase):

def setUp(self):
self.target = '332'
self.string = b'Insufficient Entropy in PRNG'

def test_cwe332_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

def test_cwe332_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe332_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe332_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe332_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

35 changes: 35 additions & 0 deletions test/acceptance/test_cwe367.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
import cwe_checker_testlib

class TestCwe367(unittest.TestCase):

def setUp(self):
self.target = '367'
self.string = b'Time-of-check Time-of-use Race Condition'

def test_cwe367_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

def test_cwe367_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe367_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe367_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe367_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

36 changes: 36 additions & 0 deletions test/acceptance/test_cwe426.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import unittest
import cwe_checker_testlib

class TestCwe426(unittest.TestCase):

def setUp(self):
self.target = '426'
self.string = b'Untrusted Search Path'

def test_cwe426_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

@unittest.skip("FIXME")
def test_cwe426_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

def test_cwe426_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe426_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

def test_cwe426_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

39 changes: 39 additions & 0 deletions test/acceptance/test_cwe457.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest
import cwe_checker_testlib

class TestCwe457(unittest.TestCase):

def setUp(self):
self.target = '457'
self.string = b'Use of Uninitialized Variable'

@unittest.skip("FIXME")
def test_cwe457_01_arm(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'arm', self.string)
assert res == expect_res

@unittest.skip("FIXME")
def test_cwe457_01_x86(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x86', self.string)
assert res == expect_res

@unittest.skip("FIXME")
def test_cwe457_01_x64(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'x64', self.string)
assert res == expect_res

@unittest.skip("Depends on proper MIPS support in BAP")
def test_cwe457_01_mips(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'mips', self.string)
assert res == expect_res

@unittest.skip("FIXME")
def test_cwe457_01_ppc(self):
expect_res = 1
res = cwe_checker_testlib.execute_and_check_occurence(self.target, self.target, 'ppc', self.string)
assert res == expect_res

Loading