tools for effortless reverse engineering of mikrotik
play

Tools for effortless reverse engineering of MikroTik routers - PowerPoint PPT Presentation

Tools for effortless reverse engineering of MikroTik routers https://github.com/0ki/mikrotik-tools v3 http ://kirils.org/ Legal disclaimer Goal of this presentation is to allow the members of the research community to assess security and


  1. Tools for effortless reverse engineering of MikroTik routers https://github.com/0ki/mikrotik-tools v3 http ://kirils.org/

  2. Legal disclaimer Goal of this presentation is to allow the members of the research community to assess security and achieve the interoperability of computer programs @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 2 / 47

  3. MikroTik? Anyone even uses it? @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 3 / 47

  4. RouterOS is … ● Linux! – old Linux! ● Startup scripts ● Nova binaries ● Config @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 4 / 47

  5. And it’s also closed source & closed ecosystem @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 5 / 47

  6. A jailbreak is needed... @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 6 / 47

  7. A built-in backdoor. How nice. ● RouterOS 2.9.8 delivered on 15 Nov 2005 – a wild “/nova/etc/devel-login” appears in /nova/bin/login – [ -f /nova/etc/devel-login && username == devel && password == admin.password ] && /bin/ash @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 7 / 47

  8. All we gotta do is ... @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 8 / 47

  9. All we gotta do is ... 1) Create /nova/etc/devel-login 2) telnet to 192.168.88.1 as devel @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 9 / 47

  10. [TAB] to the rescue ● No ls? No problem! – cat, space, tab, tab ● Or, you know, do it properly, and upload busybox – statically linked, for the right architecture ● uname -m – this might be of interest: ● https://busybox.net/downloads/binaries/1.21.1/ @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 10 / 47

  11. But how… ? @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 11 / 47

  12. The old way ● A VirtualBox appliance! ● DEMO @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 12 / 47

  13. The old way ● A VirtualBox appliance! ● Works only if – If your CPU is AR9344 and device has at least two ethernet ports ● RB951G-2HnD, RB951Ui-2HnD <== tested ● CRS109-8G-1S-2HnD-IN, CRS125-24G-1S-IN, CRS125-24G-1S-2HnD-IN ● RB2011L, RB2011LS, RB2011iLS-IN, RB2011iL-IN, RB2011UiAS-IN RB2011UiAS-RM, RB2011UiAS-2HnD-IN ● OmniTIK 5, OmniTIK 5 PoE @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 13 / 47

  14. The new way ● A bash/python script ● Works regardless of architecture ● Very fast ● Can do remote jailbreaks ● Will not help you recover lost passwords ● Will probably get patched soon after this presentation ● DEMO @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 14 / 47

  15. Now. The tools. @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 15 / 47

  16. NPK file sourcing ● getnpk.sh – deps: wget ● reversenpk.sh – deps: unsquashfs, unnpk – https://github.com/rsa9000/npk-tools @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 16 / 47

  17. Kernel patches https://github.com/wsxarcher/routeros-linux-patch @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 17 / 47

  18. RouterOS boot process @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 18 / 47

  19. Where do we put custom binaries? @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 19 / 47

  20. Anywhere! ● “path” looks for specified path in prefixed directories – Used throughout their scripts – Makes using custom scripts easier @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 20 / 47

  21. High level overview of RouterOS @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 21 / 47

  22. NPK format @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 22 / 47

  23. NPK format ● Numeric values are unsigned little endian ● File consists of header, file size, parts and footer. ● File size is 8b less ● Each part consist of: – part type (short) – payload size (long) – payload @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 23 / 47

  24. NPK format ● At least two types of current NPKs: – package ● 0..3 header 1E F1 D0 BA ● footer 10 00 01 00 00 00 49 – footer since 3.22 – restriction (invisible package) ● 0..3 header FB 0F 10 A1 ● footer 03 00 00 00 00 00 @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 24 / 47

  25. Part types @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 25 / 47

  26. supout.rif @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 26 / 47

  27. What is supout.rif? ● Support output – ridiculously intricate format – or RouterOS information file, maybe, idk ¯\_( ツ )_/¯ @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 27 / 47

  28. supout.rif from outside @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 28 / 47

  29. supout.rif section decoding ● swap bits around – per three bytes ● base64 ● section decodes to: – name + ‘\0’ + zlib_compressed_content @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 29 / 47

  30. supout.rif section decoding @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 30 / 47

  31. supout.rif from inside ● What does it contain? – your whole configuration – /proc/ folder – memory addresses – your log – and more @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 31 / 47

  32. DEMO Demo: mikrotik.com xss Demo: decode_supout.py @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 32 / 47

  33. Config files @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 33 / 47

  34. Configuration ● Config is stored in /rw/store as pairs of files – IDX = index – DAT = data @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 34 / 47

  35. IDX format ● Record ID (long) – if ID is 0xFFFFFFFF, field has no content – used for offsetting ● length (long) ● separator (long) – usually 0x05000000 @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 35 / 47

  36. DAT format ● LENGTH (short) ● M2 RECORD of length – Config ID (3 bytes) – type (1 byte) ● content depends on to type @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 36 / 47

  37. Peculiarities / features ● Field IDs shared with web ● Winbox protocol derived from DAT format – Working directly with files? – Dangerous! @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 37 / 47

  38. mt_dat_decoder.py module ● DEMO @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 38 / 47

  39. Where’s my password? ● Calm down! It’s encrypted! @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 39 / 47

  40. The password is ● hashed ● salted ● md5 ● Oh, wait, no. That’s the key. @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 40 / 47

  41. The password key = md5(username + "283i4jfkai3389") password = user["password"] xor key @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 41 / 47

  42. The password tool ● DEMO @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 42 / 47

  43. Backup files @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 43 / 47

  44. Backup file layout ● Header (long) – 0x88ACA1B1 – backup – 0xEFA89172 – encrypted backup ● Length of backup file (long) ● Records of: – Path name, idx contents, dat contents ● Each record consists of length (long) and binary data @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 44 / 47

  45. The bug ● mkdir -p pathname(“/flash/rw/store/”+filename) ● write idx to “/flash/rw/store/”+filename+“.idx” ● write dat to “/flash/rw/store/”+filename+“.dat” @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 45 / 47

  46. decode_backup.py ● DEMO @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 46 / 47

  47. The end. ● Tools & jailbreak available https://github.com/0ki/mikrotik-tools ● Latest appliance: http://02.lv/f/2017/09/15/MT_JB_0.89.ova @KirilsSolovjovs Oct 21, 2017, Hacktivity, Budapest 47 / 47

Recommend


More recommend