Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Elevate Permissions to avoid Ransomeware Crashes #3136

Open
wants to merge 5 commits 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
45 changes: 45 additions & 0 deletions cuckoo/data/analyzer/windows/modules/auxiliary/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging
from subprocess import call, STARTUPINFO, STARTF_USESHOWWINDOW
from threading import Thread

from lib.common.abstracts import Auxiliary

log = logging.getLogger(__name__)


class Permissions(Auxiliary):
"""
Change permissions for injected directory and Python interpreter
to prevent malware from messing with analysis
"""
def start(self):
if "permissions" in self.options:
if not int(self.options["permissions"]):
return

locations = ["C:\\Python27", self.analyzer.path, "C:\\WindowsAzure"]
log.debug("Adjusting permissions for %s", locations)
for location in locations:

# First add a non-inherited permission for Admin Read+Execute
# icacls <location> /grant:r "BUILTIN\Administrators:(OI)(CI)(RX)" "BUILTIN\\Administrators:(RX)" /t /c /q
modify_admin_params = ["icacls", location, "/grant:r", "BUILTIN\\Administrators:(OI)(CI)(RX)", "BUILTIN\\Administrators:(RX)", "/t", "/c", "/q"]
t1 = Thread(target=call, args=(modify_admin_params,), kwargs={"startupinfo": self.startupinfo})
t1.start()
t1.join(timeout=15)
if t1.is_alive():
log.warning("'Modify admin' call was unable to complete in 15 seconds")

# Then remove all inherited permissions so that only SYSTEM has Write access
# icacls <location> /inheritancelevel:r /t /c /q
inheritance_params = ["icacls", location, "/inheritancelevel:r", "/t", "/c", "/q"]
t2 = Thread(target=call, args=(,), kwargs={"pinfo})
t2.start()
t2.join(timeout=15)
if t2.is_alive():
log.warning("'Inheritance' call was unable to complete in 15 seconds")

def __init__(self, options={}, analyzer=None):
Auxiliary.__init__(self, options, analyzer)
self.startupinfo = STARTUPINFO()
self.startupinfo.dwFlags |= STARTF_USESHOWWINDOW