Skip to content

Commit

Permalink
Merge pull request mandiant#346 from fireeye/extract/api-jmps
Browse files Browse the repository at this point in the history
Extract/api jmps
  • Loading branch information
mr-tz authored Oct 23, 2020
2 parents 8bb3050 + 69a4b99 commit 425613e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion capa/features/extractors/ida/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_imports(ctx):

def check_for_api_call(ctx, insn):
""" check instruction for API call """
if not idaapi.is_call_insn(insn):
if not insn.get_canon_mnem() in ("call", "jmp"):
return

info = ()
Expand Down
2 changes: 1 addition & 1 deletion capa/features/extractors/viv/indirect_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def is_indirect_call(vw, va, insn=None):
if insn is None:
insn = vw.parseOpcode(va)

return insn.mnem == "call" and isinstance(insn.opers[0], envi.archs.i386.disasm.i386RegOper)
return insn.mnem in ("call", "jmp") and isinstance(insn.opers[0], envi.archs.i386.disasm.i386RegOper)


def resolve_indirect_call(vw, va, insn=None):
Expand Down
6 changes: 5 additions & 1 deletion capa/features/extractors/viv/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ def extract_insn_api_features(f, bb, insn):
#
# call dword [0x00473038]

if insn.mnem != "call":
if insn.mnem not in ("call", "jmp"):
return

if insn.mnem == "jmp":
if f.vw.getFunctionMeta(f.va, "Thunk"):
return

# traditional call via IAT
if isinstance(insn.opers[0], envi.archs.i386.disasm.i386ImmMemOper):
oper = insn.opers[0]
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ def parametrize(params, values, **kwargs):
("kernel32-64", "function=0x1800202B0", capa.features.insn.API("RtlCaptureContext"), True),
# insn/api: x64 nested thunk
("82bf6", "function=0x140059342", capa.features.insn.API("ElfClearEventLogFile"), True),
# insn/api: call via jmp
("mimikatz", "function=0x40B3C6", capa.features.insn.API("LocalFree"), True),
("c91887...", "function=0x40156F", capa.features.insn.API("CloseClipboard"), True),
# TODO ignore thunk functions that call via jmp?
# insn/api: resolve indirect calls
("c91887...", "function=0x401A77", capa.features.insn.API("kernel32.CreatePipe"), True),
("c91887...", "function=0x401A77", capa.features.insn.API("kernel32.SetHandleInformation"), True),
Expand Down

0 comments on commit 425613e

Please sign in to comment.