From 13a00a41ea1abb4826b32b130c42c174f953c270 Mon Sep 17 00:00:00 2001 From: cnheitman Date: Wed, 12 Jun 2024 13:45:20 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20=20@=20d9ed6?= =?UTF-8?q?62957bf0005ef22e8917226e028cee1e249=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tutos/hooks.html | 114 ++++++++++++++++++------------------- tutos/loaders.html | 98 ++++++++++++++++---------------- tutos/sanitizers.html | 72 ++++++++++++------------ tutos/seeds.html | 50 ++++++++--------- tutos/starting.html | 128 +++++++++++++++++++++--------------------- 5 files changed, 231 insertions(+), 231 deletions(-) diff --git a/tutos/hooks.html b/tutos/hooks.html index 3320c5e..b94fb78 100644 --- a/tutos/hooks.html +++ b/tutos/hooks.html @@ -134,15 +134,15 @@

Playing with Hooks
[41]:
 
-
- - - - - -
from tritondse.types import SolverStatus
+
from tritondse.types import SolverStatus
 
-def hook_cmp2(se: SymbolicExecutor, pstate: ProcessState, addr: int):
-    # CL contains the input of the user (hashed)
+def hook_cmp2(se: SymbolicExecutor, pstate: ProcessState, addr: int):
+    # CL contains the input of the user (hashed)
 
-    # retrieve the symbolic value of both characters
-    sym_al = pstate.read_symbolic_register(pstate.registers.al)
-    sym_cl = pstate.read_symbolic_register(pstate.registers.cl)
+    # retrieve the symbolic value of both characters
+    sym_al = pstate.read_symbolic_register(pstate.registers.al)
+    sym_cl = pstate.read_symbolic_register(pstate.registers.cl)
 
-    # Solve the constraint such that one match the other
-    status, model = pstate.solve(sym_al.getAst() == sym_cl.getAst())
+    # Solve the constraint such that one match the other
+    status, model = pstate.solve(sym_al.getAst() == sym_cl.getAst())
 
-    # If formula is SAT retrieve input values
-    if status == SolverStatus.SAT:
-        # Retrieve value of the input variable involved in the cl value here (shall be only one here)
-        var_values = pstate.get_expression_variable_values_model(sym_cl, model)
-        for var, value in var_values.items():
-            print(f"{var}: {chr(value)}")
-    else:
-        print(status.name)
+    # If formula is SAT retrieve input values
+    if status == SolverStatus.SAT:
+        # Retrieve value of the input variable involved in the cl value here (shall be only one here)
+        var_values = pstate.get_expression_variable_values_model(sym_cl, model)
+        for var, value in var_values.items():
+            print(f"{var}: {chr(value)}")
+    else:
+        print(status.name)
 
-    pstate.cpu.zf = 1
+    pstate.cpu.zf = 1
 
@@ -358,11 +358,11 @@

III. Solving queries
[48]:
 

- - -
from tritondse import SymbolicExplorator, Config, Seed, Program, ProcessState, SeedFormat, CompositeData
+
from tritondse import SymbolicExplorator, Config, Seed, Program, ProcessState, SeedFormat, CompositeData
 
-def pre_exec_hook(se: SymbolicExecutor, state: ProcessState):
-    print(f"input: {se.seed.hash} {se.seed.content.argv} ", end="")
+def pre_exec_hook(se: SymbolicExecutor, state: ProcessState):
+    print(f"input: {se.seed.hash} {se.seed.content.argv} ", end="")
 
-def post_exec_hook(se: SymbolicExecutor, state: ProcessState):
-    print(f"status:{se.seed.status.name}   [exitcode:{se.exitcode}]")
+def post_exec_hook(se: SymbolicExecutor, state: ProcessState):
+    print(f"status:{se.seed.status.name}   [exitcode:{se.exitcode}]")
 
-dse = SymbolicExplorator(Config(seed_format=SeedFormat.COMPOSITE), p)
-dse.add_input_seed(Seed(CompositeData(argv=[b"./crackme_xor", b"AAAAAAAAAAAA"])))
+dse = SymbolicExplorator(Config(seed_format=SeedFormat.COMPOSITE), p)
+dse.add_input_seed(Seed(CompositeData(argv=[b"./crackme_xor", b"AAAAAAAAAAAA"])))
 
-dse.callback_manager.register_pre_execution_callback(pre_exec_hook)
-dse.callback_manager.register_post_execution_callback(post_exec_hook)
+dse.callback_manager.register_pre_execution_callback(pre_exec_hook)
+dse.callback_manager.register_post_execution_callback(post_exec_hook)
 
-dse.explore()
+dse.explore()
 
diff --git a/tutos/loaders.html b/tutos/loaders.html index 3687cbb..b64bb49 100644 --- a/tutos/loaders.html +++ b/tutos/loaders.html @@ -124,13 +124,13 @@

Linux ELF loader
[4]:
 

- - - -
class Loader(object):
-    def __init__(self, path: str):
-        self.bin_path = Path(path)
+
class Loader(object):
+    def __init__(self, path: str):
+        self.bin_path = Path(path)
 
-    @property
-    def name(self) -> str:
-        raise NotImplementedError()
+    @property
+    def name(self) -> str:
+        raise NotImplementedError()
 
-    @property
-    def entry_point(self) -> Addr:
-        raise NotImplementedError()
+    @property
+    def entry_point(self) -> Addr:
+        raise NotImplementedError()
 
-    @property
-    def architecture(self) -> Architecture:
-        raise NotImplementedError()
+    @property
+    def architecture(self) -> Architecture:
+        raise NotImplementedError()
 
-    @property
-    def arch_mode(self) -> Optional[ArchMode]:
-        return None
+    @property
+    def arch_mode(self) -> Optional[ArchMode]:
+        return None
 
-    @property
-    def platform(self) -> Optional[Platform]:
-        return None
+    @property
+    def platform(self) -> Optional[Platform]:
+        return None
 
-    def memory_segments(self) -> Generator[LoadableSegment, None, None]:
-        raise NotImplementedError()
+    def memory_segments(self) -> Generator[LoadableSegment, None, None]:
+        raise NotImplementedError()
 
-    @property
-    def cpustate(self) -> Dict[str, int]:
-        return {}
+    @property
+    def cpustate(self) -> Dict[str, int]:
+        return {}
 
 
-    def imported_functions_relocations(self) -> Generator[Tuple[str, Addr], None, None]:
-        yield from ()
+    def imported_functions_relocations(self) -> Generator[Tuple[str, Addr], None, None]:
+        yield from ()
 
-    def imported_variable_symbols_relocations(self) -> Generator[Tuple[str, Addr], None, None]:
-        yield from ()
+    def imported_variable_symbols_relocations(self) -> Generator[Tuple[str, Addr], None, None]:
+        yield from ()
 
-    def find_function_addr(self, name: str) -> Optional[Addr]:
-        return None
+    def find_function_addr(self, name: str) -> Optional[Addr]:
+        return None
 
diff --git a/tutos/sanitizers.html b/tutos/sanitizers.html index 0745e0f..f363ca3 100644 --- a/tutos/sanitizers.html +++ b/tutos/sanitizers.html @@ -148,12 +148,12 @@

Using built-in sanitizers
[2]:
 

- -
from tritondse import ProbeInterface, SymbolicExecutor, ProcessState, CbType, SeedStatus
-from tritondse.types import Addr, SolverStatus
+
from tritondse import ProbeInterface, SymbolicExecutor, ProcessState, CbType, SeedStatus
+from tritondse.types import Addr, SolverStatus
 
-class OpenSanitizer(ProbeInterface):
+class OpenSanitizer(ProbeInterface):
 
-    PASSWD_FILE = "/etc/passwd"
+    PASSWD_FILE = "/etc/passwd"
 
-    def __init__(self):
-        super(OpenSanitizer, self).__init__()
-        self._add_callback(CbType.PRE_RTN, self.fopen_check, 'fopen')
-        self._add_callback(CbType.PRE_RTN, self.fopen_check, 'freopen')
-
-    def fopen_check(self, se: SymbolicExecutor, pstate: ProcessState, rtn_name: str, addr: Addr):
-        # the filepath is located in arg0 (ptr to a string)
-        string_ptr = se.pstate.get_argument_value(0)
-
-        symbolic = True
-        cur_ptr = string_ptr
-        while pstate.read_memory_int(cur_ptr, 1):        # while different from 0
-            if not se.pstate.is_memory_symbolic(cur_ptr, 1): # check that the byte is symbolic
-                symbolic = False
-            cur_ptr += 1
-
-        # if all memory bytes are symbolic and we have enough place to fit our string
-        if symbolic and (cur_ptr - string_ptr) > len(self.PASSWD_FILE):
-
-            # Try to solve by SMT that the filepath string is /etc/passwd
-            constraints = [pstate.read_symbolic_memory_byte(string_ptr+i).getAst() == ord(pwd_byte) for i, pwd_byte in enumerate(self.PASSWD_FILE)]
-            st, model = pstate.solve(constraints)
-
-            if st == SolverStatus.SAT:                          # if formula satisfiable
-                new_seed = se.mk_new_seed_from_model(model)  # create a new input from the model
-                new_seed.status = SeedStatus.CRASH           # mark it as crash
-                se.enqueue_seed(new_seed)                    # enqueue it *(so that it will put in the workspace..)*
+    def __init__(self):
+        super(OpenSanitizer, self).__init__()
+        self._add_callback(CbType.PRE_RTN, self.fopen_check, 'fopen')
+        self._add_callback(CbType.PRE_RTN, self.fopen_check, 'freopen')
+
+    def fopen_check(self, se: SymbolicExecutor, pstate: ProcessState, rtn_name: str, addr: Addr):
+        # the filepath is located in arg0 (ptr to a string)
+        string_ptr = se.pstate.get_argument_value(0)
+
+        symbolic = True
+        cur_ptr = string_ptr
+        while pstate.read_memory_int(cur_ptr, 1):        # while different from 0
+            if not se.pstate.is_memory_symbolic(cur_ptr, 1): # check that the byte is symbolic
+                symbolic = False
+            cur_ptr += 1
+
+        # if all memory bytes are symbolic and we have enough place to fit our string
+        if symbolic and (cur_ptr - string_ptr) > len(self.PASSWD_FILE):
+
+            # Try to solve by SMT that the filepath string is /etc/passwd
+            constraints = [pstate.read_symbolic_memory_byte(string_ptr+i).getAst() == ord(pwd_byte) for i, pwd_byte in enumerate(self.PASSWD_FILE)]
+            st, model = pstate.solve(constraints)
+
+            if st == SolverStatus.SAT:                          # if formula satisfiable
+                new_seed = se.mk_new_seed_from_model(model)  # create a new input from the model
+                new_seed.status = SeedStatus.CRASH           # mark it as crash
+                se.enqueue_seed(new_seed)                    # enqueue it *(so that it will put in the workspace..)*
 
@@ -208,7 +208,7 @@

Writing a sanitizer
[4]:
 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dse.execution_count
+
dse.execution_count