I am a student and in one of the tasks of the workshop I have to take advantage of the vulnerability in the binary.
Having decompiled the binary, I found out that the program, after starting, reads the line from the standard input and copies it to the buffer. This buffer is a part of the structure, in which there is a flag, after checking for equality to zero, the shell is started with a new euid, with which I can read the protected file.
If you give a sequence of characters of the required length (64 bytes) to the program after it starts, the flag will be zeroed (due to the use of strncat in the program), and the program will launch a shell with the required eiud and I can enter for example cat flag_1.txt to read it content, which I could not do under normal conditions.
Manually everything turns out well, but I need to write an exploit either in the form of a bashcript or a script in python.
Using bash, I created a file with the following contents:
#! / bin / sh
echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | ./task_1
when you run this script, the program gets the required string for input, the flag is clogged with 0, and I get access (because the program also writes Access granted, so I’m sure I got access) However, I’ll use the shell I do not have time, because I see the message stack smashing detected or Abort (core dumped)
On the python, I tried to use subprocess.call or subprocess.popen, but this also did nothing, because I understand that at the moment I don’t manage to NOT wait for the process to complete, which means I cannot use the shell with the new euid, although Access granted is also output, i.e. I get to the right section of the code.
Why does not work bashskript do not understand.
I have very little experience; in fact, we were simply given the assignment without any explanation. Can you please tell me how to write an exploit, or even more likely as a whole, a script that would do the following: 1) run the program 2) give it a read (not as a command line parameter, but to standard input) line 3) let it be used from of this program, a new shell for reading some kind of text file