Reverse Analysis on Windows - A First Look

Krematorij

Administrator
Staff member
ADMIN
BFD MEMBER
LEGEND
ULTIMATE
SUPREME
MEMBER
BFD Legacy
Joined
Oct 22, 2024
Messages
1,121
Reaction score
16,256
Website
bfdcrew.pro
Deposit
1,002$
Environment Information

System information: Windows
Tools involved: Visual studio , x64dbg
Note: This is a translation of the article previously written into English version, if you can not see the message I improve the translation
Test code.
C:
Code:
#include <stdio.h>
int main()
{
    int a;
    printf("Please input a number:\n");
    int x = scanf_s("%d", &a);               // This is not to assign the value of a to x, but to determine
    // this is to define an integer variable x, scanf_s is to enter a value a, when you enter an integer value, you get x = 1 (judged to be true); and when you key in a character or other unqualified content, you get x = 0 (judged to be false)

    printf("%d\n", x);
     if (a % 5 == 0 && a % 7 == 0 && a >1 && a <200)                        /* Determine if the number is divisible by both 5 and 7 and a is greater than 1 and less than 200*/
            printf("yes\n");                                /* output yes if you can*/
    else
            printf("no\n");                                    /* if not, output no*/
    return 0;
}
Game rules
Enter a value so that its terminal returns the following information.
Code:
Code:
1
yes
Note: Normal input of 140 will satisfy the requirement
Break the rules
Enter something that does not match the condition to satisfy the requirement
1665830990224.png


Example idea:
After the program runs, a string will be entered
1665831003888.png


After that, the user starts to input, and then returns some content after judging.
The normal flow of the output string code will be before the judgment code, and most likely in a region, you can test to locate the judgment code region according to this string.
Verification:
The following settings will break at the Enyry Breakpoint
1665831047573.png


Click the Run button to let the program continue to run
1665831060173.png


At this point, return to the x64dbg interface and search for the string information loaded by the program
1665831075275.png


Result
1665831086467.png


Double click the left mouse button to enter, at this time see some judgment process
1665831094196.png


Mouse wheel slide up to see the entry point of this function area (sub)
There are multiple int3 on sub, determine this is the address of the call
1665831104534.png


Next breakpoint
1665831118962.png


Reload the program
1665831126584.png



Run to the place where the breakpoint is placed
1665831135368.png


Breakpoints under Call and Judgment instructions are used for analysis
1665831144974.png


lea instruction: take offset address 7FF7D3DA2260 and send to register RCX

1665830928742.png



1665830922072.png


Run it in a single step and see that the terminal outputs the following string after this call
1665830905413.png


After this call, the terminal can enter the value
1665830894328.png


After confirming
1665830882167.png


Call register information
1665830870871.png


Return 1 after Call
1665830857696.png


Rerun, enter the value that does not meet the condition and compare

Call register information
1665830833292.png


Return 0 after Call
1665830807946.png


Difference
RAX is different
Rerun and enter the value that does not meet the condition and change the rax information to 1
Select RAX or the corresponding value and right click
1665830793996.png


Modify
1665830786135.png


Call runs and sees that 1 has been returned and a rule has been broken
1665830757668.png


Continue to run and see the following judgments
1665830742963.png


Judgment: according to the displayed instruction execution flow judgment, if the two jne instructions do not jump and jbe jump can return yes
Right click to edit the instruction so that it does not work
1665830731365.png



1665830719822.png


Modify the instructions
1665830712817.png




1665830704813.png


After modifying
1665830695757.png


Run to verify
1665830680976.png


This article, this is the end, have the fate to meet again.

Test code modified at: https://blog.csdn.net/qq_42200183/article/details/81431747
 
Top Bottom