1. Lena Reversing
02.Keyfiling the reverseme + assembler
๋ฒ์ญ์ : re4lfl0w / re4lfl0w@gmail.com
Last updated: 2012.02.22
The creator of this movie or the ISP(s) hosting this movie or any content in this
movie take no responsibility for the way you use the information provided in this
movie.
Movie ๋ง๋ ์ฌ๋์ด๋ ISP์ ์ด movie๋ฅผ hostingํ๊ฑฐ๋ ์ด movie ์์ ์ด๋ค content์์
๋ ์ ๊ณต๋ ์ ๋ณด๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ ๋ํด ์ฑ ์์ง์ง ์์ต๋๋ค.
These file and anything else on this site and in this movie are here for private
purposes only and should not be downloaded or viewed whatsoever!
์ด site์์ file๋ค๊ณผ ๋ชจ๋ ๊ฒ๋ค์ ์ค์ง ๊ฐ์ธ์ ์ธ ๋ชฉ์ ์ผ๋ก download ํ๊ฑฐ๋ ๋ณผ ์ ์์ต
๋๋ค.
If you are affiliated with any government, or Anti-Piracy group or any other related
group or were formally a worker of one you cannot enter this web site nor see this
movie,
๋น์ ์ด ์ด๋ค ์ ๋ถ ๋๋ ๋ถ๋ฒ ๋ณต์ ๋ฐฉ์ง ๊ทธ๋ฃน ๋๋ ๊ธฐํ ๊ด๋ จ ๋จ์ฒด์ ์ ํดํ๊ฑฐ๋ ๊ณต์์
์ผ๋ก ํ๋์ ๋ ธ๋์๋ก ์ผํ ๊ฒฝ์ฐ ์ด web site์ ์ ์ํ ์ ์์ต๋๋ค. ๋ํ ์ด movie๋ฅผ ๋ณผ
์ ์์ต๋๋ค.
cannot access any of its files and you cannot view any of the HTML files.
์ด๋ค file์๋ ์ ์ํ ์ ์์ต๋๋ค. ์ด๋ค HTML file๋ ๋ณผ ์ ์์ต๋๋ค.
All the objects on this site and in this movie are private property and are not meant
for viewing or any other purposes other then bandwidth space.
02.Keyfiling the reverseme + assembler
2012๋ 1์ 16์ผ ์์์ผ
์ค์ 6:15
20120328_lena ํ๊ธ ํ์ด์ง 1
2. for viewing or any other purposes other then bandwidth space.
์ด movie ์์ Site์ ์๋ ๋ชจ๋ object์ ๊ฐ์ธ์ ์ธ ์ฌ์ฐ์ด๋ค. ๋ค๋ฅธ ๋ชฉ์ ์ด๋ ๋์ญํญ์
์๋ฏธํ์ง ์๋๋ค.
Do not see this movie whatsoever!
์ด movie๋ฅผ ์ฐธ์กฐํ์ง ๋ง์ญ์์ค.
If you see this movie you are not agreeing to these terms and you are violating code
431.322.12 of the Internet Privacy Act singed by Bill Clinton in 1995 and that means
that you can't threaten our ISP(s) or any person(s) or company storing these file or
these movies, cannot prosecute any person(s) affiliated with this page and movie
which includes family, friends or individuals who run or enter this site or see this
movie.
์ด movie๋ฅผ ๋ณผ ๊ฒฝ์ฐ ์ด ์ฝ๊ด์ ๋์ํ์ง ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋น์ ์ 1995๋ ๋น ํด๋ฆฐํด์
์๋ช ์ด ์ธํฐ๋ท ๊ฐ์ธ ์ ๋ณด ๋ณดํธ๋ฒ์ ์ฝ๋ 431.322.12์ ์๋ฐํ๊ณ ๋น์ ์ด ์ฐ๋ฆฌ์ ISP๋ค ๋
๋ ์ฌ๋๋ค์ ์ํํ ์ ์๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ๋๋ ์ด๋ฌํ ํ์ผ์ด๋ ์ด๋ฌํ movie๋ฅผ
์คํํ๊ณ ์ ์ฅํ๋ ํ์ฌ, ๊ฐ์กฑ, ์น๊ตฌ๊ฑฐ๋ ์ฌ์ดํธ์ ๋ค์ด์ค๊ฑฐ๋ ์ํ๋ฅผ ๋ณผ ๊ฐ์ธ์ ํฌํจํ
๊ฑฐ๋ ํ์ด์ง ๋ฐ ์ํ์ ์ ํดํ ๋ค๋ฅธ์ฌ๋๋ค์ ๊ธฐ์ํ ์ ์์ต๋๋ค.
๋ฒ์ญ ์ฃผ)์ด ๋ถ๋ถ ๋ฒ์ญ์ด ์ ์ผ ์ด๋ ค์ ์ต๋๋ค. ์ดํด๋ ์ ์๋๊ณ .
Hello everybody.
์๋ ๋ชจ๋๋ค.
Welcome to this Part2 in my series about reversing for newbies/beginners.
๋์ reversing ์ด๋ณด์๋ฅผ ์ํ series Part 2์ ์จ ๊ฒ์ ํ์ํด.
This "saga" is intended for complete starters in reversing, even for those without any
programming experience at all.
์ด saga์ ๋์์ reversing์์ Programming ๊ฒฝํ์กฐ์ฐจ ์๋ ์๋ฒฝํ ์ด๋ณด์๋ค.
Set your screen resolution to 1152*864 and press F11 to see the movie full screen !!!
Again, I have made this movie interactive.
You screen ํด์๋๋ฅผ 1152*864๋ก ์ค์ ํด ๊ทธ๋ฆฌ๊ณ full screen์ผ๋ก movie๋ฅผ ๋ณด๊ธฐ ์ํด
F11๋ฅผ ๋๋ฌ
So, if you are a fast reader and you want to continue to the next screen, just click
here on this invisible hotspot. You don't see it, but it IS there on text screens.
๊ทธ๋์, ๋ค๊ฐ ์ด๊ฒ์ ๋นจ๋ฆฌ ์ฝ๊ณ ๋ค์ screen์ ๋ณด๊ณ ์ถ๋ค๋ฉด, ๋ณด์ด๋ hotspot ์ฌ๊ธฐ๋ฅผ ๋๋ฌ.
๋ณด๊ณ ์ถ์ง ์์ ๋๋ ์ฌ๊ธฐ์ ๋์ง๋ง.
Then the movie will skip the text and continue with the next screen.
Movie๋ text์ ๋ค์ screen์ skipํ ์ ์๋ค.
If something is not clear or goes too fast, you can always use the control buttons
and the slider below on this screen.
๋ฌด์ธ๊ฐ ๋ช ํํ์ง ์๊ฑฐ๋ ๋นจ๋ฆฌ ๋๊ธฐ๊ณ ์ ํ ๋, ํญ์ control button๊ณผ ์ด screen ๋ฐ์ ์
๋ slider ๋ฐ๋ฅผ ์ฌ์ฉํด.
He, try it out and click on the hotspot to skip this text and to go to the next screen
now!!!
๋์ ํด๋ด. ๊ทธ๋ฆฌ๊ณ ์ด text์ ๋ค์ screen์ ๋ณด๊ธฐ ์ํด hotspot์ clickํด.
During the whole movie you can click this spot to leave immediately
20120328_lena ํ๊ธ ํ์ด์ง 2
3. During the whole movie you can click this spot to leave immediately
์ด movie ์ด๋์์๋ ์ฆ์ ๋ ๋๊ธฐ ์ํด ์ด spot์ click ํ ์ ์๋ค.
Click here as soon as you finished reading(on each screen !)
๋ค๊ฐ ์ฝ๊ธฐ๊ฐ ๋๋ฌ์ ๋ ์ด ๊ณณ์ ํด๋ฆญํด. (์ด๋ฒ screen์์)
Tools and Target2.
Throughout most of these tutorials, you will use Ollydebug andโฆ your brain. The first
can be obtained for free at
๋๋ถ๋ถ์ tutorial์ ํตํด, ๋๋ Olly์ ๋์ ๋๋๋ฅผ ์ฌ์ฉํ ๊ฒ์ด๋ค.
์ฒซ๋ฒ์งธ๋ก ์ฌ๊ธฐ์์ ๋ฌด๋ฃ๋ก ์ป์ ์ ์๋ค.
http://www.ollydbg.de
...again, the second is your responsibility ;)
2๋ฒ์งธ๋ ๋์ ์ฑ ์๊ฐ์ด ํ์ํ๋ค.
For your convenience, I included the target (ReverseMe) in this package. In this
package is also included a file "Keyfile.dat".
๋์ ํธ๋ฆฌ๋ฅผ ์ํด, ์ด package์ ReverseMe๋ฅผ ํฌํจํ๋ค. ๋ํ "Keyfile.dat"๋ ํฌํจ๋์ด
์๋ค.
Do not extract it to the same directory as the ReverseMe if you want to try this
tutorial yourself. (Practice is the best way to learn).
์ด tutorial์ ํผ์์ ์๋ํ ๋ ๊ฐ์ ๋๋ ํ ๋ฆฌ์ ํ ์ ์๋ค. (์ฐ์ต์ด ๋ฐฐ์ธ ๋ ๊ฐ์ฅ ์ข๋ค)
The use of plugins3.
Study of the target is always extremely important. However, we did that for this
target already in Part 1, so, I'll refer you to Part 1 for it. In fact, this tutorial will build
some things on Part 1 and if you have not already done so, I strongly suggest to see
that tutorial first ;))
๊ณต๋ถ ๋ชฉํ๊ฐ ์ ๋ง๋ก ์ค์ํ๋ค. ๊ทธ๋ฌ๋, ์ฐ๋ฆฌ๋ ์ด๋ฏธ Part1์์ ๋ชฉํ๋ฌผ์ ์ ํ๋ค. ๊ทธ๋์
๋๋ Part 1์ ์ฐธ์กฐํ๋ผ๊ณ ์๊ธฐํ๋ค. ์ฌ์ค, ์ด tutorial์ Part1์์ ๋ฌด์์ ๋ง๋ ๋ค. ๊ทธ๋ฆฌ
๊ณ ๋ค๊ฐ ๋จผ์ ๋ณด์ง ์์๋ค๋ฉด, ๊ฐ๋ ฅํ ๋จผ์ ๋ณผ ๊ฒ์ ์ถ์ฒํ๋ค.
Keep your mouse pointer here and click whenever you are ready reading on each
textscreen
๋ค๊ฐ ๋ค์ textscreen์ ์ฝ๊ณ ์ ํ ๋ ๋์ ๋ง์ฐ์ค๋ฅผ ์ฌ๊ธฐ์ ์์นํ๊ณ ํด๋ฆญ ํด.
When loading a target, Olly will automatically analyze the code to comment the code
for us. (Not in certain conditions, see later Parts)
If you doubt that Olly has effectively done it, you can always make Olly do that like
thisโฆ.
Target์ด loading ๋ ๋, Olly๋ ์๋์ผ๋ก code์ comment๋ฅผ ๋ฌ์ ํด์ํ๋ค.(์ด๊ฒ์ ๋ช
ํํ ์กฐ๊ฑด์ ์๋๋ค, ๋์ค Parts๋ฅผ ๋ด๋ผ)
Olly๊ฐ ํจ๊ณผ์ ์ผ๋ก ์๋ฃํ๋์ง ์์ฌ์ด ๋ ๋ค๋ฉด, ์ด๊ฒ์ฒ๋ผ ํญ์ Olly๊ฐ ํ ์ ์๊ฒ ๋ง๋ ๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 3
4. And now click to analyze code.
However, I want to explain you the use of plugins in Ollyโฆ.
ํด์ code๋ฅผ click ํ์.
๊ทธ๋ฌ๋, Olly์์ ์ฌ์ฉํ๊ธฐ ์ข์ plugins์ ์๊ฐํ๊ณ ์ ํ๋ค.
...and see this "analyze This!" plugin that I will use here. (Only to show you plugins).
๊ทธ๋ฆฌ๊ณ "analyze This!" plugin์ ์ฌ๊ธฐ์์ ์ฌ์ฉํ ๊ฒ์ด๋ค.(๋์๊ฒ๋ง ๋ณด์ฌ์ฃผ๋ plugin)
INFO : Analyze This! Is an OllyDbg plugin to allow OllyDbg's analysis function to
operate outside of the marked code segment.
It can be downloaded at :
http://tuts4you.com/request.php?22
20120328_lena ํ๊ธ ํ์ด์ง 4
5. http://tuts4you.com/request.php?22
Unzip in Olly's plugins directory and then it can be accessed by rightclicking in the
code
์ ๋ณด : Analyze This๋ Ollydbg์ ํด์ ํจ์๊ฐ ํ์๋ code segment๋ฅผ ์ธ๋ถ์์ ์กฐ์ํ
์ ์๋ Ollydbg plugin ์ ๋๋ค.
์ฌ๊ธฐ์์ ๋ค์ด๋ก๋ ๊ฐ๋ฅํ๋ค.
http://tuts4you.com/request.php?22
Olly plugin directory์ ํ๊ณ code์์ rightclicking์ผ๋ก ์ ๊ทผํ ์ ์๋ค.
Ok. In the blink of an eye, Olly has analyzed the code.
Ok. ๋์ ๊น๋นก์ด์, Olly๋ code๋ฅผ ํด์ํ๋ค.
Solving the ReverseMe4.
See also Part 1 in this tutorial series but to understand everything fine, we will need
to broaden your overall knowledge a little concerning bits - bytes - numbers - hex.
I'll try to keep it to the minimum that is required to understand this series though.
์ด tutorial์ Part1์ ๋ด๋ผ. ๊ทธ๋ฌ๋ ๋ค๊ฐ ์ดํด๊ฐ ๋๋ค๋ฉด ์ฐ๋ฆฌ๋ ์ง์์ด ๋ํ๋๋ฐ bits -
bytes - numbers - hex๋ฅผ ์ง์คํ ์ ์๋ค.
๋๋ ์๊ฒ ์ ์งํ๊ธฐ ์ํด ์ด series๋ฅผ ์ดํดํ๋ ๊ฒ์ด ์๊ตฌ๋๋ค.
If you have an outstanding knowledge in this matter, it is clear that you can skip this
piece. Let's go!
๋ง์ฝ์ ๋ฐ์ด๋ ์ง์์ ๊ฐ์ง๋ค๋ฉด, ์ด๊ฒ์ ๋ช ํํ๋ค. ๋๋ ์ด ์กฐ๊ฐ์ ๋๊ธธ ์ ์๋ค.
The decimal number system.โข
INFO:
The easiest way to understand bits is to compare them to something known: digits. A
digit is a single place that can hold numerical values between 0 and 9 in our numeric
decimal system.
๊ฐ์ฅ ์ฝ๊ฒ bit๋ฅผ ์ดํดํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ซ์๋ค์ ๋น๊ตํ๋ ๊ฒ์ด๋ค. Digit๋ ํ ์๋ฆฌ๋ค. ๊ทธ
๊ฒ์ 0๊ณผ 9 ์ฌ์ด์ 10์ง์ system์ด๋ค.
Digits are normally combined together in groups to create larger numbers.
For example, 6357 is a decimal number and has four digits.
์ซ์๋ค์ ๋ณดํต ๊ทธ๋ฃน ์์์ ํฐ ์ซ์๋ค์ ๋ง๋ค ๋ ์กฐํฉ๋๋ค.
์๋ฅผ ๋ค์ด, 6357์ 10์ง์ system์ด๊ณ 4๊ฐ์ ์ซ์๋ก ๋์ด ์๋ค.
That should all feel pretty comfortable -- we work with decimal digits every day. The
neat thing about number systems is that there is nothing that forces you to have 10
different values in a digit.
๋งค์ฐ ํธ์ํ๋ค. -- ์ฐ๋ฆฌ๊ฐ ๋งค์ผ 10์ง์๋ฅผ ์ฌ์ฉํ๋ค. ๋จ์ ๋ ์ซ์ system์ ์๋ฌด๊ฒ๋ ์๋
๋ค. ์ซ์์์ 10๊ฐ์ง์ ๋ค๋ฅธ ๊ฐ๋ค์ ๊ฐ์ง๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 5
6. Out base-10 number system likely grew up because we have 10 fingers, but if we
happened to evolve to have eight fingers instead, we would probably have a base-8
number system.
Base-10 ์ง์๋ ์ฑ์ฅํ๋ค. ์๋ํ๋ฉด ์ฐ๋ฆฌ๋ 10๊ฐ์ ์๊ฐ๋ฝ์ ๊ฐ์ง๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋ฌ๋
๋ง์ฝ์ ์ฐ๋ฆฌ๊ฐ 8๊ฐ์ ์๊ฐ๋ฝ์์ ์งํํ๋ค๋ฉด, ์ฐ๋ฆฌ๋ ์๋ง 8์ง์ system์ ์ฌ์ฉํ์ ๊ฒ
์ด๋ค.
You can have base-anything number systems. In fact, there are lots of good reasons
to use different bases in different situations.
๋๋ ๋ค๋ฅธ number system์ ๊ฐ์ง ์ ์๋ค. ์ฌ์ค, ๊ทธ๊ฒ์ ๋ง์ ๋ค๋ฅธ ์ํฉ ์์์ ๋ค๋ฅด๊ฒ
์ฌ์ฉํ๋ ์ด์ ๊ฐ ์๋ค.
So, all this seems pretty simple, but how do we calculate in the decimal number
system, I mean how do we assign values for numbers?
๊ทธ๋์, ๋งค์ฐ ๊ฐ๋จํ๋ค, ๊ทธ๋ฌ๋ ์ฐ๋ฆฌ๊ฐ ์ด๋ป๊ฒ 10์ง์ system์์ ๊ณ์ฐ์ ํด์ผ๋๋? ์ด
๋ป๊ฒ ์ซ์ value ๊ฐ์ ํ ๋นํ๋?
INFO:
It is understood that in the number 6,357, the 7 is filling the 1s place, while the 5 is
filling the 10s place, the 3 is filling the 100s place and the 6 is filling the 1,000s place.
6357์ 7์ 1์ ์๋ฆฌ, 5๋ 10์ ์๋ฆฌ, 3์ 100์ ์๋ฆฌ, 6์ 1000์ ์๋ฆฌ.
So you could express things this way if you wanted to be explicit:
๋ค๊ฐ ์ํ๋ ๋ช ์พํ ๊ฒ์ด ์๋ค๋ฉด ํํํ ์ ์๋ค.
(6 * 1000) + (3 * 100) + (5 * 10) + (7 * 1)
= 6000 + 300 + 50 + 7 = 6357
Another way to express it would be to use powers of 10. Assuming that we are going
to represent the concept of "raised to the power of" with the "^" symbol (so "10
squared" is written as "10^2"), then another way to express it is like this:
๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ํํํ ์ ์๋ค. ๊ทธ๊ฒ์ 10์ง๋ฒ์ผ๋ก ์ฌ์ฉํ ์ ์๋ค. ์๊ฐํ๊ฑด๋ฐ ์ฐ๋ฆฌ๋
"raised to the power of" ๊ฐ๋ ์ ์ค๋ช ํ๊ธฐ ์ํ ์์ง์ผ๋ก "^"(๊ทธ๋์ "10 squared"๋
"10^2"๋ก ์ฐ์ฌ์ก๋ค), ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์ด๊ฒ์ฒ๋ผ ํํํ ์ ์๋ค.
(6 * 10^3) + (3 * 10^2) + (5 * 10^1) + (7 * 10^0) = 6,357
6000 + 300 + 50 + 7 = 6357
What you can see from this expression is that each digit is a placeholder for the next
higher power of 10, starting in the first digit with 10 raised to the power of zero.
์ด ํํ์์์ ๋๋ ๋ณผ ์ ์๋ค. ๊ฐ ์ซ์๋ค์ ๋ค์ 10์ง์๋ฅผ ์ํด ์๋ฆฌ๋ฅผ ์งํจ๋ค. ์ฒ์
์์ํ๋ 10์ ์ง์๋ 0์ด๋ค.
Computers happen to operate using the base-2 number system, also known as the
binary number system (just like the base-10 number system is known as the decimal
number system). Let's find out why and how that worksโฆ
Computer๋ ์ค์ง 2์ง์์์๋ง ์๋ํ๋ค, binary number system(10์ง์ ์์คํ ์
20120328_lena ํ๊ธ ํ์ด์ง 6
7. Computer๋ ์ค์ง 2์ง์์์๋ง ์๋ํ๋ค, binary number system(10์ง์ ์์คํ ์
decimal number system)์ ์๊ณ ์๋ค. ์, ์ ์ฌ์ฉํ๋์ง ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ์ฐพ์๋ณด์
The base-2 System and the 8-bit Byte.โข
2์ง์ and 8byt Byteโข
INFO:
The reason computers use the base-2 system is because it makes it a lot easier to
implement them with current electronic technology. So computers use binary
numbers, and therefore use binary digits in place of decimal digits. The world bit is a
shortening of the words "Binary digIT."
์ปดํจํฐ๊ฐ 2์ง์๋ฅผ ์ฌ์ฉํ๋ ์ด์ ๋ ์ฝ๊ฒ ์ํํ ์ ์๊ณ ์ ๊ธฐ์ ์ธ ๊ธฐ์ ์ด๊ธฐ ๋๋ฌธ์ด๋ค.
๊ทธ๋์ ์ปดํจํฐ๋ 2์ง์๋ฅผ ์ฌ์ฉํ๊ณ 2์ง์๋ฅผ 10์ง์ ์๋ฆฌ์ ์ฌ์ฉํ๋ค.
์ธ๊ณ์ ์ผ๋ก bit๋ "Binary digIT"์ ์ฝ์ด๋ค.
Whereas decimal digits have 10 possible values ranging from 0 to 9, bits have only
two possible values: 0 and 1. Therefore, a binary number is composed of only 0s and
1s, like this: 1011. How do you figure out what the value of the binary number 1011
is?
๋์กฐ์ ์ผ๋ก 10์ง์๋ 0~9๊น์ง 10๊ฐ์ ๊ฐ์ ๊ฐ์ง๋ค, bit๋ 2๊ฐ์ง ๊ฐ์ ๊ฐ์ง๋ค:0๊ณผ 1. ๊ทธ๋ฐ
๊น๋ญ์ผ๋ก 2์ง์๋ ์ค์ง 0๊ณผ 1๋ก ๋์ด ์๋ค. ์ด๊ฒ์ฒ๋ผ : 1011. ์ด๋ป๊ฒ 2์ง์ 1011์ ๊ณ์ฐ
ํ ๊ฒ์ธ๊ฐ?
You do it in the same way as for 6357, but you use a base of 2 instead of a base of
10.
๋๋ 6357๋ฅผ ํ ๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํ ์ ์๋ค. ๊ทธ๋ฌ๋ 10์ง์ ๋์ ์ 2์ง์๋ฅผ ์ฌ์ฉํด
์ผ ๋๋ค.
(1 * 2^3) + (0 * 2^2) + (1 * 2^1) + (1 * 2^0) = 11
= 8 + 0 + 2 + 1 = 11
You can see that in binary numbers, each bit holds the value of increasing powers of
2.
๋๋ 2์ง์์์ ๋ณผ ์ ์๋ค. ๊ฐ bit๋ ์ฆ๊ฐํ๋ 2์ง์์ ๊ฐ์ ๊ฐ์ง๋ค.
That makes counting in binary pretty easy.
Starting at zero and going through 20, counting in decimal and binary looks like this:
2์ง์์์ ์ฝ๊ฒ ์ ์ ์๋ค.
0์์ ์์ํ๊ณ 20๊น์ง, ๊ณ์ฐํ 10์ง์์ 2์ง์๋ฅผ ๋ด๋ผ. ์ด๋ ๊ฒ
INFO
0 = 0
1 = 1
2 = 10
3 = 11
4 = 100
5 = 101
6 = 110
7 = 111
8=1000
20120328_lena ํ๊ธ ํ์ด์ง 7
8. 8=1000
9=1001
10=1010
11=1011
12=1100
13=1101
14=1110
15=1111
16=10000
17=10001
18=10010
19=10011
20=10100
INFO
Bits are rarely seen alone in computers. They are almost always bundled together
into 8-bit collections, and these collections are called bytes.
์ปดํจํฐ ๋ถ์ผ์์ ๋๋ฌผ๊ฒ ์ฐ์ธ๋ค. ๊ทธ๋ค์ ๊ฑฐ์ ํญ์ 8bit ๊พธ๋ฌ๋ฏธ๋ก ๋ค๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ๋ค
์ ๊พธ๋ฌ๋ฏธ๋ 1byte๋ก ๋ถ๋ฆฐ๋ค.
Why are there 8 bits in a byte? Well, a similar question is, "Why are there 12 eggs in
a dozen?" The 8-bit byte is something that people settled on through trial and error
over the past 50 years.
์ 8bit๋ฅผ 1byte๋ผ๊ณ ๋ถ๋ฅด๋? ์ด๊ฒ์ ์ด ์ง๋ฌธ๊ณผ ๊ฐ๋ค. "์ 12๊ฐ์ ๊ณ๋์ ํ ๋ค์ค๋ผ๊ณ ๋ถ
๋ฅด๋?" 8bit๋ ์ฌ๋๋ค์ด ์ง๋ 50๋ ๊ฐ ์๋์ ์๋ฌ๋ฅผ ํตํ์ฌ ํฉ์๋ฅผ ๋ดค๋ค.
With 8 bits in a byte, you can represent 256 values ranging from 0 to 255, as shown
here:
8bit๋ 1byte๋ค. ๋๋ 256๊ฐ์ง์ ๊ฐ์ ๋ฒ์๋ก 0~255๊น์ง ํํํ ์ ์๋ค. ๋ณด์ด๋ ๊ฒ๊ณผ
๊ฐ์ด
0 = 0000 0000
1 = 0000 0001
2 = 0000 0010
โฆ
โฆ
254 = 1111 1110
255 = 1111 1111
INFO
Bytes values are also used to hold individual characters in the ASCII character set,
each binary value between 0 and 127 is given a specific character.
Bytes ๊ฐ์ ASCII์์ ๊ฐ๊ฐ ๋ฌธ์๋ก ์ฌ์ฉ๋๋ค. ๊ฐ binary value๋ 0~127๊น์ง ํน๋ณํ ๋ฌธ์
๋ก ๊ตฌ์ฑ๋์ด์ ธ ์๋ค.
Most computers extend the ASCII character set to use the full range of 256
characters available in a byte. The upper 128 characters handle special things like
accented characters from common foreign languages. See included file called
20120328_lena ํ๊ธ ํ์ด์ง 8
9. accented characters from common foreign languages. See included file called
Dec2Hex2Ascii.htm
๋๋ถ๋ถ์ ์ปดํจํฐ๋ ASCII๋ฅผ ํ์ฅํ๋ค. Byte์์ 256 ๋ฌธ์๋ฅผ ์ฌ์ฉํ ์ ์๊ฒ ๋๋ค. ์์
128 ๋ฌธ์๋ ๊ณตํต์ ์ธ ์ธ๊ตญ์ด์์ accent ๋ฌธ์๊ฐ์ด ํน๋ณํ ๊ฒ๋ค์ ์กฐ์ข ํ ์ ์๋ค. ํฌํจ
๋์ด ์๋ ํ์ผ์ธ Dec2Hex2Ascii.htm์ ๋ด๋ผ.
But I will discuss this further on too.
๊ทธ๋ฌ๋ ๋๋ ๋์ค์ ์ด๊ฒ์ ๋ค์ ์๋ ผํ๋ค.
The Hexadecimal Number Base Systemโข
16์ง์ Systemโข
INFO
Now, the next step -assuming you understood the previous- is rather easy to make:
from the binary to the hexadecimal system.
์ด์ , ์ด์ ๊ฐ์๋ฅผ ์ดํดํ ๊ฒ์ผ๋ก ๊ฐ์ ํ ๋ ๋ค์ step์ผ๋ก binary์์ hexadecimal ์ผ
๋ก ๋ฐ๊พธ๋ ๊ฒ ์คํ๋ ค ๋ ์ฝ๋ค.
A big problem with the binary system is verbosity. To represent the value 202, it
requires eight binary digits.
binary system์ ๊ฐ์ฅ ํฐ ๋ฌธ์ ๋ ์ฅํฉํ๋ค. 202 ๊ฐ์ ํํํ๋ ค๋ฉด, 8์๋ฆฌ์ binary ์ซ์๊ฐ
ํ์ํ๋ค.
๋ฒ์ญ ์ฃผ)Binary: 11001010(8์๋ฆฌ), Dec: 202(3์๋ฆฌ), Hex: CA(2์๋ฆฌ)
The decimal version requires only three decimal digits and, thus, represents numbers
much more compactly than does the binary numbering system.
10์ง๋ฒ์ ์ค์ง 10์ง์ 3์๋ฆฌ๋ง ํ์ํ๊ณ 2์ง์ system๋ณด๋ค ํํํ๋๋ฐ ๊ฐํธํ๋ค.
This fact was not lost on the engineers who designed binary computer systems.
When dealing with large values, binary numbers quickly become too unwieldy.
์ฌ์ค 2์ง์ computer system์ ๊ฐ๋ฐํ engineer๋ค์ ์์ ๊ฒ ์๋ค. Large ๊ฐ์ ์ฒ๋ฆฌํ
๋, 2์ง์๋ ๋น ๋ฅด๊ฒ ๋์ด๋๋ค.
The hexadecimal (base 16) numbering system solves these problems.
Hexadecimal numbers offer the two features:
16์ง์ system์ ์ด ๋ฌธ์ ๋ค์ ํด๊ฒฐํ๋ค.
Hex numbers are very compact-
It is easy to convert from hex to binary and binary to hex.-
16์ง์๋ ๋งค์ฐ ๊ฐํธํ๋ค.-
๊ทธ๊ฒ์ 16 -> 2, 2 -> 16์ผ๋ก ๋ณ๊ฒฝํ๋๋ฐ ์ฝ๋ค.-
16์ง์๋ 2๊ฐ์ง ์ฌ์ค์ ์ ๊ณตํ๋ค.
Now, all the previously explained concerning the calculation for the value represented
by the binary/decimal notation equally works for this hexadecimal system.
์ด์ , ๋ชจ๋ ๊ฒ๋ค์ ์ค๋ช ํ๊ธฐ ์ ์ ๊ฐ๋ค์ ํํํ๊ธฐ ์ํด ๊ณ์ฐํ๋๋ฐ ์ง์คํด๋ผ. 2์ง์/16
์ง์ ํ๊ธฐ๋ฒ์ 16์ง์ system์ ์ํด ๋๊ฐ์ ์ผ์ ํ๋ค.
If you like, you can try it out for yourself(the square value calc)
20120328_lena ํ๊ธ ํ์ด์ง 9
10. If you like, you can try it out for yourself(the square value calc)
๋ค๊ฐ ์ข์ํ๋ค๋ฉด, ๋๋ ๋ค ์์ ์ ์ํด ๋์ ํ ์ ์๋ค.(์คํจ๊ฐ ๊ณ์ฐ)
INFO
Since we'll need to enter hexadecimal numbers into the computer system, we'll need
a different mechanism for representing hexadecimal numbers to display their
associated value.
์ฐ๋ฆฌ๊ฐ ์ปดํจํฐ์ 16์ง์๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์๋ ํ์ํ ๊ฒ์ด๋ค, ๊ด๋ จ๋ 16์ง์๋ฅผ ํํํ
๊ธฐ ์ํด ๋ค๋ฅธ mechanism์ด ํ์ํ๋ค.
In Assembly Language programming, most assemblers require the first digit of a
hexadecimal number to be 0, and we place an H(h) at the end of the number to
denote the number base.
Assembly programming์์, ๋๋ถ๋ถ assembler๋ค์ 16์ง์์ ์ฒซ๋ฒ์งธ ์๋ฆฌ๊ฐ 0์ด ๋๋
๊ฒ์ด ํ์ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฌ๋ h๋ฅผ ์ซ์์ ๋ง์ง๋ง์ number base๋ฅผ ํํํ๊ธฐ ์ํด ๋ถ์ธ
๋ค.
To denote the difference with binary, we place a B(b) behind the number and a D (d)
for the decimal number.
2์ง์๋ฅผ ๋ค๋ฅธ ๊ฒ๊ณผ ๊ตฌ๋ถํ๊ธฐ ์ํด, ์ซ์ ๋ค์ b๋ฅผ ๋ถ์ด๊ณ Decimal ์ซ์ ๋ค์๋ d๋ฅผ ๋ถ์ธ
๋ค.
The Hexadecimal Number System:
Uses base 16-
Includes only the digits 0 through 9 and the letters A, B, C, D, E, and F-
16์ง์๋ฅผ ์ฌ์ฉํ๋ค.-
์ค์ง 0~9์ A,B,C,D,E,F ๋ฌธ์๋ฅผ ์ฌ์ฉํ๋ค.-
16์ง์ system
A hex number example is 1C9EB7F3h
16์ง์ ์๋ก 1C9EB7F3h๊ฐ ์๋ค.
It suffices to know these basics and to be able to calculate them to the decimal
system and vice versa using windows calculator(scientific in hex) (Example is
480163827d)
์ด๊ฒ์ ๊ธฐ๋ณธ์ ์๊ณ windows ๊ณ์ฐ๊ธฐ๋ฅผ(16์ง์์์) ์ฌ์ฉํ์ฌ 10์ง์๋ก ๊ณ์ฐ์ด ๊ฐ๋ฅํ
๊ณ ๋ฐ๋๋ ํ ์ ์๋ค.
๋ฒ์ญ ์ฃผ) ์ฆ ์ฝ๊ฒ ์ด์ผ๊ธฐํด์ 16์ง์ -> 10์ง์, 10์ง์ -> 16์ง์ ๊ฐ๋ฅํ๋ค๋ ์ด์ผ๊ธฐ
(์๋ฅผ ๋ค์ด, 480163827d)
So far our little detour in bits, bytes, binary, decimal and hex. But we were going to
solve the ReverseMe, remember? Let's continue and step over(F8) to see what goes
on.
์ง๊ธ๊น์ง bit, bytes, binary, decimal and hex๋ฅผ ์ฝ๊ฐ ์ฐํํ๋ค. ๊ทธ๋ฌ๋ ์ฐ๋ฆฌ๋
ReverseMe๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์๋ค ๊ธฐ์ต๋? ์์ํ์. ๊ทธ๋ฆฌ๊ณ F8๋ก ๋ฌด์จ ์ผ์ด ์ผ์ด๋๋์ง
๋ณด์.
20120328_lena ํ๊ธ ํ์ด์ง 10
11. So far all good. Remember from Part 1 that here, the action takes place? Let me
refresh your memory and let's go see the API again.
์ง๊ธ๊น์ง๋ ์ข๋ค. Part 1์์ ์ด๊ณณ์ ์ป๊ธฐ ์ํ ์ก์ ์ด ๊ธฐ์ต๋? ๋ค์ ์๋กญ๊ฒ ๋์ ๊ธฐ์ต์
๋ฃ์ด์ฃผ๋ง. ๊ทธ๋ฆฌ๊ณ API๋ฅผ ๋ค์ ๋ด๋ผ.
If we would continue executing the code, then it is on this line that the bad message
appears.
๋ง์ฝ ์ฐ๋ฆฌ๊ฐ code๋ฅผ ์คํํ๋ค๋ฉด ์ด line์ด bad message๊ฐ ๋ํ๋๋ค.
...unless of course we can avoid somehow this badboyโฆ???
์ฐ๋ฆฌ๊ฐ badboy๋ฅผ ํผํ์ง ์๋ ํ
Rightclick
"The CreateFile function creates or opens an object and returns a handle to access
the object"
20120328_lena ํ๊ธ ํ์ด์ง 11
12. the object"
"CreateFile function์ obejct์ object๋ฅผ ์ ๊ทผํ handle์ return์ ๋ง๋ค๊ฑฐ๋ ์ฐ๋ค."
The name of the file the program is looking for!!!
Let's see that in the code
Program file name์ ๋ด๋ผ.
์ฝ๋์์ ์ฐพ์๋ด๋ผ.
Don't forget: in assembler, you will find the parameters of a function pushed to the
stack in reversed order (when POP'ed they come in regular order)
์์ง ๋ง๋ผ: assembler์์ ๋๋ stack์ ๋ฐ๋ ์์๋ก ๋ฃ์ด์ง function์ paramter๋ค์ ์ฐพ
์ ์ ์๋ค. (๊ท์น์ ์ธ ์์๋ก ๊บผ๋ด์ง ๋, POP์ด๋ผ ๋ถ๋ฆฐ๋ค.)
So, what is first here, will be last in assembler
๊ทธ๋์, ์ฒ์์ด ๋ฌด์์ธ์ง ๋ด๋ผ, assembler์ ๋ง์ง๋ง์ ์์นํ ๊ฒ์ด๋ค.
And it is not a big mystery what file the program is looking for, right???
OK. The ReverseMe wants a file called "Keyfile.dat", well then โฆ let's give the
ReverseMe what it wants and make one!
์ด๊ฒ์ ํฐ ๋ฌธ์ ๊ฐ ์๋๋ค. File program์ด ๋ฌด์์ ์ฐพ๊ณ ์๋์ง ๋ณด์ด๋???
20120328_lena ํ๊ธ ํ์ด์ง 12
13. ์ด๊ฒ์ ํฐ ๋ฌธ์ ๊ฐ ์๋๋ค. File program์ด ๋ฌด์์ ์ฐพ๊ณ ์๋์ง ๋ณด์ด๋???
Ok. ReverseMe๋ "Keyfile.dat"๋ผ๊ณ ๋ถ๋ฆฌ๋ ํ์ผ์ ์ํ๋ค. ReverseMe์๊ฒ ์ํ๋ ๊ฒ์
๋ง๋ค์ด์ฃผ์.
Open windows notepad
And save Keyfile.datโฆ.
Yes, leave notepad open, we may need it again :)
Notepad๋ฅผ ์ด๊ณ Keyfile.dat๋ฅผ ์ ์ฅํด๋ผ.
์, notepad๋ ์ด๋ฆฐ ์ฑ๋ก ๋๋ฌ, ์ฐ๋ฆฌ๋ ๋ค์ ํ์ํ ๋๊ฐ ์ฌ ๊ฑฐ์ผ.
So, let's execute the API.
Press F8
API๋ฅผ ์คํํ์.
F8 ๋๋ฌ.
File found!!!
(When not found, EAX would be FFFFFFFFh)
Press F8 to continue
...and we will jump passed the badboy!
Let's continue.
ํ์ผ์ ์ฐพ์๋ค!!!
(ํ์ผ์ ์ฐพ์ง ๋ชปํ์ ๋, EAX๋ FFFF FFFFh์ด ๋ ๊ฒ์ด๋ค.)
F8์ ๋๋ฌ ๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฌ๋ badboy๋ฅผ ํต๊ณผํ ๊ฒ์ด๋ค.
ํด๋ณด์.
Scroll up to see what the future will bring us :)
And continue stepping over the code
์ด ์ฌ์ค์ด ์ฐ๋ฆฌ์๊ฒ ๋ฌด์์ ๊ฐ์ ธ์ฌ์ง ๋ณด๊ธฐ ์ํด scoll ์ฌ๋ ค.
๊ทธ๋ฆฌ๊ณ code๋ฅผ ์คํํด๋ณด์.
All right. Now the file will be read by ReadFile. Let's see the API
๋ง์. ์ด์ file์ ReadFile์ ์ํด ์ฝํ ๊ฒ์ด๋ค. API๋ฅผ ๋ณด์.
See the explanation?
That clarifies a lot, doesn't it?
์ค๋ช ์ ๋ณด์ด๋?
๊ฝค ๋ช ํํ๋ค. ๊ทธ๋ ์ง ์๋?
20120328_lena ํ๊ธ ํ์ด์ง 13
14. ๊ฝค ๋ช ํํ๋ค. ๊ทธ๋ ์ง ์๋?
In short, ReadFile tries to read our Keyfile.dat for a certain number of bytes which it
puts in a buffer at a certain address.
์์ฝํ๋ฉด, ReadFile์ Keyfile.dat์ ๋ช ํํ ๊ฐ์์ bytes๋ฅผ ์ฝ๊ธฐ ์ํด ๋์ ํ๋ค. ๊ทธ๊ฒ์
์ ํํ address์ buffer์ ๋ค์ด๊ฐ๋ค.
Take a look at the parameters
To understand the following in assembler.
Paramter ๋ค์ ๋ด๋ผ.
Assembler๋ฅผ ์ดํดํ๊ณ ๋ฐ๋ผ์๋ผ.
ReadFile reads 46h(==70d) bytes
At 402173
ReadFile์ 46h(==70d) bytes๋ฅผ ์ฝ๋๋ค.
๋ฒ์ญ ์ฃผ)h๋ 16์ง์(hexa decimal), d๋ 10์ง์(decimal)๋ผ๋ ๊ฒ์ ์ดํดํ ๊ฒ์ด๋ค.
To place them in a buffer at 40211A
Mmmm. Readfile will succeed. But our Keyfile is empty. So, ReadFile will read all
zeros. Let's see.
Buffer์ 40211A์ ์ ์ฅํ๋ค.
Mmmmm. Readfile์ ์ฑ๊ณตํ ๊ฒ์ด๋ค. ๊ทธ๋ฌ๋ ์ฐ๋ฆฌ์ Keyfile์ ๋น์ด์๋ค. ๊ทธ๋์
ReadFile์ zero๋ค์ ์ฝ์ ๊ฒ์ด๋ค. ๋ด๋ผ.
See that ReadFile succeeded.
ReadFile์ด ์ฑ๊ณตํ ๊ฒ์ ๋ด๋ผ.
INFO:
The info (if any!) after returning from an API is ALWAYS in EAX
API์์ Return ํ์ ์ ๋ณด๋ ํญ์ EAX ์์ ๋ค์ด์๋ค.
๋ฒ์ญ ์ฃผ)์ค์ํ ์ ๋ณด. ํญ์ return๊ฐ์ EAX ์์ ์ ์ฅ ๋ฉ๋๋ค. TEST EAX, EAX ๊ฐ์ ๊ฒ๋ค
์ด ์ดํด๋ ๊ฒ๋๋ค.
And so, the jump is taken.
Continue.
20120328_lena ํ๊ธ ํ์ด์ง 14
15. Continue.
๊ทธ๋์, jump๋ฅผ ํ๋ค. ๊ณ์ ํ์.
Do you still remember that
XOR REG, REG
Makes the register zero.
(XOR'ing the same register)
This is done to prepare EBX and ESI for the next operations.
์์ง ๊ธฐ์ตํ๋?
XOR REG, REG
Register๋ฅผ zero๋ก ๋ง๋ ๋ค.
(๊ฐ์ register๋ฅผ XOR ํ๋ค.)
๋ค์ ๋ช ๋ น์ด๋ค์ ์ํด EBX์ ESI๋ฅผ ์ค๋นํ๋ค.
๋ฒ์ญ ์ฃผ) 0์ผ๋ก ์ด๊ธฐํ ์์ผ์ ๋ค์ ๋ช ๋ น์ด๊ฐ ๋ค์ด์๋ ๋ฌธ์ ์๊ฒ ํด๋จ๋ค๋ ๋ป
A compare with 10.
Now, what is 10?
And what is [402173]?
10๊ณผ ๋น๊ตํ๋ค.
๋ฒ์ญ ์ฃผ) ์ฌ๊ธฐ์์ 10์ 10h๋ค. 10d์ ํท๊ฐ๋ฆฌ์ง ๋ง์. 10h == 16d)
์ 10์ธ๊ฐ?
[402173]์ ๋ฌด์์ธ๊ฐ?
Well, I already told that in a program, ALL values are in HEX (hexadecimal system).
๋๋ ์ด๋ฏธ ํ๋ก๊ทธ๋จ์์ ๋ชจ๋ ๊ฐ์ hex๋ผ๊ณ ๋งํ๋ค.
---> 10h == 16d
(10 hexadecimal is 16 decimal)
20120328_lena ํ๊ธ ํ์ด์ง 15
16. So, the ReverseMe compares something with 16d
And what exactly is compared with 16d ???
๊ทธ๋์, ReverseMe๋ 16d์ ๋น๊ตํ๋ค.
๊ทธ๋ฆฌ๊ณ ์ ํํ 16d์ ๋น๊ตํ๋ ๊ฒ์ธ๊ฐ?
[402371] means the value from what is at the address 402371. Hence, in our case, it
is compared with the value from the dword at address 402371.
[402371]์ 402371์ address์ ๊ฐ์ด๋ค. ๊ทธ๋ฆฌํ์ฌ, ์ด๋ฒ case์์๋ 402371 address์
dword๊ฐ๊ณผ ๋น๊ต๋๋ค.
Try to understand but don't worry too much yet. All is repeated again later.
์ดํดํ๊ธฐ ์ํด ๋์ ํด๋ผ. ๊ทธ๋ฌ๋ ์์ง ๊ฑฑ์ ํ์ง ๋ง๋ผ. ๋์ค์ ๋ค์ ๋ฐ๋ณต๋๋ค.
One can also follow these values in the dump windows which will clarify things a lot.
๊ทธ๊ฒ๋ค์ ๊ฐ์ dump windows์์ ๋ฐ๋ผ๊ฐ๋ผ. ๊ทธ๊ฒ์ ๊ฝค ๋ช ํํ๋ค.
We will see these things in more detail later.
์ฐ๋ฆฌ๋ ๊ทธ๊ฒ๋ค์ ๊ฝค ์์ธํ๊ฒ ๋์ค์ ๋ณผ ๊ฒ์ด๋ค.
In fact, this is the number of bytes that were read
์ฌ์ค, ์ด ์ซ์๋งํผ์ bytes๊ฐ ์ฝํ๋ค.
๋ฒ์ญ ์ฃผ) Lena์ ์ค๋ฅ๋ค. ์ค์ํ ๋๋ ์์ฃ .ใ 402371์ด ์๋๊ณ 402173 ์ด๋ค.
Let's continue
๊ณ์ํ์.
Aha, and the code jumps to the badboy if the number of bytes read by ReadFile is
lower then 16d
์ํ, code๋ ReadFile์ ์ํด์ 16d๋ณด๋ค ์ ๊ฒ ์ฝ์์ ๋ badboy๋ก jumpํ๋ค.
Mmmm, in short : the number of bytes that ReadFile reads from Keyfile.dat must be
at least 16d (==10h). Ok, let's remember that for later. Now, let's make the program
think it has read at least 16d bytes :))
์์ฝํ์๋ฉด: bytes์ ์ซ์๋งํผ ReadFile ์ฝ๊ธฐ๋ Keyfile.dat์์ ์ต์ํ 16์ด์ด์ผ ํ๋ค.
Ok, ๋์ค์ ์ํด์ ๊ธฐ์ตํด๋ผ. ์ด์ , program์ด ์ต์ํ 16d bytes๋ฅผ ์ฝ๋๋ค๊ณ ์๊ฐํ์.
20120328_lena ํ๊ธ ํ์ด์ง 16
17. Remember this?
์ด๊ฒ์ ๊ธฐ์ตํด?
Right. We don't jump to the badboy anymore.
๋ง์, ์ฐ๋ฆฌ๋ ๋ ์ด์ badboy๋ก jump ํ์ง ์๋๋ค.
Now what is next? Well, we will have to deal with a loop here. First, look at the next
lines of code and try to understand what will happen.
์ด์ ๋ค์์ ๋ฌด์์ด๋? ์ฐ๋ฆฌ๋ ์ฌ๊ธฐ์ ์๋ loop์ ๊ฑฐ๋ํ ์ ์๋ค. ๋จผ์ , ๋ค์ lines์
code๋ฅผ ๋ด๋ผ. ๊ทธ๋ฆฌ๊ณ ๋ฌด์จ ์ผ์ด ๋ฒ์ด์ง์ง ์ดํดํ๋๋ก ๋ ธ๋ ฅํด๋ผ.
The application is going to move the value at [EBX + 40211A] in AL
Application์ [EBX + 40211A]์ ๊ฐ์ AL์ ์ด๋ํ๋ค.
In the beginning of this routine, EBX was XOR'ed, hence EBX is zero at this moment
์์ํ๋ routine์, ebs๋ฅผ XOR ํ๋ค. ๊ทธ๋ฆฌํ์ฌ ํ์ฌ EBX๋ zero๋ค.
Whilst [40211A] becomes the first byte read by ReadFile and is put in the buffer at
40211A
40211A๋ ReadFile์ ์ํด์ ์ฒซ byte๊ฐ ์ฝํ๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ 40211A buffer์ ๋ฃ๋๋ค.
๋ฒ์ญ ์ฃผ) ์ฌ๊ธฐ์์ ์ byte๊ฐ ์ฝํ๋๋ฉด ๋ด๋ ๊ทธ๋ฆ์ด AL์ด๊ธฐ ๋๋ฌธ์ด๋ค. AL์ byte, AX๋
20120328_lena ํ๊ธ ํ์ด์ง 17
18. ๋ฒ์ญ ์ฃผ) ์ฌ๊ธฐ์์ ์ byte๊ฐ ์ฝํ๋๋ฉด ๋ด๋ ๊ทธ๋ฆ์ด AL์ด๊ธฐ ๋๋ฌธ์ด๋ค. AL์ byte, AX๋
2byte, EAX๋ 4byte๋ค.
---> [โฆโฆ] means "value of"
[โฆ..] ์ ๋ป์ "๊ฐ์"
๋ฒ์ญ ์ฃผ) ์ฆ, [40211A]์ ์ฃผ์์ ๋ค์ด์๋ ๊ฐ
You can follow this in the pane window too.
BTW, AL is the rightmost two digits from EAX.
See also that ReadFile has read the value 00 for the first byte.
๋๋ pane window์์ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ ์๋ค.
By the way, AL์ EAX์์ 2๊ฐ์ง ๊ฐ์ด ์๋ค.
ReadFile์ first byte์ ๊ฐ์ธ 00์ ์ฝ์ ๊ฒ์ ๋ด.
In short, the ReverseMe will move the first byte that ReadFile has read in our
Keyfile.dat in AL
์์ฝํ๋ฉด, ReverseMe๋ Keyfile.dat์์ ReadFile์ด ์ฝ์๋ ์ฒซ๋ฒ์งธ byte๋ฅผ AL๋ก ์ด๋ํ
๊ฒ์ด๋ค.
AL is then compared with zero.
AL์ zero์ ๋น๊ต๋๋ค.
If AL == 0 (like it is now) then we jumpโฆ
20120328_lena ํ๊ธ ํ์ด์ง 18
19. If AL == 0 (like it is now) then we jumpโฆ
AL์ด 0๊ณผ ๊ฐ๋ค๋ฉด ์ฐ๋ฆฌ๋ jump ํ๋ค.
๋ฒ์ญ ์ฃผ)์ฌ๊ธฐ์์๋ ๋น์ฐํ jumpํ๋ค. ์๋ํ๋ฉด ReadFile์์ ์ฝ์ ๊ฒ 0์ด๋๊น. EAX์
๊ฐ 0๊ณผ 0์ ๋น๊ตํ๋ฉด Z-Flag๋ฅผ 1๋ก setํ๋ค.
โฆ.to a compare ESI with 8
ESI๊ฐ 8๊ณผ ๋น๊ต๋๋ค.
But we jump to the badboy if ESI is lower then 8
๊ทธ๋ฌ๋ ๋ง์ฝ์ ESI๊ฐ 8๋ณด๋ค ์๋ค๋ฉด ์ฐ๋ฆฌ๋ badboy๋ก jump ํ๋ค.
Aha, so, we need ESI greater or equal then 8 to continue to jump to the goodboy !!!!
์ํ, ๊ทธ๋์, ESI ๊ฐ 8๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์์ผ goodboy๋ก jumpํ ์ ์๋ค.
But ESI is zero because it was XOR'ed before starting this routine !!!
Let's continue stepping to see it in the code
๊ทธ๋ฌ๋ ESI๋ zero๋ค. ์๋ํ๋ฉด ์ด routine์ ์์ํ ๋ XOR ์ฐ์ฐ์ ํ๊ธฐ ๋๋ฌธ์ด๋ค.
Code๋ฅผ ๋๊ธฐ๋ฉด์ ๋ณด์.
Let's not jump here because we first need
ESI >= 8
Jumpํ๋ฉด ์ ๋๋ค. ์๋ํ๋ฉด ์ฒซ๋ฒ์งธ๋ก ์ฐ๋ฆฌ๋ ESI๊ฐ 8์ด์์ด ํ์ํ๋ค.
What's up next?
20120328_lena ํ๊ธ ํ์ด์ง 19
20. What's up next?
๋ฌด์จ ์ผ์ด๋?
Aha, notice that AL
(which is our first byte read, remember) is compared to 47h
์ํ, AL์ด 47h์ ๋น๊ต๋๋ค.(AL์ ์๋ ๋ด์ฉ์ ์ฐ๋ฆฌ๊ฐ ์ฒ์์ ์ฝ์ byte๋ค.)
"But what is 47h ?" you ask.
Well, every char, number, sign, has its hexadecimal counterpart.
(See explaining in info's before).
"47h์ด ๋ญ์ผ?"
๋ชจ๋ ๋ฌธ์, ์ซ์, ๋ถํธ๋ 16์ง์๋ก ์ด๋ฃจ์ด์ ธ ์๋ค.
(์ด์ ์ ์ค๋ช ํ๋ค)
I have prepared a html page with these for you and also included it in this package.
๋๋ ์ด๋ฏธ ์ด๊ฒ๊ณผ ํจ๊ป ๋๋ฅผ ์ํด html page๋ฅผ ์ด package ์์ ํฌํจํด์ ์ค๋นํด๋๋ค.
BTW, there exist also tools to do this. A very good one is "Crackerstool" which I have
also included in this package.
Remark: place the included comdlg32.ocx in the same dir if it doesn't run on your
machine.
By the way, tools๊ฐ ์ผ์ ํ๊ธฐ ์ํด ์กด์ฌํ๋ค. ๋งค์ฐ ์ข์ "Crackerstool" ์ด๋ค. ์ด๋ฏธ ์ด
package์ ํฌํจํด๋๋ค.
์ฃผ๋ชฉ: comdlg32.ocx๋ฅผ ๊ฐ์ directory์ ํฌํจ๋๋ค. ๋ง์ฝ์ ์ด๊ฒ์ด ์์ผ๋ฉด ๋์ ์ปดํจํฐ์
์ ์คํ๋์ง ์๋๋ค.
This is the chart with the dec/hex/ascii representations. (See also before). Each byte
20120328_lena ํ๊ธ ํ์ด์ง 20
21. This is the chart with the dec/hex/ascii representations. (See also before). Each byte
can have a value ranging from 00 to FF
์ด chart๋ dec/hex/ascii ํ๊ธฐ๋ฒ์ด๋ค. ๊ฐ byte๋ 00~FF ๊น์ง ๋ฒ์๋ฅผ ๊ฐ์ง๋ค.
๋ฒ์ญ ์ฃผ)2์ง์, 16์ง์ ์ดํด๊ฐ ์๋๋ฉด ํ๋ค์ด์. ์ฌ์ด ์ฑ ๋ถํฐ ์์ํ์ธ์. ๊ผญ 2์ง์, 16์ง
์๋ฅผ ์ดํดํด์ผ ๋ฉ๋๋ค.
In our example, 47h (equals 71d) stands for the letter G(in ascii)
Indeed : 47h == G in ascii
์ด๋ฒ ์์ ์์๋, 47h๋ (71d์ ๊ฐ๋ค) G ๋ฌธ์๋ฅผ ๋ปํ๋ค(ascii)
47h == G (ascii์์)
Mmmm, so the ReverseMe verifies if the first found byte is G
์, ReverseMe๋ ์ฒซ๋ฒ์งธ๋ก ์ฐพ์ byte๊ฐ G์ธ์ง ๊ฒ์ฆํ๋ค.
Mmmm, if the byte is not "G", then we jump over the command
๋ง์ฝ์ G๊ฐ ์๋๋ผ๋ฉด ๋ช ๋ น์ jumpํ๋ค.
INC ESI
Let's see what INC means
INC ์๋ฏธ๊ฐ ๋ฌด์์ธ์ง ๋ณด์.
ASSEMBLER INFO:
INC (Increment)
Syntax:
INC Register
INC is the opposite of the DEC instruction it increases values by 1.
INC can set the Z/O flags.
INC ๋ฐ๋๋ DEC ๋ช ๋ น์ด๋ค. INC ๋ป์ ๊ฐ์ 1๋งํผ ์ฆ๊ฐ์ํจ๋ค.
INC๋ Z/O flags๋ฅผ setํ๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 21
22. In short : INC increments by 1.
Remember that we need to have
ESI >= 8
์์ฝํ๋ฉด, INC๋ 1์ ์ฆ๊ฐ์ํจ๋ค.
๊ธฐ์ตํด. ์ฐ๋ฆฌ๋ ESI๊ฐ 8์ด์ ๋๋ ๊ฒ์ด ํ์ํ๋ค.
And here, we increment the value of ESI by one if we do NOT jump over it.
Let's step again.
๊ทธ๋ฆฌ๊ณ ์ด๊ณณ์, ESI value๋ฅผ ํ๋์ฉ ์ฆ๊ฐํ๋ค. ์ฐ๋ฆฌ๋ ์ด๊ฒ์ jump ํ ์ ์๋ค.
๊ณ์ ํด.
EBX was zero, but is now incremented by 1 Continue stepping.
EBX๋ zero, ๊ทธ๋ฌ๋ ์ด step์ ๊ณ์ํ๋ฉด 1์ด ์ฆ๊ฐ๋๋ค.
And we jump back to start the verifying of the next byte.
Let's see the important code
๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฌ๋ ๋ค์ byte๋ฅผ ๊ฒ์ฆํ๊ธฐ ์ํด jump ํ๋ค.
์ค์ํ code๋ฅผ ์ ๋ด๋ผ.
20120328_lena ํ๊ธ ํ์ด์ง 22
23. We need to increment ESI to 8
--> this can only if the byte is "G"
์ฐ๋ฆฌ๋ ESI๋ฅผ 8๋ก ์ฆ๊ฐ์ํค๋ ๊ฒ ํ์ํ๋ค.
--> ์ค์ง byte๋ G๋ง ๋๋ค.
And if the byte is zero (end of the file), it is verified if ESI is at least 8
--> Were there at least 8 times "G" ?
๊ทธ๋ฆฌ๊ณ ๋ง์ฝ์ byte๊ฐ zero๋ผ๋ฉด(file์ ๋ง์ง๋ง), ESI๊ฐ 8๋ณด๋ค ์์์ง ๊ฒ์ฆ๋๋ค.
--> G์ ๊ฐฏ์๊ฐ 8๋ณด๋ค ์๋ค๋ฉด?
Also remember that in the beginning was verified if there are at least 16d bytes read
in the file
๋ํ ๊ธฐ์ตํด๋ผ. ์ฒ์ ์์ํ ๋ File์์ ์ต์ํ 16d bytes ์ด์์ด์ด์ผ ์ฝ๋๋ค๋ ๊ฒ์ ๊ฒ
์ฆํ๋ค.
Do you understand that EBX has the role of counter? EBX was incremented to 1. This
value is added to the pointer's value from the first read byte.
So, we will verify the second byte from Keyfile.dat now.
EBX๊ฐ ์ด role์ counter๋ผ๋ ๊ฒ์ ์ดํดํ์ด? EBX๋ 1์ฉ ์ฆ๊ฐ๋๋ค. ์ด ๊ฐ์ ์ฒซ๋ฒ์งธ byte
๋ฅผ ์ฝ์ด pointer ๊ฐ์ ์ถ๊ฐ๋๋ค.
๊ทธ๋์ ์ฐ๋ฆฌ๋ Keyfile.dat์์ second byte๋ฅผ ๊ฒ์ฆํ๋ค.
If this is not clear, take your time and study it all over again. Let's continueโฆ
๋ง์ฝ์ ์ด๊ฒ ๋ช ํํ์ง ์๋ค๋ฉด, ๋์ ์๊ฐ์ ๋ค์ฌ ๋ชจ๋ ๊ฒ์ ๋ค์ ๊ณต๋ถํด๋ผ. ๊ณ์ํ์.
Once again : if the verified bytes is 00 (empty) โฆ
๋ค์ ํ ๋ฒ : ๊ฒ์ฆ๋ bytes๋ 00 ์ด๋ค. (๋น์ด์๋ค)
20120328_lena ํ๊ธ ํ์ด์ง 23
24. โฆ. Then we jump to verify if ESI is equal or bigger then 8.
Scroll up.
๊ทธ๋์ ์ฐ๋ฆฌ๋ ESI๊ฐ 8๋ณด๋ค ๊ฐ๊ฑฐ๋ ํฌ๋ค๋ ๊ฒ์ ๊ฒ์ฆํ๊ธฐ ์ํด jump ํ๋ค.
Scroll ์ฌ๋ ค.
And if there were not yet 8 "G"
Then we jump to the badboy.
๊ทธ๋ฆฌ๊ณ ์์ง "G"๊ฐ 8์ด ๋์ง ์์๋ค๋ฉด ์ฐ๋ฆฌ๋ badboy๋ก jump ํ๋ค.
Else, we jump to the goodboy !!!
์๋๋ฉด, ์ฐ๋ฆฌ๋ goodboy๋ก jump ํ๋ค!!!
So, let's avoid this situation ;)
We have enough information now to make ourselves a right Keyfile.dat
์ฐ๋ฆฌ๋ ์ด ์ํฉ์ ํผํ๊ฒ ๋ค.
์ฐ๋ฆฌ๋ ์ฌ๋ฐ๋ฅธ Keyfile.dat๋ฅผ ๋ง๋ค ์ถฉ๋ถํ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 24
25. Exactly : at least 8 "G"s and at least 16 bytes all together. There are a lot of good
Keyfile.dat's possible of course.
Now, save the file and โฆ verify !!!
์ ํ : ์ต์ํ "G"๊ฐ 8๊ฐ์ด๊ณ ์ต์ํ 16bytes ๊ฐ ๋์ด์ผ ํ๋ค. ์ข์ Keyfile.dat๋ฅผ ๋ง๋ค ๊ฐ
๋ฅ์ฑ์ด ๊ฝค ๋ง๋ค.
์ด์ , file์ ์ ์ฅํ๊ณ ๊ฒ์ฆํ์ !!!
๋ฒ์ญ ์ฃผ) ์ ๋ ์ด๊ณณ์์ ๊ฝค ํค๋งธ์ต๋๋ค. ์ฒซ๋ฒ์งธ ์กฐ๊ฑด์ G๊ฐ ์ต์ํ 8๊ฐ์ด๊ณ ๋๋ฒ์งธ ์กฐ๊ฑด
์ ์ต์ํ 16bytes ์ ๋๋ค. ๋ ๊ฐ์ง ์กฐ๊ฑด์ ๋ชจ๋ ๋ง์กฑํด์ผ ๋ฉ๋๋ค.
Save the changes
๋ฐ๋ ๊ฒ์ ์ ์ฅํด๋ผ.
Restart the ReverseMe
ReverseMe๋ฅผ ์ฌ์์ ํด๋ผ.
Testing the keyfile5.
With Keyfile.dat in the same directory as the ReverseMe, let's follow and verify
Yep, the jump over the first badboy is taken
Keyfile.dat๋ ReverseMe์ ๊ฐ์ directory์ ์์ด์ผ ํ๋ค. ๋ฐ๋ผ๊ฐ๋ณด๋ฉฐ ๊ฒ์ฆํ์. ์ฒซ๋ฒ์งธ
badboy๋ฅผ Jumpํ๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 25
26. Yep, Keyfile.dat was read
์, Keyfile.dat๋ฅผ ์ฐพ์๋ค.
๋ฒ์ญ ์ฃผ) JNZ๋ EAX๊ฐ zero๊ฐ ์๋ ๋ jump ํ๋ค. TEST EAX, EAX์์ Z-Flag ๊ฐ์ด 1์ด
์๋๋ผ๋ ๋ง. ์ฆ, file์ ์๋ฌด๊ฒ๋ ์๋ค๋ฉด ReadFile ํ์ EAX๋ 0์ด ๋์ด TEST EAX, EAX๋ฅผ
ํ๋ฉด Z-Flag๊ฐ 1์ด ๋๋ค.
How many bytes are read?
Hehe, there are 17h == 23d bytes in the buffer
์ผ๋ง๋ ๋ง์ bytes๋ฅผ ์ฝ์๋?
ํคํค, 17h == 23d bytes๊ฐ buffer์ ์๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 26
27. No jumping to the badboy now !!!
์ด์ Badboy๋ก jumpํ์ง ์๋๋ค.
The first byte โฆ
โฆis a "G" โฆ
์ฒซ๋ฒ์งธ byte๊ฐ "G" ๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 27
28. It is not empty, so we do not jump
์ด๊ฒ์ ๋น์ด์์ง ์๋ค, ๊ทธ๋์ ์ฐ๋ฆฌ๋ jump ํ์ง ์๋๋ค.
It is equal to 47h, --> no jump either
์ด๊ฒ์ 47h์ ๊ฐ๋ค. --> jumpํ์ง ์๋๋ค.
๋ฒ์ญ ์ฃผ) "G"๋ 16์ง์๋ก 47h์ด๋ค. CMP์ ์ํด์ 47 - 47 ์ด๋ฏ๋ก 0์ด ๋๋ค. 0์ด ๋๋ฉด Z-
Flag๋ 1๋ก set ๋๋ค. ๊ทธ๋ฌ๋ฏ๋ก JNZ ๋ Z-Flag๊ฐ 1์ด ์๋ ๋ jumpํ๋๋ฐ Z-Flag๊ฐ 1์ด๋ฏ
๋ก jump๋ฅผ ํ์ง ์๋๋ค.
It was a "G", so ESI is incremented from 0 to 1
์ด๊ฒ์ "G", ๊ทธ๋์ ESI๋ 0์์ 1๋ก ์ฆ๊ฐ๋๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 28
29. And EBX is incremented to verify the next byte in the buffer
๊ทธ๋ฆฌ๊ณ EBX๋ buffer์์ ๋ค์ byte๋ฅผ ๊ฒ์ฆํ๊ธฐ ์ํด ์ฆ๊ฐ๋๋ค.
You see that this jump serves as a loop.
๋๋ ์ด loop์์ jump๋ฅผ ์ง์ํ๋ ๊ฒ์ ๋ดค๋ค.
See that we verify the byte (at 40211B) now.
This is the second byte which is again "G"
์ฐ๋ฆฌ๋ byte๋ฅผ ๊ฒ์ฆํ๋ค.( 40211B์์)
์ด๊ฒ์ 2๋ฒ์งธ byte๋ "G"๋ฅผ ๋ปํ๋ค.
Look a second at the loop, to see how it all works
๋๋ฒ์งธ loop๋ฅผ ๋ด๋ผ, ์ด๋ป๊ฒ ์ผ์ด ์ด๋ฃจ์ด์ง์ง ๋ด.
20120328_lena ํ๊ธ ํ์ด์ง 29
30. Ok. The program has already found 3 "G"
And is about to add the fourth one
Ok. Program์ ์ด๋ฏธ 3๊ฐ์ "G"๋ฅผ ์ฐพ์๋ค.
๊ทธ๋ฆฌ๊ณ 4๋ฒ์งธ๋ฅผ ์ถ๊ฐํ๋ ค๊ณ ํ๋ค.
Now, how can the loop be left?
Not here!
์ด์ , ์ด loop๋ฅผ ์ด๋ป๊ฒ ๋น ์ ธ๋๊ฐ์ผ ํ๋?
์ฌ๊ธฐ๋ ์๋๋ค.
But here and only if the byte is "empty", this is at the end of the file
BTW, the counterpart in hex for the "number" zero (ascii) is not 0 but is 30.
๋ง์ฝ์ ์ด๊ฒ์ด file์ ๋์์ Byte๊ฐ "empty"๊ฐ ๋๋ค๋ฉด ์ค์ง ์ฌ๊ธฐ๋ค.
์ด ๋ถ๋ถ์ ์ซ์ 0์ด ์๋๋ค. ์ซ์ 0์ ascii๋ก 30 ์ด๋ค.
00 means empty !!!
00์ ๋ป์ empty(๋น์ด์๋ค) !!!
48d == 30h == 0 (ascii)
20120328_lena ํ๊ธ ํ์ด์ง 30
31. 48d == 30h == 0 (ascii)
10์ง์ 16์ง์ ascii
๋ฒ์ญ ์ฃผ)์ฆ, ํ๋ง๋๋ก ascii์์ ํ์ผ์ ๋์ 0์ผ๋ก ์ฐ์. ๊ผญ ์ดํดํ๊ณ ๋์ด๊ฐ์ผ ๋จ!
Be sure to understand this and look at the DEC2HEX2ASCII page for this. If you have
no programming background, I'm sure this is a bit confusing at first.
๋ฌผ๋ก , ์ด๊ฒ์ ์ดํดํ์ ๊ฒ์ด๊ณ DEC2HEX2ASCII page๋ฅผ ๋ด. ๋ง์ฝ์ programing ์ง์์ด
์๋ค๋ฉด, ์ฒ์์๋ ๊ฝค ํท๊ฐ๋ฆด ๊ฒ์ด๋ค.
I hope you have understood all so far.
์ง๊ธ๊น์ง ๋ค๊ฐ ์ดํด ํ๊ธฐ๋ฅผ ํฌ๋งํ๋ค.
So, let's run the ReverseMe till โฆ
โฆ here.
์ฌ๊ธฐ๊น์ง ReverseMe๋ฅผ ์คํํ๋ผ.
โฆ ์ฌ๊ธฐ.
20120328_lena ํ๊ธ ํ์ด์ง 31
32. How many "G"s the program has found ???
0Ah == 10d indeed.
์ผ๋ง๋ ๋ง์ "G"๋ฅผ ์ฐพ์์ด?
0Ah == 10d ๋ค.
Those BP's won't be needed any longer :)
์ด์ ๋์ด์ BP๊ฐ ํ์ํ์ง ์๋ค.
No jumping to the badboy:
We jump to the goodboy :))
Badboy๋ก jump ํ์ง ์๋๋ค.
์ฐ๋ฆฌ๋ goodboy๋ก jump ํ๋ค.
Here we come !!!
Let's finally run the ReverseMe to see how things should be โฆ
๋ง์ง๋ง์ผ๋ก ์ด๋ค ์ผ์ด ๋ฐ์ํ๋์ง ๋ณด๊ธฐ ์ํด ์คํํ์.
20120328_lena ํ๊ธ ํ์ด์ง 32
33. ;)
Conclusion6.
Congratulations !!!
You just keyfiled your first ReverseMe.
์ถํํด.
๋๋ ReverseMe๋ฅผ ๋ง ๋๋๋ค.
I hope you understood everything fine and I also hope someone somewhere learned
something from this.
๋๋ ๋ค๊ฐ ๋ชจ๋ ์ดํดํ๊ธฐ๋ฅผ ๊ทธ๋ฆฌ๊ณ ๋๊ตฌ๋ ์ง ์ด๋์์ ์ด๊ฒ์์ ๋ฌด์์ ๋ฐฐ์ ์ผ๋ฉด ํ๊ณ
ํฌ๋งํ๋ค.
See me back in part 3 in this series ;)
๋๋ ์ด series์ Part 3 ์์ ๋์์ค๊ฒ ๋ค.
The other parts are available at
๋ค๋ฅธ parts๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋ค.
http://tinyurl.com/27dzdn (tuts4you)
http://tinyurl.com/r89zq (SnD Filez)
http://tinyurl.com/l6srv (fixdown)
Regards to all and especially to you for taking the time to look at this tutorial.
Lena151 (2006, updated 2007)
๋ชจ๋์๊ฒ ์๋ถ๋ฅผ ์ ํ๊ณ ํน๋ณํ ์ด tutorial์ ์๊ฐ์ ํฌ์ํด์ค ๋์๊ฒ ๊ฐ์ฌํ๋ค.
20120328_lena ํ๊ธ ํ์ด์ง 33