1. Mastering machine codes for NOP, JNE, JE, JMP, CMP assembly instructions
NOP : The NOP instruction is the "null instruction". When executing to the NOP instruction, the CPU does nothing, just as an instruction to execute the past and continue executing a command behind NOP. (Machine code: 90)
JNE : Conditional transfer directives, if not equal, jumps. (Machine code: 75)
JE : The conditional transfer instruction, if equal, jumps. (Machine code: 74)
JMP : Unconditional transfer instructions. Direct transfer within the section of JMP Short (machine code: EB) directly within the section of JMP near (machine code: E9) Section indirectly transfer JMP Word (Machine code: FF) between segments Direct (FAR) Transfer JMP remote (machine code: EA)
CMP: compare instruction, function equivalent to subtraction instruction, just compare operation between operands, do not save result. After the CMP directive executes, it affects the flag register. Other relevant instructions are identified by identifying these affected flag register bits to get a comparison result.
2 , mastering disassembly and hex programmer
(1) Writing and compiling programs
Code function: Enter the password and the pre-stored password to match, correctly output right, otherwise output wrong.
(2) The user name and password are obtained by disassembly
Open terminal, enter Objdump–d Hello, find main function:
(Objdump is a GCC tool used to view the composition of the post-compilation target file)
Note The marked Jne command, which indicates that the value of the CMP instruction comparison is the original password and the input value when the preceding CMP instruction compares the result to a non-equal.
When the two are not equal to jump 4005f0 output wrong, otherwise continue to execute the next command output right,
(3) Modify the executable file, play the password login
① can log in correctly, whether or not it is entered properly.
to implement inequality, also output right, just modify the jump address, that is, modify the instruction to 7500
Open the executable file with VI, use%! XXD Command 16 binary display
Then use the/750e command to find the code, if you cannot search to the middle of the empty lattice/75 0e
Find modified Location
Change 0c to 00: then ENTER:%! Xxd–r
Then use:%! Xxd-r command revert to binary, finally: Wq save can
The following is the result of disassembling the modified file
Test Result: (whether the password is correct or not, it means correct)
② can not log in normally, that is, need to jump unconditionally to the wrong place, unconditionally jump to jmp, then the same need to change 750c to eb0c. (EB for unconditional jump);
Test Result: (input correct, indicate error)
The following is the result of a modified disassembly
Test Result: (enter correct password, display incorrect)
③ Enter the correct password can not log in, enter the wrong password to login.
You need to change it to 740c (je equal to jump, not equal to continue execution)
Linux kernel analysis-program hack