The passcode of pwnable.kr

Source: Internet
Author: User


Passcode

Download the source code down

From the source code analysis to see, in the scanf time Passcode1 and Passcode2 no address symbol, so there will be a warning in the title.

This wood has two functions, welcome and login, entered the name string in Welcome, then entered Passcode1 and Passcode2 in login, passcode1= 338150 (0x528e6) and passcode2=13371337 (0XCC07C9) return to the shell and get flag.

To take for granted:


Unexpectedly found a paragraph error. What the heck. So I wrote a Python script (think it is wrong to enter 338150), to enter hex with Python ... )

I found out later that I couldn't.

Then think, can use the input name to overwrite Passcode1 and Passcode2. But name and Passcode1 and Passcode2 are in two functions, so it doesn't seem to work, nor is there a format string vulnerability in the name input.

Only the scanf function, passcode1 and passcode2 do not use the address symbol. How to use it?

Here's a point of knowledge: if you don't use the address symbol, the program uses the data on the stack as a pointer to hold the input data.

Then start debugging the program.

PS: I heard that Peda is very useful, so I also installed a play, sure enough, really useful

Let's look at the functions.


Then welcome the breakpoint, analyze the Welcome function

Here you can see that the welcome function of the EBP is 0xbffff088, the second red arrow indicates the use of GS protection, the two points in the back will be said.

Continue execution


In this address is the input name of the format string, then the following edx is the name of the address, first write down

Name: [ebp-x070]


See the input AA in 0xbffff018

Go on


Here you will see, the program to EBP-0XC place to do a check, if compared with the previous. You will find that if the value of this place is modified, it will call [email protected] and can be seen from Ida

Continue into the login function


Strange thing happened, Login's EBP is also 0xbffff088, this is not the same as the beginning of the Welcome EBP?

Write it down, go ahead.

Here is another scanf,ebp-0x10 is the address of passcode1, here to note, since the two function of the EBP is the same, then name and Passcode1 in a stack space, think of what? ...

You didn't think of anything? Then go on.

Crashed after entering a passcode1.


When will scanf collapse? Contact said earlier, write scanf function when there is no add address symbol, that must be written to the address is not writable (indicating this time passcode1 point to a non-writable address, because there is no initialization! )。 So when does this address have to be written?

Need to use a knowledge point: Because the Got table is writable.


Look at the login function, call the Fflush, printf, exit


The passcode1 and name mentioned above are in a stack space, calculate the difference between name and Passcode1 96 bytes, so the name after 4 bytes can be overwritten to passcode1. You can therefore overwrite the address of the passcode1 with the address of fflush or printf or exit, and then use the SCANF function to override the system's address. Such calls to Fflush or printf or exit are called the system. (The reason that the system function can be called is that Linux does not randomize the code segment)

The idea is clear, the next step is to find the address.

See the Got area from Ida, where you can read flag directly with the system: 080485E3



These three addresses are available.

Let's use printf here, 0804a000.

And because of the scanf's use of%d, so to convert the system address into decimal

System:080483e3 = = 134514147 (decimal)

Payload = ' A ' *96 + ' \x00\xa0\x04\x08 ' + ' \ n ' + ' 134514147\n '

Python-c "Print (' A ' *96+ ' \x00\xa0\x04\x08 ' + ' \ n ' + ' 134514147\n ')" |./passcode

Local testing


pwnable.kr Test


Flag:sorry mom. I got confused aboutscanf usage:(

Reference:

Http://jing0107.lofter.com/post/1cbc869f_8b3d8a5

http://www.frog0d.ml/pwnable-kr-toddlers-bottle-passcode/

Http://blog.yiz96.com/archives/34

http://bluereader.org/article/47636676

Http://naphthalol66.rssing.com/chan-60259461/all_p5.html#item91

Http://rickgray.me/2015/07/24/toddler-s-bottle-writeup-pwnable-kr.html

The passcode of pwnable.kr

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.