Chapter 139: Stack buffer overflow
Chapter 139: Stack buffer overflow
The next day, the school cafeteria.
The Sam trio got together for a meal again.
The scars on Arthur and Matthew's faces are no longer visible if they don't pay attention to them, and the swelling has completely disappeared, and they both praise Lin Hong's "Yunnan Baiyao" as very magical.
On their table, there were three Ti-82 calculators, and while they were eating, they looked at the calculators on the table from time to time, and sometimes looked at each other and smiled, although their faces were tired, but there was a look of great excitement and pride between their eyebrows.
These three calculators are the ones that have been successfully cracked!
After eating quickly, Matthew immediately picked up his calculator, pressed it a few times, called up a directory, and then ran the program in it, the entire calculator LCD screen suddenly refreshed, only to see a small black bar on the right began to slowly move from right to left, Matthew turned the calculator sideways, and began to play with relish.
Yesterday, the circuit drawings of the TI-82 calculator were directly posted on the BBS, so the information mailed by Texas Instruments is actually of little significance. That person was an engineer at Texas Instruments, and he answered a lot of questions from users and said that suggestions for improvement were welcome and that he would submit feedback to the company.
Since they got the drawings in advance, the matter of cracking was immediately put on the daily routine, and the three of them who were excited didn't have the heart to sleep at all, and they made an important decision, that is, they must crack the calculator before the back-to-school dance arrived.
They work together, Matthew and Arthur are responsible for designing an interesting software or game, and Lin Hong is responsible for cracking the calculator, and after cracking it, it will be transplanted to the calculator to give everyone a huge surprise.
Due to the basis of those posts on BBS, Lin Hong already had a very good grasp of cracking the calculator, and he finally asked Arthur to take out the toolbox, disassemble the calculator, and carefully study the hardware structure of the calculator against the circuit diagram.
In the end, Lin Hong determined that there was no need to make hardware modifications to the calculator to break through the restrictive shackles set by Texas Instruments on the firmware.
That's because in one of the posts, a user described a phenomenon he found that a calculator could be put into a special mode called "debug-n" in the order and manner of a few keys he gave. However, the user's reply post was quickly inundated with other replies that followed, and only a few people noticed his reply.
Because Lin Hong needed to crack the calculator, he paid more attention to all the replies on the opposite. He attached great importance to this user's reply, and used his calculator to operate it completely in the order described by the other party, and then connected the calculator to the computer for a series of tests, and was pleasantly surprised to find that this mode seemed to be used by Texas Instruments engineers during the development process for debugging, and in this mode, the user has a lot of authority to operate the calculator.
This is definitely good news, originally Lin Hong thought that the hardware needed to be changed, but now that there is a way to enter this mode, he can directly crack this calculator without going through the hardware, just from the loopholes in the software.
After a night of fighting, Lin Hong finally succeeded.
He found a stack buffer overflow in the calculator and successfully wrote his own code into it, breaking through the firmware system's restrictions on user space permissions.
During the running of the program, in order to temporarily access the data, it is generally necessary to allocate some memory space, which is usually called a buffer.
This area can generally be used for data storage and deletion operations, and the level of protection is not strict. Outside of the buffer, there are other areas of the system kernel where the data stored is very important data in the system, and once that data is modified, the whole system may crash, and of course, there may be other unexpected results.
Therefore, these system kernel data areas are strictly restricted and protected, and users cannot operate on them.
A stack is a special data structure that is characterized by first-in, first-out. It's like a dead end, everyone queues up to go in, stops entering when it's full, and then comes out one by one, and the one who goes in first comes out last. There are also many examples of this kind of data structure in life, such as handing in test papers, the person who submits it first will generally not be seen by the teacher until the end, and there is the song ordering system in KTV before, and the person who orders the song first sings at the end.
It stands to reason that Texas Instruments engineers need to check the length of the data pressed into the stack when writing the program, and once the stack is full, they must stop pressing it in again, otherwise there will be overflow.
The stack buffer that Lin Hong found was that those engineers were not rigorous when they wrote the code, and forgot to check the length of the stack, so Lin Hong kept pressing data into it, and when it was full, he continued to press in, so the stack overflow occurred.
Overflow means that the cells outside the stack buffer will be overwritten, and if the data stored in these data units is useful data, there will be unintended consequences, the most common consequence is the crash of the program, which is usually only a bug in the program, but when the designed data is pressed into these stacks, it is not just a bug, but a vulnerability that can be exploited by hackers.
Lin Hong carefully designed a small program, and then compiled it into machine code, first pressed some invalid data into the stack he found, accurately calculated the length of these data, and then pressed the data he designed into it, so that it overflowed, covering the area outside the buffer, so that when the firmware system runs here, it will successfully call and execute his program......
As a result, this tight fortress was successfully conquered by Lin Hong.
In order to accurately calculate the length of the stack, he repeated the data pressing process more than 50 times, and in order to be able to smoothly take over the running process of the firmware, the time and effort spent on it cannot be clearly described in a few words.
After Lin Hong successfully cracked it, in his excitement, he forgot that others didn't need to sleep like him, so he immediately knocked on Arthur's door, fortunately, they had just fallen asleep, and when they heard that he had broken the calculator so quickly, the two of them, who had been so sleepy that they couldn't open their eyes, suddenly refreshed themselves and threw their sleepiness out of the clouds.
I immediately wanted to see what the result was, but then the problem came again - there was no suitable software to run on it.
The two of them had been discussing for a long time, but they couldn't decide what function to write for the first piece of software. Arthur prefers to make a practical software, such as a school aid to students' learning, while Matthew prefers to write an interesting game.
The opinions of the two people could not be unanimous, and time passed in their constant arguments, and as a result, nothing was done.
Now that the machine has come out, but there is no suitable software, it is really frustrating.
At this time, Matthew proposed to write a relatively simple game first, which was unanimously approved by Lin Hong and Arthur.
The three of them discussed it for a while and finally decided to port the game Tetris to the calculator.
Tetris is a classic game of Soviet scientist Alexei Pakitnov, which is deceptively simple but infinitely varied and addictive. When it was released in the United States in 1988, it was an instant commercial success and was popular with all men, women and children, becoming an extremely classic mass game that no game could match.
When Arthur was learning programming before, he had developed this game independently, and there was ready-made source code, so it was not difficult to port.
So, they moved the position to Lin Hong's room, because his machine can simulate the running environment of the Z80CPU, and after simple modification and optimization of the source program written by Arthur before, it will be compiled into a file that can be executed in the calculator, and then transferred to the calculator storage space through the data cable.
Something went wrong in the first few runs, but this is a very normal situation (the latest chapter of Seeking Demons), transplanting to another platform, if it can be successful at one time, it would be too exaggerated, even if it is a great programmer, sometimes it will make some low-level mistakes, such as writing the wrong variable name, forgetting to write a semicolon and the like, which is a very normal situation (the latest chapter of Seeking Magic). As long as the debugging information is used, targeted modifications are made.
That's what it is to write a program, debug, run, debug, ......
Keep fighting all kinds of bugs and bugs until the moment you finally get through!
After a dozen times of constant back-and-forth debugging and transfer of programs, Arthur's Russian game finally ran smoothly on the Ti-82!
Matthew snatched the calculator for the first time and started playing.
To play Tetris, you only need to press up to five buttons, three arrow keys, one for transformation and one for acceleration. And there are dozens of keys on the calculator, which is enough.
Matthew played for a while and found that because the height of the calculator display was too low, it was easy to be propped up to the top and eventually hang up.
Therefore, he proposed to improve the display by rotating it 90 degrees clockwise, so that the distance of the block can be greatly lengthened, which can reduce the difficulty.
As a result, Arthur began to modify the game's source code......
During the whole process, Lin Hou didn't intervene again, he just watched Arthur write the program from the side.
Arthur's Tetris program is written in C language, Lin Hong came to the United States to start contact with this programming language, not very familiar with it, today I see Arthur continue to modify and debug, and I have learned a lot.
He found that when Arthur wrote a program, there were some small programming habits worth learning from, such as commenting points in key places and indenting code statements in multiple lines to improve the readability of the code...... Wait a minute.
It was almost five o'clock in the morning when they finally settled on the final version of the Tetris game.
At this moment, except for Lin Hong, Arthur and Matthew were exhausted and fell asleep directly on the bed.
On this morning's morning exercise, Arthur and Matthew were not able to go, only Lin Hong was alone.
Chapter 139: Stack buffer overflow
Chapter 139 Stack buffer overflow, go to (Holy King txt download) to read the novel