Skip to content
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

Update miasm version #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ addons:
- python-virtualenv
- unzip
- gcc-multilib
- python-future
before_script:
- "cd .."
# make virtual env
- "python /usr/lib/python2.7/dist-packages/virtualenv.py virtualenv;"
- "cd virtualenv;"
- "source bin/activate;"
# install elfesteem
- "git clone https://github.com/serpilliere/elfesteem elfesteem && cd elfesteem && python setup.py install && cd ..;"
# install pyparsing
- "pip install pyparsing"
# install future
- "pip install future"
# install miasm
- "cd ..;git clone -b 'v0.1.1' https://github.com/cea-sec/miasm miasm && cd miasm;"
- "cd ..;git clone https://github.com/cea-sec/miasm miasm && cd miasm && git checkout 6faf83fe27bbfc7fec501d9b674480f02edea854;"
- "python setup.py build build_ext -I$(pwd)/../virtualenv/include -L$(pwd)/../virtualenv/tinycc"
- "python setup.py install"
- "cd ..;"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ RUN cd /opt &&\
tar xzvf Sibyl.tar.gz &&\
rm Sibyl.tar.gz &&\
mv Sibyl-master Sibyl &&\
chown -Rh miasm2 Sibyl &&\
chown -Rh miasm Sibyl &&\
cd Sibyl &&\
python setup.py install

# Prepare the environment
WORKDIR /opt/Sibyl
USER miasm2
USER miasm

CMD ["/usr/local/bin/sibyl"]
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Copyright 2014 - 2019 [Camille MOUGEY](mailto:[email protected])
Sibyl
=====

A _Miasm2_ based function divination.
A _Miasm_ based function divination.

Idea
----
Expand All @@ -16,7 +16,7 @@ But it is a time consuming task. Moreover, this task is made more difficult due

Tools have been developed to automate this task. Some are based on CFG (Control Flow Graph) signature (_Bindiff_), others on magic constants (_FindCrypt_) or enhanced pattern matching (_FLIRT_).

_Sibyl_ is one of these tools, dynamic analysis oriented and **based on _Miasm2_** (https://github.com/cea-sec/miasm).
_Sibyl_ is one of these tools, dynamic analysis oriented and **based on _Miasm_** (https://github.com/cea-sec/miasm).
The idea is to identify functions from their side effects. That way, identification is independent of the used implementation.

Identifications are done thanks to these steps:
Expand Down Expand Up @@ -167,7 +167,7 @@ Installation

### Standard

_Sibyl_ requires at least _Miasm2_ version `v0.1.1` and the corresponding version of _Elfesteem_.
_Sibyl_ requires at least _Miasm_ version `v0.1.3`.
For the `qemu` engine, the `unicorn` python package must be installed (refer to the documentation of Unicorn for more detail).

_Sibyl_ comes as a Python module, and the installation follow the standard procedure:
Expand Down Expand Up @@ -253,7 +253,7 @@ To avoid these behaviors, there is a timeout on each sub-test. The _-i/--timeout

### How to run the tool on a custom architecture?

Once the architecture and corresponding semantic is implemented in Miasm2, one just needs to implement the wanted ABI in _sibyl/abi/_.
Once the architecture and corresponding semantic is implemented in Miasm, one just needs to implement the wanted ABI in _sibyl/abi/_.
If writing the jitter engine part is an issue, one can directly use the _python_ jitter option with _-j/--jitter_ argument.
If the semantic is not complete enough, one can add the corresponding bridge with _qemu_ in `sibyl/engine/qemu.py`, if available.

Expand Down
2 changes: 1 addition & 1 deletion doc/LEARNING.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ restrictive implementation, or a useless argument.

The resulting test looks like:
```Python
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE

from sibyl.test.test import TestHeader, TestSetTest

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
url='https://github.com/cea-sec/sibyl',
download_url='https://github.com/cea-sec/sibyl/tarball/master',
license='GPLv3+',
description='A Miasm2 based function divination',
description='A Miasm based function divination',
long_description="""
Sibyl is a tool aiming at recognizing functions in binaries based on their side
effects, by running them in a sandboxed environment.""",
keywords=["reverse engineering", "emulation"],
install_requires=[
'miasm2',
'miasm',
],
packages=['sibyl', 'sibyl/abi', 'sibyl/engine', 'sibyl/learn',
'sibyl/learn/tracer', 'sibyl/learn/generator',
Expand Down
4 changes: 2 additions & 2 deletions sibyl/actions/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import sys
from collections import namedtuple

from miasm2.analysis.machine import Machine
from miasm2.analysis.binary import Container
from miasm.analysis.machine import Machine
from miasm.analysis.binary import Container

from sibyl.config import config
from sibyl.testlauncher import TestLauncher
Expand Down
4 changes: 2 additions & 2 deletions sibyl/actions/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import os

from miasm2.analysis.machine import Machine
from miasm2.analysis.binary import Container
from miasm.analysis.machine import Machine
from miasm.analysis.binary import Container

from sibyl.config import config, config_paths
from sibyl.actions.action import Action
Expand Down
2 changes: 1 addition & 1 deletion sibyl/actions/learn.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import logging

from miasm2.analysis.binary import Container
from miasm.analysis.binary import Container

from sibyl.actions.action import Action
from sibyl.learn.tracer import AVAILABLE_TRACER
Expand Down
6 changes: 3 additions & 3 deletions sibyl/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
except ImportError:
pycparser = None
else:
from miasm2.core.ctypesmngr import c_to_ast, CTypeFunc
from miasm2.core.objc import ObjCPtr, ObjCArray
from miasm.core.ctypesmngr import c_to_ast, CTypeFunc
from miasm.core.objc import ObjCPtr, ObjCArray

def init_logger(name):
logger = logging.getLogger(name)
Expand Down Expand Up @@ -51,7 +51,7 @@ class HeaderFile(object):
def __init__(self, header_data, ctype_manager):
"""Parse @header_data to fill @ctype_manager
@header_data: str of a C-like header file
@ctype_manager: miasm2.core.objc.CTypesManager instance"""
@ctype_manager: miasm.core.objc.CTypesManager instance"""
self.data = header_data
self.ctype_manager = ctype_manager

Expand Down
8 changes: 4 additions & 4 deletions sibyl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, default_config, files):
def expandpath(path):
"""Expand @path with following rules:
- $SIBYL is replaced by the installation path of Sibyl
- $MIASM is replaced by the installation path of miasm2
- $MIASM is replaced by the installation path of miasm
- path are expanded ('~' -> '/home/user', ...)
"""
if "$SIBYL" in path:
Expand All @@ -76,9 +76,9 @@ def expandpath(path):
path = path.replace("$SIBYL", sibyl_base)

if "$MIASM" in path:
import miasm2
miasm2_base = miasm2.__path__[0]
path = path.replace("$MIASM", miasm2_base)
import miasm
miasm_base = miasm.__path__[0]
path = path.replace("$MIASM", miasm_base)

path = os.path.expandvars(path)
path = os.path.expanduser(path)
Expand Down
2 changes: 1 addition & 1 deletion sibyl/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module abstracts running engine"""

from sibyl.engine.qemu import QEMUEngine
from sibyl.engine.miasm import MiasmEngine
from sibyl.engine.miasm_engine import MiasmEngine
2 changes: 1 addition & 1 deletion sibyl/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Engine(object):

def __init__(self, machine):
"""Instanciate an Engine
@machine: miasm2.analysis.machine:Machine instance"""
@machine: miasm.analysis.machine:Machine instance"""
self.logger = init_logger(self.__class__.__name__)

def take_snapshot(self):
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions sibyl/engine/qemu.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from miasm2.core.utils import pck32, pck64
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm.core.utils import pck32, pck64
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
try:
import unicorn
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion sibyl/heuristics/arch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"Module for architecture guessing"

from miasm2.analysis.binary import Container, ContainerUnknown
from miasm.analysis.binary import Container, ContainerUnknown

from sibyl.heuristics.heuristic import Heuristic

Expand Down
6 changes: 3 additions & 3 deletions sibyl/heuristics/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import shutil
import os

from miasm2.core.asmblock import AsmBlockBad, log_asmblock
from miasm.core.asmblock import AsmBlockBad, log_asmblock

from sibyl.heuristics.heuristic import Heuristic
import sibyl.heuristics.csts as csts
Expand Down Expand Up @@ -225,8 +225,8 @@ class FuncHeuristic(Heuristic):

def __init__(self, cont, machine, filename):
"""
@cont: miasm2's Container instance
@machine: miasm2's Machine instance
@cont: miasm's Container instance
@machine: miasm's Machine instance
@filename: target's filename
"""
super(FuncHeuristic, self).__init__()
Expand Down
21 changes: 9 additions & 12 deletions sibyl/learn/findref.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import struct
import logging

from miasm2.jitter.loader.elf import vm_load_elf
from miasm2.analysis.machine import Machine
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL, EXCEPT_DIV_BY_ZERO, EXCEPT_PRIV_INSN
from miasm2.core.bin_stream import bin_stream_vm
from miasm2.analysis.dse import ESETrackModif
import miasm2.expression.expression as m2_expr
from miasm2.ir.ir import AssignBlock
from miasm2.core.objc import CHandler
from miasm.jitter.loader.elf import vm_load_elf
from miasm.analysis.machine import Machine
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL, EXCEPT_DIV_BY_ZERO, EXCEPT_PRIV_INSN
from miasm.core.bin_stream import bin_stream_vm
from miasm.analysis.dse import ESETrackModif
import miasm.expression.expression as m2_expr
from miasm.ir.ir import AssignBlock
from miasm.core.objc import CHandler

from sibyl.commons import objc_is_dereferenceable
from sibyl.config import config
Expand Down Expand Up @@ -227,17 +227,14 @@ def prepare_symbexec(self, jitter, return_addr):
self.symb.reset_regs()
self.symb.update_engine_from_cpu()

## Load the memory as ExprMem
self.symb.func_read = None
self.symb.func_write = None
for base_addr, mem_segment in jitter.vm.get_all_memory().iteritems():
# Split into 8 bytes chunk for get_mem_overlapping
for start in xrange(0, mem_segment["size"], 8):
expr_mem = m2_expr.ExprMem(m2_expr.ExprInt(base_addr + start,
size=64),
size=8*min(8, mem_segment["size"] - start))
# Its initialisation, self.symb.apply_change is not necessary
self.symb.symbols[expr_mem] = self.symb._func_read(expr_mem)
self.symb.symbols[expr_mem] = self.symb.mem_read(expr_mem)

## Save the initial state
self.symbols_init = self.symb.symbols.copy()
Expand Down
2 changes: 1 addition & 1 deletion sibyl/learn/generator/generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from miasm2.analysis.machine import Machine
from miasm.analysis.machine import Machine


class Generator(object):
Expand Down
8 changes: 4 additions & 4 deletions sibyl/learn/generator/pythongenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from sibyl.learn.generator.generator import Generator
from sibyl.learn.generator import templates as TPL
from sibyl.learn.trace import MemoryAccess
from miasm2.ir.ir import AssignBlock
from miasm.ir.ir import AssignBlock

from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm2.expression.expression import *
from miasm2.expression.simplifications import expr_simp
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm.expression.expression import *
from miasm.expression.simplifications import expr_simp

from sibyl.commons import objc_is_dereferenceable

Expand Down
2 changes: 1 addition & 1 deletion sibyl/learn/generator/templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python
imports = """
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE

from sibyl.test.test import TestHeader, TestSetTest
""".strip()
Expand Down
6 changes: 3 additions & 3 deletions sibyl/learn/learn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import pycparser
except ImportError:
raise ImportError("pycparser module is needed to learn and generate")
from miasm2.core.objc import CTypesManagerNotPacked
from miasm2.core.ctypesmngr import CAstTypes
from miasm2.arch.x86.ctype import CTypeAMD64_unk
from miasm.core.objc import CTypesManagerNotPacked
from miasm.core.ctypesmngr import CAstTypes
from miasm.arch.x86.ctype import CTypeAMD64_unk

from sibyl.learn.replay import Replay
from sibyl.learn.findref import ExtractRef
Expand Down
6 changes: 3 additions & 3 deletions sibyl/learn/replay.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import struct

from miasm2.jitter.loader.elf import vm_load_elf
from miasm2.analysis.machine import Machine
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL, EXCEPT_DIV_BY_ZERO, EXCEPT_PRIV_INSN
from miasm.jitter.loader.elf import vm_load_elf
from miasm.analysis.machine import Machine
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE, EXCEPT_ACCESS_VIOL, EXCEPT_DIV_BY_ZERO, EXCEPT_PRIV_INSN

from sibyl.config import config

Expand Down
6 changes: 3 additions & 3 deletions sibyl/learn/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import struct

from sibyl.learn.replay import Replay
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm2.core.graph import DiGraph
from miasm2.analysis.machine import Machine
from miasm.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm.core.graph import DiGraph
from miasm.analysis.machine import Machine


class Trace(list):
Expand Down
2 changes: 1 addition & 1 deletion sibyl/learn/tracer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from sibyl.learn.tracer.pin import TracerPin
from sibyl.learn.tracer.miasm import TracerMiasm
from sibyl.learn.tracer.miasm_tracer import TracerMiasm

AVAILABLE_TRACER = {
"pin": TracerPin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from sibyl.learn.tracer.tracer import Tracer
from sibyl.learn.trace import Trace, Snapshot

from miasm2.jitter.emulatedsymbexec import EmulatedSymbExec
from miasm2.jitter.csts import PAGE_READ
from miasm2.analysis.machine import Machine
from miasm2.jitter.loader.elf import vm_load_elf
from miasm.jitter.emulatedsymbexec import EmulatedSymbExec
from miasm.jitter.csts import PAGE_READ
from miasm.analysis.machine import Machine
from miasm.jitter.loader.elf import vm_load_elf

class CustomEmulatedSymbExec(EmulatedSymbExec):
'''New emulator that trap all memory read and write which is needed by the miasm tracer'''
Expand All @@ -35,19 +35,19 @@ def remove_write_callback(self, callback):
'''Remove a write callback'''
self._write_callback.remove(callback)

def _func_read(self, expr_mem):
def mem_read(self, expr_mem):
'''Function call for each read. We overwrite it to intercept the read'''
for callback in self._read_callback:
callback(self, expr_mem)

return super(CustomEmulatedSymbExec, self)._func_read(expr_mem)
return super(CustomEmulatedSymbExec, self).mem_read(expr_mem)

def _func_write(self, symb_exec, dest, data):
def mem_write(self, dest, data):
'''Function call for each write. We overwrite it to intercept the write'''
for callback in self._write_callback:
callback(self, dest, data)

super(CustomEmulatedSymbExec, self)._func_write(symb_exec, dest, data)
super(CustomEmulatedSymbExec, self).mem_write(dest, data)


class TracerMiasm(Tracer):
Expand All @@ -64,7 +64,7 @@ def read_callback(self, symb_exec, expr_mem):
'''Read callback that add the read event to the snapshot'''
addr = int(expr_mem.ptr)
size = expr_mem.size / 8
value = int(symb_exec.cpu.get_mem(addr, size)[::-1].encode("hex"), 16)
value = int(symb_exec.vm.get_mem(addr, size)[::-1].encode("hex"), 16)

self.current_snapshot.add_memory_read(addr, size, value)

Expand Down
Loading