30

!rant
A rather long(it's 8 hrs long to be precise) story

So I just finished an amazing homework assignment. The goal was to open a new shell on Linux using a C program. We were asked to follow instructions from http://phrack.org/issues/49/14.html . However the instructions given were for 32 bit processors and we had to do same for 64 bit machines. In a nutshell we had to write a 64 bit shell code and use buffer-overflow technique to change the return address if the function to our shell code.

I was able to write my own shellcode within 1hr and was able to confirm that it's working by compiling with nasm and all. Also the "show-off-dev" inside me told me to execute "/bin/bash" instead of "/bin/sh"(which everyone else was going to do). After my assembly code was properly executing shellcode, I was excited to put it in my C code.
For that, I needed opcodes of assembly code in a string. Following again the "show-off-dev" inside me, I wrote a shell script which would extract the exact opcodes out of objdump output. After this I put it in my C code, call my friend and tell him that "hell yeah bro, I did it. Pretty sure sir is gonna give me full marks etc etc etc". I compiled the code and BOOM, IT SEGFAULTS RIGHT IN FRONT OF MY FRIEND. Worst, friend had copied a "/bin/sh" code from shellstorm and already had it working.

Really burned my ego, I sat continuously for 8 hrs in front of my laptop and didn't talk to anyone. I was continuously debugging the code for 8 hrs. Just a few minutes ago, I noticed that the shellcode which I'm actually putting in my C code is actually 2 bytes shorter than actual code length. WHAT THE F. I ran objdump manually and copied the opcodes one by one into the string (like a noob) and VOILA ! IT WORKED !!!

TURNS OUT I DIDN'T CUT THE LAST COLUMN OF OPCODES IN MY SHELL SCRIPT. I FIXED THAT AND IT WORKED !!
THE SINGLE SHITTY NUMBER MADE ME STRUGGLE 8 HRS OF MY LIFE !! SMH

Lessons learnt :
1)Never have such an ego that makes you think you're perfect, cuz you're retarded not perfect
2)Examine your scripts properly before using them
3)Never, I repeat NEVER!! brag about your code before compiling and testing it.

That's it!
If you've read this long story, you might as well press the "++" button.

Comments
  • 9
    Nah. That last paragraph says you haven't learned your first lesson. You seem very sure I'm going to press that "++" button.
  • 0
    This is why I like to use high-level languages, do more with less headaches about the small things like how many bytes a type is on which platform.
  • 0
    @Jmann same here. I felt obligated.
  • 2
    @JohnScott uhm yeah I kind of agree. I shouldn't have put the last line. I tried to put it like those Instagram posts which say "if you've scrolled this far, you might as well follow me". Obviously this is devRant and Instagram. Didn't work anyway. I personally don't like such posts either, but idk why I put it there(i was out of my mind or whatever). I'd make sure I don't put it from next time.
  • 0
    @FancyDeveloper I have certain reservations about the way people leave captions like that on Instagram. It sounds like an awesome project but please be careful with your words; can make you (or anyone) seem less than genuine.
  • 2
    @JohnScott Uh oh, pressed ++ anyway...
Add Comment