Skip to content

behavior tree rewrite #2143

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 31 additions & 5 deletions modules/processing/behavior.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,9 @@
import logging
import os
import struct
from copy import deepcopy
from contextlib import suppress
from collections import OrderedDict

from lib.cuckoo.common.abstracts import Processing
from lib.cuckoo.common.compressor import CuckooBsonCompressor
@@ -1001,8 +1003,25 @@ class ProcessTree:
key = "processtree"

def __init__(self):

self.processes = []
self.tree = []
"""
{
"pid_graph": {
<parent1>: [<child11>, <child12>, ...],
<parent2>: [<child21>, <child22>...],
...
},
pid_map: {}
}
"""
self.graph_tree = {
"pid_graph": OrderedDict(),
"pid_map": {},
}

# self.graph_tree["pid_map"][10664]

def add_node(self, node, tree):
"""Add a node to a process tree.
@@ -1016,7 +1035,9 @@ def add_node(self, node, tree):
# If the current process has the same ID of the parent process of
# the provided one, append it the children.
if process["pid"] == node["parent_id"]:
self.graph_tree["pid_graph"].setdefault(str(process["pid"]), list()).append(str(node["pid"]))
process["children"].append(node)
# self.graph_tree["pid_map"][node["pid"]] = node
ret = True
break
# Otherwise try with the children of the current process.
@@ -1053,25 +1074,30 @@ def run(self):
for process_again in self.processes:
if process_again == process:
continue
# If we find a parent for the first process, we mark it as
# as a child.

str_pid = str(process["pid"])
# If we find a parent for the first process, we mark it as a child.
if process_again["pid"] == process["parent_id"]:
self.graph_tree["pid_graph"][str_pid] = list()
self.graph_tree["pid_map"][str_pid] = deepcopy(process)
has_parent = True
break

# If the process has a parent, add it to the children list.
if has_parent:
children.append(process)
self.graph_tree["pid_graph"][str_pid] = list()
self.graph_tree["pid_map"][str_pid] = deepcopy(process)
# Otherwise it's an orphan and we add it to the tree root.
else:
self.tree.append(process)

self.graph_tree["pid_graph"][str_pid] = list()
self.graph_tree["pid_map"][str_pid] = deepcopy(process)
# Now we loop over the remaining child processes.
for process in children:
if not self.add_node(process, self.tree):
self.tree.append(process)

return self.tree
return self.graph_tree


class EncryptedBuffers:
28 changes: 18 additions & 10 deletions web/analysis/templatetags/generic_tags.py
Original file line number Diff line number Diff line change
@@ -12,20 +12,25 @@ def endswith(value, thestr):

@register.filter("proctreetolist")
def proctreetolist(tree):
outlist = []
if not tree:
return outlist
stack = deque(tree)
return []
graph = {}
outlist = []
stack = deque(tree.get("pid_graph", {}).keys())
while stack:
node = stack.popleft()
pid_id = stack.popleft()
is_special = False
if "startchildren" in node or "endchildren" in node:
if "startchildren" in pid_id or "endchildren" in pid_id:
is_special = True
outlist.append(node)
outlist.append(pid_id)
else:
node = tree["pid_map"][pid_id]
str_pid = str(node["pid"])
newnode = {}
newnode["pid"] = node["pid"]
newnode["pid"] = str_pid
newnode["name"] = node["name"]
newnode["parent_id"] = str(node["parent_id"])

if "module_path" in node:
newnode["module_path"] = node["module_path"]
if "environ" in node and "CommandLine" in node["environ"]:
@@ -49,10 +54,13 @@ def proctreetolist(tree):
cmdline = cmdline[:200] + " ...(truncated)"
newnode["commandline"] = convert_to_printable(cmdline)
outlist.append(newnode)
graph[str_pid] = newnode

if is_special:
continue
if node["children"]:
for child in tree["pid_graph"][pid_id]:
stack.appendleft({"endchildren": 1})
stack.extendleft(reversed(node["children"]))
stack.extendleft([child])
stack.appendleft({"startchildren": 1})
return outlist

return outlist

Unchanged files with check annotations Beta

strings:
$trap0 = {81 C6 00 10 00 00 [0-88] 81 FE 00 F0 [2] 0F 84 [2] 00 00}
$trap1 = {31 FF [0-128] (B9|C7 85 F8 00 00 00) 60 5F A9 00}
$antihook = {FF 34 08 [0-360] 8F 04 0B [0-360] 83 F9 18 [0-460] FF E3}

Check warning on line 11 in analyzer/windows/data/yara/Guloader.yar

VirusTotal YARA-CI / Rules Analysis

analyzer/windows/data/yara/Guloader.yar#L11

rule "GuloaderB": string "$antihook" may slow down scanning
$trap2 = {83 BD 9C 00 00 00 00 0F 85 [2] 00 00}
condition:
3 of them
$trap0 = {81 C6 00 10 00 00 [0-148] (39 CE|3B B5) [0-6] 0F 84 [2] 00 00}
$trap0A = {E8 00 00 00 00 59 [0-2800] 81 C6 00 10 00 00 [0-148] (39 CE|3B B5) [0-6] 0F 84 [2] 00 00}
$trap1 = {89 D6 60 0F 31 B8 [4] (05|35|2D|B8) [4] (05|35|2D|B8) [4] (05|35|2D|B8) [4] 0F A2}
$antihook = {FF 34 08 [0-360] 8F 04 0B [0-800] FF E3}

Check warning on line 44 in analyzer/windows/data/yara/Guloader.yar

VirusTotal YARA-CI / Rules Analysis

analyzer/windows/data/yara/Guloader.yar#L44

rule "GuloaderC": string "$antihook" may slow down scanning
condition:
3 of them
}
$trap1 = {49 83 F9 00 75 [1-20] 83 FF 00 [2-6] 81 FF}
$trap2 = {39 CB 59 01 D7 49 85 C8 83 F9 00 75 B3}
$trap3 = {61 0F AE E8 0F 31 0F AE E8 C1 E2 20 09 C2 29 F2 83 FA 00 7E CE C3}
$antihook = {FF 34 08 [0-360] 8F 04 0B [0-800] FF E3}

Check warning on line 12 in data/yara/CAPE/Guloader.yar

VirusTotal YARA-CI / Rules Analysis

data/yara/CAPE/Guloader.yar#L12

rule "Guloader": string "$antihook" may slow down scanning
$antidbg = {39 48 04 0F 85 [4] 39 48 08 0F 85 [4] 39 48 0C 0F 85 [4] 39 48 10 0F 85 [4] 39 48 14 0F 85 [4] 39 48 18 0F 85}
$except = {8B 45 08 8B 00 [0-1] 8B 58 18 [0-20] 81 38 05 00 00 C0 0F 85 [4-7] 83 FB 00 (0F 84|74)}
$cape_string = "cape_options"
$download2 = {8B 75 ?? 8D 4D ?? 8B 7D ?? 8B D6 57 89 1E 89 1F E8 [4] 59 3D C8 00 00 00 75 05 33 C0 40 EB}
$download3 = {B8 50 00 00 00 66 89 45 ?? 4C 89 65 ?? 4C 89 75 ?? E8 [4] 48 8B 1E 3D 94 01 00 00}
$major_ver = {0F B6 05 ?? ?? ?? ?? 6A ?? 6A 72 FF 75 0C 6A 70 50 FF 35 ?? ?? ?? ?? 8D 45 80 FF 35 ?? ?? ?? ?? 6A 63 FF 75 08 6A 67 50 FF 75 10 FF 15 ?? ?? ?? ?? 83 C4 38 8B E5 5D C3}
$decode1 = {4? 8D [5-6] 8A 4? [1-3] 32 }//0? 01 88 44 [2] 4?}

Check warning on line 18 in data/yara/CAPE/IcedIDLoader.yar

VirusTotal YARA-CI / Rules Analysis

data/yara/CAPE/IcedIDLoader.yar#L18

rule "IcedIDLoader": string "$decode1" may slow down scanning
$decode2 = {42 0F B6 4C 02 ?? 42 0F B6 04 02 32 C8 88 8C 15 ?? ?? ?? ?? 48 FF C2 48 83 FA 20}
condition:
2 of them