Git Product home page Git Product logo

ebpf-for-ghidra's Introduction

eBPF processor for Ghidra

The extension implements eBPF architecture support for Ghidra and allows for disassembly and decompilation of ELF files containing eBPF programs.

Example of eBPF program you can get here.

eBPF Extension

Example of disassembling and decompiling of eBPF:

Example of decompiling

Installation

  • Download Release version of extension and install it in Ghidra File → Install Extensions...
  • Use gradle to build extension: GHIDRA_INSTALL_DIR=${GHIDRA_HOME} gradle and use Ghidra to install it: File → Install Extensions...
  • Clone this repository to \Ghidra\Extensions directory.

Updates

03.09.2019 — eBPF maps implementation, custom relocation handler was implemented

19.09.2019 — problem with stack is resolved

20.09.2019 — eBPF call-helpers are implemented as syscalls, added helper's signature through custom eBPFAnalyzer

23.09.2019 — bad bookmarks fixed

01.12.2020 — new eBPF-helpers added

23.06.2022 — added support for relative calls (R_BPF_64_32 relocation type). Thanks @cnwangjihe for this idea. imm of call instruction where bpf_call->src_reg == BPF_PSEUDO_CALL now contains the relative offset to target function.

Before:

image

After:

24.06.2022 — making the Pull Request to official Ghidra repository as the main supplier of the eBPF processor

19.12.2022 — added support for BPF_ATOMIC operations, ALU32 instructions added, BPF_JMP32 instructions added, JSET instruction fixed

03.05.2023 — eBPF processor support added to the Ghidra official repository in the commit 506ca1e. Expected to work out of the box in the next Ghidra release 10.3.

eBPF support out of the box in Ghidra

Despite the inclusion of this project in the Ghidra, I will continue to maintain this repository. If you have problems or questions, you can open an issue either here or in the Ghidra repository. This repository will continue to be maintained in order to be able to work with older versions of Ghidra.

Useful links

ebpf-for-ghidra's People

Contributors

drw0if avatar nalen98 avatar ri-char avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ebpf-for-ghidra's Issues

helper syscalls not decompiling on version 9.1.2

Hi,

I've tried to run your plugin on ghidra 9.1.2 and I only see helper names and no other helper syscall attributes. (ret type etc.)
I see these warnings in eclipse logs when linking and running with ghidra and analysing an eBPF program.
WARN Decompiling syscall:0033, pcode error at syscall:0033: Unable to resolve constructor at syscall:0033 (DecompileCallback)
WARN Decompiling syscall:0001, pcode error at syscall:0001: Unable to resolve constructor at syscall:0001 (DecompileCallback)

eBPF Maps

Greetings!

In the near future I plan to implement interaction with eBPF maps through some helpers (https://prototype-kernel.readthedocs.io/en/latest/bpf/ebpf_maps.html#interacting-with-maps).
«eBPF maps are a generic data structure for storage of different data types. It’s a method to keep state between invocations of the eBPF program, and allows sharing data between eBPF kernel programs, and also between kernel and user-space applications. So, map handles are file descriptors, and multiple maps can be created and accessed by multiple programs».

We know (based on the relocation table) that the eBPF loader patches LDDW instruction, which forms Rn for the helper-call (for example, bpf_map_lookup_elem(…)).Therefore, relying on relocation table, it’s theoretically possible to implement string information of map’s name in disassembler and decompiler.

Make Stack Better

Greetings!
eBPF has a number of nasty moments with the stack:
https://www.kernel.org/doc/html/latest/bpf/bpf_design_QA.html#q-can-bpf-programs-access-instruction-pointer-or-return-address
And small citation:
«Q: Can BPF programs access instruction pointer or return address?
A: NO.
Q: Can BPF programs access stack pointer ?
A: NO. Only frame pointer (register R10) is accessible. From compiler point of view it's necessary to have stack pointer. For example, LLVM defines register R11 as stack pointer in its BPF backend, but it makes sure that generated code never uses it.»
Pretty sad, isn't it?

Register R10 is the last hope for us and Ghidra to implement access to stack of eBPF programm. I put «stackpointer» attribute on it in specification files for extension. R10 is a frameponter register, it’s unchangeable, and we use this register and offset to access the stack (such as index in array). Accordingly, the "original" SP (stack pointer register) is missing and no substitute in eBPF. This implies several problems:

=> Stack Depth field in Ghidra will be guaranteed zero, beacuse we have to appoint R10 as a stackponter in these architectural conditions.

=> Instructions which operate with R10 (Load/Store instructions) often doesn't decompile. Any ideas about this thing? Ghidra usually doesn't decompile dead code (snippets that won't execute), but it generally does not apply to the subject of Issue.

Thanks to support!

It seems that the new version of ghidra is not supported

Extension version for [eBPF-for-Ghidra] is incompatible with Ghidra.

Build Date: 2022-Jan-25 1526 EST
Ghidra Version: 10.1.2
Java Home: /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
JVM Version: Eclipse Adoptium 11.0.14.1
OS: Mac OS X 12.0.1 x86_64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.