Mikrotik initrd hacks
Find a file
Sergey Sergeev a6f257a42e fix chmod bug in init.c and add USB flash drive support.
Signed-off-by: Sergey Sergeev <adron@yapic.net>
2022-06-02 15:53:34 +03:00
busyboxes minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
cpio-fs-aarch64 update releases 2022-01-27 07:24:15 +02:00
cpio-fs-arm fix chmod bug in init.c and add USB flash drive support. 2022-06-02 15:53:34 +03:00
cpio-fs-mips minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
finder add support for RouterOS 7.1rc4 and aarch64(arm64 - RB5009) 2021-09-25 20:03:56 +03:00
for_ftp_upload/pub minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
init fix chmod bug in init.c and add USB flash drive support. 2022-06-02 15:53:34 +03:00
owl minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
ready-kernels fix chmod bug in init.c and add USB flash drive support. 2022-06-02 15:53:34 +03:00
releases update releases 2022-01-27 07:24:15 +02:00
work/rb5009/ros/rootfs/dev minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
x1 add support for RouterOS 7.1rc4 and aarch64(arm64 - RB5009) 2021-09-25 20:03:56 +03:00
.gitignore Finally, support for 7.0b1 has been added. 2019-09-12 00:55:18 +03:00
dump_elf.sh add copyrights and warnings 2019-03-09 20:28:19 +03:00
ftp_upload.sh minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
globals.sh update releases 2022-01-27 07:24:15 +02:00
pack-kernel.sh minimize initrd size: remove busybox from initrd and use for_ftp_uload busybox 2022-01-27 07:02:44 +02:00
README.md fix chmod bug in init.c and add USB flash drive support. 2022-06-02 15:53:34 +03:00
unpack-kernel.sh add support for RouterOS 7.1rc4 and aarch64(arm64 - RB5009) 2021-09-25 20:03:56 +03:00
unpack-npk.sh Trying to add support 7.0b1. So far, unsuccessful! 2019-09-11 21:52:24 +03:00

Mikrotik netboot/initrd jailbreak

(C) Sergey Sergeev, 2019-2021

All that you do is at your own risk! The author has not liable for any of you actions and their consequences! This code is presented as is and is solely for educational purposes ONLY! - to investigate the internals of a Linux distro called RouterOS. In particular, to facilitate porting OpenWRT to new Mikrotik devices. For injection(jailbreak) to RouterOS is used the standard(for almost any Linux) initrd mechanism. Native binary init file is replaced with a fake one. This modified init forks itself (spawning its daemon copy) and then pass control to the original init process. The begotten daemon copy waits for the filesystem to initialize and installs busybox and then launch the telnetd service. To run Linux kernel with modified init file, uses the standard RouterBOOT ability - loading via the network using dhcp/bootp and tftp server. dhcp/bootp server can be deployed on another device with RouterOS and OpenWRT or even tftp32 program. For a one-time launch with tftp, You can use this commands in RouterOS:

/system/routerboard/settings/set boot-device=try-ethernet-once-then-nand
/system/reboot

and after that do the following:

  1. Use RouterOS 6.44 or 6.45.6 or 7.x(7.1rc4)!
  2. Upload(using FTP) content of ./for_ftp_upload/pub/* to /pub (or /flash or /flash/rw/disk/pub) folder on target RouterOS device
  3. Netboot(via bootp and tftp) with kernel-new.elf
  4. telnet x.x.x.x 22111

Cyrillic:

Все что вы делаете, вы делаете на свой страх и риск! Автор не несет никакой ответственности за ваши действия и их последствия! Данный код представляется as-is и исключительно в учебных целях - для исследования внутреннего устройства дистрибутива Linux под названием RouterOS. В частностия для для облегчения портирования OpenWRT на новые устройства от Mikrotik. Для внедрения(jailbreak-а) в RouterOS используется стандартный(практически для любого Linux-а) механизм initrd. Родной бинарный файл init-а заменяется на поддельный. Этот измененный init форкает себя(порождая свою копию-демона) и дальше передает управление родному init процессу. Порожденная копия-демон ожидает инициализации файловой системы и запускает скрипт установки busybox с последующим запуском telnetd сервиса. Для запуска ядра Linux с измененным init файлом используется штатный механизм RouterBOOT - загрузка через сеть с использованием dhcp/bootp и tftp сервера. dhcp/bootp сервером может выступать как другое устройство с RouterOS так и OpenWRT или даже программа tftp32. Для единоразового запуска с tftp вы можете выполнить следующие команды в RouterOS:

/system/routerboard/settings/set boot-device=try-ethernet-once-then-nand
/system/reboot

For Developers:

Place routeros-XXX.mpk to ./ros/
cd ./finder
./Build.sh
cd ..
edit ./globals.sh and set your target device ARCH: aarch64 or arm or mips
./unpack-npk.sh ./ros/routeros-mipsbe-6.45.6.npk
./unpack-kernel.sh
cd ./init
./compile.sh
cd ..
Make the necessary changes to the ./cpio-fs-ARCH(copy oldinit && order from ./bins/initramfs.cpio, compile add add busybox, etc...)
In the end, when everything is ready, to get ./bins/kernel-new.elf, run: ./pack-kernel.sh
Upload content of ./for_ftp_upload/pub/* to target RouterOS device via FTP(to /pub or /flash or /disk1 or ...)
		* /disk1 is a USB flash drive with ext3 fs
Put ./bins/kernel-new.elf to your tftp and Netboot from it
telnet x.x.x.x 22111

If you want to boot the modified kernel from a flash drive, then place it in the /flash/boot dir:
	nc x.x.x.y 1111 > /flash/boot/kernel