General Question

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
karfas
Posts: 193
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: General Question

Post by karfas » Wed Jul 13, 2022 11:15 am

Firas_Baccouri wrote:
Wed Jul 13, 2022 6:56 am
I want to prevent the micropython code running on the controller from any attacker . This is my main goal .
You are demanding the impossible. Any "security" scheme only increases the effort required to break in (and the expense to work with). I remember that even some security keys of otherwise inaccessible smart cards had been read out by analyzing the power consumption of the chip.

Your code lives (in one form or another) in the EEPROM of your device.
Find a balance between security and usability.
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

martincho
Posts: 96
Joined: Mon May 16, 2022 9:59 pm

Re: General Question

Post by martincho » Wed Jul 13, 2022 8:09 pm

Firas_Baccouri wrote:
Wed Jul 13, 2022 6:56 am
jimmo wrote:
Mon Jul 11, 2022 12:50 pm
But again... I would seriously question how valuable this is and whether it's worth the additional cost and complexity to your development. What are you really protecting against?
I want to prevent the micropython code running on the controller from any attacker . This is my main goal .
Your description is so broad that the only possible answer is: This is impossible. Perhaps you mean something more narrow than what "any attacker" means to all of us?

Just to give you an example of the kinds of things people can do. Back some thirty years ago I was tasked with adding non-trivial functionality to an industrial device used extensively where I worked at the time. The manufacturer had gone out of business and there was no information whatsoever to be had at all. Remember, no internet, no Google, no Stackoverflow, etc.

I don't remember the processor, it was a common rugged 8-bit processor of the era. All I had was a data book and the device.

First, I had to reverse engineer the schematic to the extent possible.

After that, I removed the ROM from the board, got the contents and dis assembled it to get an assembler listing. Oh, yes, the designer thought they were clever and mis-wired the ROM to jumble-up the bits. In other words, instead of wiring bits 0-7 to the corresponding pins on the ROM chip, they wired 5 to 2, 7 to 0, etc. An attempt to make the disassembled code meaningless. That was a wasted effort, it took no time to figure it out and create a hand-wired adaptor board to read the correctly-aligned bits with an EPROM reader.

The next phase took some time. I had to go through the assembler listing, identify variables, functions, memory map, etc. This involved such things as making changes to the code and running it to see what happened. I don't remember how long this took. It was definitely several weeks.

Finally, I identified a routine I could attack to add the functions we needed. I relocated it to the end of the ROM, where there was room to spare. I added jumps to and from that section so that to the rest of the program the routine felt like it was still at the same memory address. Once I got to that point I wrote my own code to add functions to the device and essentially appended the code to the prior function. The change in functionality was not trivial at all, however, once I had my entry point isolated it was no different from normal programming in assembler. In fact, at that point I knew so much about the firmware that we added all kinds of functionality to the device over the years and eventually built a completely new custom version of it from scratch using a newer/faster/better processor.

So, yes, if you truly mean "any attacker", then that is absolutely impossible. If you mean something less than that, maybe.

There's another point to be made. Unless your device has significant economic value or is widely deployed in an industry, there likely isn't much incentive to expend time and effort engaging in reverse engineering anything. Make sure you are not worrying about something that has a low probability of taking place.

Firas_Baccouri
Posts: 35
Joined: Wed Apr 27, 2022 7:22 am

Re: General Question

Post by Firas_Baccouri » Fri Jul 15, 2022 7:57 am

karfas wrote:
Wed Jul 13, 2022 11:15 am
You are demanding the impossible. Any "security" scheme only increases the effort required to break in (and the expense to work with). I remember that even some security keys of otherwise inaccessible smart cards had been read out by analyzing the power consumption of the chip.
Yeah you are right , actually I don´t mean any attacker , what I want to achieve is to prevent access to the micropython code running on the controller , for example by locking the flash memory and disabling the REPL , is with this two thing my code could be secure and it is hard to get it .

Firas_Baccouri
Posts: 35
Joined: Wed Apr 27, 2022 7:22 am

Re: General Question

Post by Firas_Baccouri » Fri Jul 15, 2022 8:01 am

martincho wrote:
Wed Jul 13, 2022 8:09 pm
So, yes, if you truly mean "any attacker", then that is absolutely impossible. If you mean something less than that, maybe.

There's another point to be made. Unless your device has significant economic value or is widely deployed in an industry, there likely isn't much incentive to expend time and effort engaging in reverse engineering anything. Make sure you are not worrying about something that has a low probability of taking place.
Thanks martincho for replying and telling us this story , it was nice :) .
Actually I don´t mean any attacker , what I want to achieve is to prevent access to the micropython code running on the controller , for example by locking the flash memory and disabling the REPL , is with this two thing my code could be secure and it is hard to get it or there are some other steps that I should fulfil .

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: General Question

Post by Roberthh » Fri Jul 15, 2022 9:17 am

If it's just about running only your code and disabling REPL you could:
a) Disable keyboard interrupt with micropython.kbd_intr(-1) in boot.py and start your code there or in main.py. Then there would be still a short time window to stop boot.py with ctrl-c, before this is disabled again.
b) Disable keyboard interrupt with micropython.kbd_intr(-1) in _boot.py and/or remove the call to REPL in main.c in the main loop. That requires to build your own firmware.
In any case, getting back to an initial state would require erasing the flash.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: General Question

Post by pythoncoder » Fri Jul 15, 2022 11:04 am

martincho wrote:
Wed Jul 13, 2022 8:09 pm
...Oh, yes, the designer thought they were clever and mis-wired the ROM to jumble-up the bits. In other words, instead of wiring bits 0-7 to the corresponding pins on the ROM chip, they wired 5 to 2, 7 to 0, etc. An attempt to make the disassembled code meaningless...
He made your life too easy. He should have jumbled the address lines too ;)
Peter Hinch
Index to my micropython libraries.

martincho
Posts: 96
Joined: Mon May 16, 2022 9:59 pm

Re: General Question

Post by martincho » Fri Jul 15, 2022 2:27 pm

pythoncoder wrote:
Fri Jul 15, 2022 11:04 am
martincho wrote:
Wed Jul 13, 2022 8:09 pm
...Oh, yes, the designer thought they were clever and mis-wired the ROM to jumble-up the bits. In other words, instead of wiring bits 0-7 to the corresponding pins on the ROM chip, they wired 5 to 2, 7 to 0, etc. An attempt to make the disassembled code meaningless...
He made your life too easy. He should have jumbled the address lines too ;)
I did that myself in my 20's when I was full of myself and thought I was being clever. Pretty funny looking back.

Post Reply