import angr
from .shellcode_manager import ShellcodeManager
from rex.exploit import CannotExploit

import logging
l = logging.getLogger("rex.exploit.Exploit")

class Exploit(object):
    '''
    Exploit object which can leak flags or set registers
    '''

    def __init__(self, crash):
        '''
        :param crash: an exploitable crash object
        :param use_rop_cache: should rop gadgets be cached?
        :param rop_cache_file: which filename to use for a rop cache
        '''

        if not crash.exploitable():
            raise CannotExploit("crash cannot be exploited")

        self.crash = crash

        self.binary = crash.binary

        self.os = crash.project.loader.main_bin.os

        project = angr.Project(self.binary)
        # let's put together our rop gadgets
        self.rop = project.analyses.ROP()

        # and let's gather some
        self.shellcode = ShellcodeManager(project)

        self.payloads = [ ]

    def initialize(self):

        l.info("accumulating rop gadgets")

        self.rop.find_gadgets()

        for technique in Techniques[self.os]:
            p = technique(self.crash, self.rop, self.shellcode)
            try:
                l.debug("applying technique %s", p.name)
                self.payloads.append(p.apply())
            except CannotExploit as e:
                l.debug("technique failed: %s", e.message)

from .techniques import Techniques

import angr
from .shellcode_manager import ShellcodeManager
from rex.exploit import CannotExploit

import logging
l = logging.getLogger("rex.exploit.Exploit")

class Exploit(object):
    '''
    Exploit object which can leak flags or set registers
    '''

    def __init__(self, crash):
        '''
        :param crash: an exploitable crash object
        :param use_rop_cache: should rop gadgets be cached?
        :param rop_cache_file: which filename to use for a rop cache
        '''

        if not crash.exploitable():
            raise CannotExploit("crash cannot be exploited")

        self.crash = crash

        self.binary = crash.binary

        self.os = crash.project.loader.main_bin.os

        project = angr.Project(self.binary)
        # let's put together our rop gadgets
        self.rop = project.analyses.ROP()

        # and let's gather some shellcode
        self.shellcode = ShellcodeManager(project)

        self.payloads = [ ]

    def initialize(self):

        l.info("accumulating rop gadgets")

        self.rop.find_gadgets()

        for technique in Techniques[self.os]:
            p = technique(self.crash, self.rop, self.shellcode)
            try:
                l.debug("applying technique %s", p.name)
                self.payloads.append(p.apply())
            except CannotExploit as e:
                l.debug("technique failed: %s", e.message)

from .techniques import Techniques

Complete a sentence in a comment
Complete a sentence in a comment
