コード例 #1
0
    def test_apicalls_children(self):
        # given
        expected_grandchild_api = ("printf", ["grandchild started\n"], 19)
        expected_child_api = ("printf", ["child started\n"], 14)
        expected_parent_api = ("printf", ["parent started\n"], 15)
        pids = Set()
        output = []
        # when
        for call in apicalls(self.current_target(), run_as_root=False):
            output.append(call)
            pids.add(call.pid)

        matched_grandchild = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_grandchild_api
        ]
        matched_child = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_child_api
        ]
        matched_parent = [
            x for x in output
            if (x.api, x.args, x.retval) == expected_parent_api
        ]
        # then
        self.assertEqual(len(matched_grandchild), 1)
        self.assertEqual(len(matched_child), 1)
        self.assertEqual(len(matched_parent), 1)
コード例 #2
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_root(self):
     # given
     expected_api = ("printf", ["I'm root!\n"], 10)
     output = []
     # when
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     self.assertEqual(len(matched), 1)
コード例 #3
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_basic(self):
     # given
     expected_api = ("system", ["whoami"], 0)
     output = []
     # when
     for call in apicalls(self.current_target()):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     self.assertEqual(len(matched), 1)
コード例 #4
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_errno_root(self):
     # given
     expected_api = ("fopen", ["doesn't matter", "r"], 0, 2)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [x for x in output if (x.api, x.args, x.retval, x.errno) == expected_api]
     # then
     self.assertEqual(len(matched), 1)
コード例 #5
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_from_dynamic_library_root(self):
     # given
     expected_api = ("rb_isalpha", ["a"], 1)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [x for x in output if (x.api, x.args, x.retval) == expected_api]
     # then
     self.assertEqual(len(matched), 1)
コード例 #6
0
 def test_apicalls_with_args(self):
     # given
     expected_api = ("atoi", ["666"])
     args = ["666", "-k", "bar"]
     output = []
     # when
     for call in apicalls(self.current_target(), args=args):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args) == expected_api]
     self.assertEqual(len(matched), 1)
コード例 #7
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_with_args(self):
     # given
     expected_api = ("atoi", ["666"])
     args = ["666", "-k", "bar"]
     output = []
     # when
     for call in apicalls(self.current_target(), args=args):
         output.append(call)
     # then
     matched = [x for x in output if (x.api, x.args) == expected_api]
     self.assertEqual(len(matched), 1)
コード例 #8
0
 def test_apicalls_root(self):
     # given
     expected_api = ("printf", ["I'm root!\n"], 10)
     output = []
     # when
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     # then
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     self.assertEqual(len(matched), 1)
コード例 #9
0
 def test_apicalls_from_dynamic_library_root(self):
     # given
     expected_api = ("rb_isalpha", ["a"], 1)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     # then
     self.assertEqual(len(matched), 1)
コード例 #10
0
 def test_apicalls_basic(self):
     # given
     expected_api = ("system", ["whoami"], 0)
     output = []
     # when
     for call in apicalls(self.current_target()):
         output.append(call)
     # then
     matched = [
         x for x in output if (x.api, x.args, x.retval) == expected_api
     ]
     self.assertEqual(len(matched), 1)
コード例 #11
0
 def test_apicalls_errno_root(self):
     # given
     expected_api = ("fopen", ["doesn't matter", "r"], 0, 2)
     # when
     output = []
     for call in apicalls(self.current_target(), run_as_root=True):
         output.append(call)
     matched = [
         x for x in output
         if (x.api, x.args, x.retval, x.errno) == expected_api
     ]
     # then
     self.assertEqual(len(matched), 1)
コード例 #12
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
    def test_apicalls_children_root(self):
        # given
        expected_grandchild_api = ("printf", ["grandchild started\n"], 19)
        expected_child_api = ("printf", ["child started\n"], 14)
        expected_parent_api = ("printf", ["parent started\n"], 15)
        pids = Set()
        output = []
        # when
        for call in apicalls(self.current_target(), run_as_root=True):
            output.append(call)
            pids.add(call.pid)

        matched_grandchild = [x for x in output if (x.api, x.args, x.retval) == expected_grandchild_api]
        matched_child = [x for x in output if (x.api, x.args, x.retval) == expected_child_api]
        matched_parent = [x for x in output if (x.api, x.args, x.retval) == expected_parent_api]
        # then
        self.assertEqual(len(matched_grandchild), 1)
        self.assertEqual(len(matched_child), 1)
        self.assertEqual(len(matched_parent), 1)
コード例 #13
0
 def test_apicalls_without_target(self):
     with self.assertRaisesRegexp(Exception,
                                  "Invalid target for apicalls()"):
         for call in apicalls(None):
             pass
コード例 #14
0
ファイル: test_apicalls.py プロジェクト: 0day29/cuckoo
 def test_apicalls_without_target(self):
     with self.assertRaisesRegexp(Exception, "Invalid target for apicalls()"):
         for call in apicalls(None):
             pass