All Projects → alexander-hanel → hansel

alexander-hanel / hansel

Licence: other
Hansel - a simple but flexible search for IDA

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to hansel

Abyss
abyss - IDAPython Plugin for Postprocessing of Hexrays Decompiler Output
Stars: ✭ 161 (+544%)
Mutual labels:  idapython
Awesome Reverse Engineering
Reverse Engineering Resources About All Platforms(Windows/Linux/macOS/Android/iOS/IoT) And Every Aspect! (More than 3500 open source tools and 2300 posts&videos)
Stars: ✭ 2,954 (+11716%)
Mutual labels:  idapython
ida migrator
IDA Migrator is an IDA Pro plugin which helps migrate existing work from one database instance to another. It Conveniently migrates function names, structures and enums.
Stars: ✭ 65 (+160%)
Mutual labels:  idapython
Hrast
PoC of modifying HexRays AST
Stars: ✭ 178 (+612%)
Mutual labels:  idapython
Hexraystoolbox
Hexrays Toolbox - Find code patterns within the Hexrays AST
Stars: ✭ 202 (+708%)
Mutual labels:  idapython
Nao
Simple No-meaning Assembly Omitter for IDA Pro (This is just a prototype)
Stars: ✭ 228 (+812%)
Mutual labels:  idapython
Amie
A Minimalist Instruction Extender for the ARM architecture and IDA Pro
Stars: ✭ 136 (+444%)
Mutual labels:  idapython
ida-embed-arch-disasm
Allows IDA PRO to disassemble x86-64 code (WOW64) in 32-bit database
Stars: ✭ 22 (-12%)
Mutual labels:  idapython
Idangr
Use angr in the IDA Pro debugger generating a state from the current debug session
Stars: ✭ 214 (+756%)
Mutual labels:  idapython
ida-scripts
Collection of IDA Pro/Hex-Rays configs, scripts, and plugins
Stars: ✭ 18 (-28%)
Mutual labels:  idapython
Fakepdb
Tool for PDB generation from IDA Pro database
Stars: ✭ 186 (+644%)
Mutual labels:  idapython
Hrdevhelper
Context-sensitive HexRays decompiler plugin that visualizes the ctree of decompiled functions.
Stars: ✭ 193 (+672%)
Mutual labels:  idapython
DriverBuddyReloaded
Driver Buddy Reloaded is an IDA Pro Python plugin that helps automate some tedious Windows Kernel Drivers reverse engineering tasks
Stars: ✭ 210 (+740%)
Mutual labels:  idapython
Ida Minsc
IDA-minsc is a plugin for IDA Pro that simplifies IDAPython. The API is grouped into contextual modules, and is dumbed down by removing the concept of types (DWIM). This allows one to script w/ very little investment or the need for documentation. Click "Watch" to keep track of any ongoing development, and smash that "Star" button if you like this.
Stars: ✭ 170 (+580%)
Mutual labels:  idapython
DrGadget
dr.rer.oec.gadget IDAPython plugin for the Interactive Disassembler <ABANDONED PROJECT>
Stars: ✭ 61 (+144%)
Mutual labels:  idapython
Genmc
Display Hex-Rays Microcode
Stars: ✭ 159 (+536%)
Mutual labels:  idapython
Uefi retool
A tool for UEFI firmware reverse engineering
Stars: ✭ 227 (+808%)
Mutual labels:  idapython
Hyara
Yara rule making tool (IDA Pro & Binary Ninja & Cutter Plugin)
Stars: ✭ 142 (+468%)
Mutual labels:  idapython
xray
Hexrays decompiler plugin that colorizes and filters the decompiler's output based on regular expressions
Stars: ✭ 97 (+288%)
Mutual labels:  idapython
re-scripts
IDA, Ghidra and Radare2 scripts. Also Android scripts to make your life easier.
Stars: ✭ 47 (+88%)
Mutual labels:  idapython

Hansel

A simple but flexible search for IDA.

Bytes, strings, symbols and values from enumerated types are sometimes all that is needed to identify a function’s functionality. For example, cross-referencing CreateToolhelp32Snapshot and TerminateProcess to a single function can be used to inter that an executable might have functionality to kill a remote process. Or another example might be identifying a function as SHA256 because of the presence of 0x6a09e667 and 0xbb67ae85. Overtime functionality can be quickly identified during the reverse engineering process because of the reappearing attributes. Hansel can be used to search for these attributes, label and comment functions with these attributes or automatically extract these attributes from a function. All of this starts with the search function. It can contain arguments of strings (foo), integers (0xFFFFFFFF) or byte patterns ({55 8B EC}). There are keywords that are covered later on. The goal of the search is to be as simple as possible. Nothing needs to be defined from a search perspective. The following snippet searches for CreateToolhelp32Snapshot and TerminateProcess. The return of search is a tuple. The first value is a bool stating if the search was True or False. The second value is a set of offsets that contains the start offset of function or functions the search matches on.

Python>search("CreateToolhelp32Snapshot", 0xFFFFFFFF, "TerminateProcess", )
(True, set([4249808L]))

To rename the function that matches the search add ”rename=NewFunctionName”. To add a function comment that matches the search add comment="My Comment". The following snippet is the previous search with function comment and labeling added.

search("CreateToolhelp32Snapshot", 0xFFFFFFFF, "TerminateProcess", rename="kill_process", comment="kill process" )

Searches can be saved to a rules file by calling save_search(). This function must contain filename="FILE.rule”. The following snippet is the working example saved to a file named kill_process.rule.

save_search("CreateToolhelp32Snapshot", 0xFFFFFFFF, "TerminateProcess", filename="kill_process.rule", rename="kill_process", comment="kill process") 

To search using rules saved in a file the function run_rule(rule_name) is used.

Python>run_rule("kill_process.rule")
RULE(s): C:/Users/this/Documents/repo/hansel\rules\kill_process.rule
	SEARCH: ['CreateToolhelp32Snapshot', 4294967295L, 'TerminateProcess']
	Match at 0x40e8a0

To run all rules the function run_rules() can be used. Attributes can be extracted from a function by calling generate_skeleton(ea).

Python>generate_skeleton(here())
['CreateToolhelp32Snapshot', 0, 2, 1, 556, 'lstrlenW', 'Process32NextW', 'OpenProcess', 'CharUpperBuffW', 'Process32FirstW', 1600, 'lstrcpyW', 4294965704L, 4294965696L, 'CloseHandle', 'TerminateProcess', 'lstrcmpW', 4294965732L, 4294966252L, 4294966772L, 4294967292L, 4294967295L]

To quickly save attributes from a function and revisit them at a later date, the hotkey ALT-/ can be used. The rules are saved in the rules directory within the working directory of the Hansel repo. The rule file name is the current date YEAR-MONTH-DAY.rule (example: 2019-03-03.rule). The search contains a field name context that has the IDB path and function offset. The following is an example of a rule file.

{"search_terms": ["CreateToolhelp32Snapshot", 0, 2, 1, 556, "lstrlenW", "Process32NextW", "OpenProcess", "CharUpperBuffW", "Process32FirstW", 1600, "lstrcpyW", 4294965704, 4294965696, "CloseHandle", "TerminateProcess", "lstrcmpW", 4294965732, 4294966252, 4294966772, 4294967292, 4294967295], "kwargs": {"context": "C:\\Users\\REMOVED\\Desktop\\foo.idb, 0x40e8a0"}}

The function cheat_sheet() can used to retrieve all the needed APIS and their keywords.

Python>cheat_sheet()

    search("query1", "query2", comment="My_Comment", rename="FUNCTION_NAME")
    save_search( "query1", file_name="RULE_NAME.rule", comment="My_Comment", rename="FUNCTION_NAME")
    run_rule("RULES_NAME.rule")
    run_rules() <- no arguments
    hot_key() <- saves output of generate_skelton(ea) to rules directory with the date as the name   
    added by hot_key() "context=XYZ.idb"

Hansel uses Yara to search for strings and bytes. When loaded it copies data from the IDB into memory that Yara can search. On VMs with limited memory, the copying can take a second to load. A status is displayed on IDA’s command line.

Status: Loading memory for Yara.
Status: Memory has been loaded.

If a rule throws an error it is likely because the search breaks Yara’s search syntax (mostly strings that need escape sequences). As previously mentioned Hansel returns the start of the function that contains the match. If the search is a single byte pattern rule and with no function cross-reference(s) than the byte pattern match is returned.

Python>search("{7F 7F 7F 7F 7F 7F 7F 7F  40 56 41 00 84 62 41 00 }")
(True, [4281968L])

Status

  • Stablish.
  • I’m still testing all the possible combinations of searches and keywords.
  • Daily usage so bugs will be fixed.

Version Changes

2.0

  • removed storing the rename, comment, filename and similar within strings. I didn't reliaze I could use **kwargs to store multiple named arguments.
  • renamed file_name to filename.
  • converted the rules to a dict json format. It kind of sucks not being able to cut and paste from the command line to the rules file but it didn't work with the named arguments.
  • only displays matches, not rules being scanned
  • I'll start uploading rules once this rule set format seems to be working well.
  • Thanks to OA for the feedback.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].