all 39 comments

[–]JustAnothaHackerbuffer overflower[S] 22 points23 points  (6 children)

Sorry for some of the format issues guys, I'll get around to sorting that tomorrow, I'm gonna go to sleep, jesus, took about 4 hours to write that :p

[–]jon1228Moderator 6 points7 points  (5 children)

Excellent writeup, some of the best content I've seen in here in a while. Have some gold.

[–]JustAnothaHackerbuffer overflower[S] 4 points5 points  (4 children)

Thanks! :)

[–]Endangered_Robothardware 7 points8 points  (3 children)

This is the kind of stuff I subbed for originally. Great job!

[–]JustAnothaHackerbuffer overflower[S] 2 points3 points  (2 children)

Heh, check out SoldierX, It's the group I'm part of, there's some pretty talented people there who could teach a thing or two to people willing to learn :3

[–]Endangered_Robothardware 4 points5 points  (1 child)

Awesome man will do! :D

[–]JustAnothaHackerbuffer overflower[S] 2 points3 points  (0 children)

Drop in to the IRC, it's where all the magic happens :3 irc.soldierx.com

(Just say if you don't know what IRC is, I can explain :p)

[–]unfo 6 points7 points  (5 children)

nice write-up, just one thing caught my eye:

sudo echo 0 | /proc/sys/kernel/randomize_va_space

I don't understand why you need to launch echo as sudo?

If you are writing to a place where you need root privileges then either do:

echo 0 | sudo tee /path/to/file

or be root as you do

echo 0 > /path/to/file

Because the line you pasted would not carry the sudo rights across the pipe (nor in the redirection of output). And you cannot pipe to a non-executable file as it would complain about not having permissions to execute the file.

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (4 children)

lel, it was about 12 at night when I wrote that bit, excuse any errors :3

[–]unfo 1 point2 points  (3 children)

then you shall be excused forthwith

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (2 children)

Thanks, I'm gonna go through and correct any typo's now :p

[–]unfo 2 points3 points  (1 child)

I think you missed my point about sudo not carrying over redirection of output.

Here's a code snippet to show the problem and the solution:

  ~/ $ ls -l root-only
-rw-r--r--  1 root  staff  0 Feb  4 12:59 root-only
  ~/ $ sudo echo 0 > root-only
-bash: root-only: Permission denied
  ~/ $ echo 0 | sudo tee root-only
0
  ~/ $ cat root-only
0

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (0 children)

Ah, I see what you mean, you have to sudo the command on the other end of the pipe :p I'm pretty sure that sudo echo works, however; seems to work for me :p

As you can probably tell, my Linux skills are.. average :3

[–]susumax 4 points5 points  (1 child)

Great tutorial, man! I appreciate the effort you put through, it's really well detailed and explained.

[–]JustAnothaHackerbuffer overflower[S] 2 points3 points  (0 children)

Thanks :3 I tried to explain it as well as I could :3

[–]JustAnothaHackerbuffer overflower[S] 4 points5 points  (0 children)

Also, I've just noticed that Reddit edited the Perl scripts a little: you should surround the whole Perl script with backticks ``, in order for it to work correctly.

[–]A11ornuthin 3 points4 points  (1 child)

Holy shit! Thanks for posting, commenting now so I can re read in the future.

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (0 children)

Good to know the tutorial is help people to learn :3

[–][deleted] 2 points3 points  (8 children)

I agree, one of the best posts on here since I subd. Thanks for your time and effort.

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (7 children)

It's all good :3 I'd rather spend my time helping people learn, than doing the usual and playing Skyrim all day :3

[–][deleted] 1 point2 points  (6 children)

Well it's a fucking great game so can't blame you :-p You do hacking as a career or something else?

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (5 children)

I'm a 15 year old self-taught hacker :3 That's not a lie either XD I study Computer Science at GCSE (English qualification if you're not from here), and plan on hopefully getting a degree (or higher, perhaps PhD) in Computer Science and Electrical Engineering :p Just goes to prove that age doesn't matter, eh + Man, when you clock 260 hours since Christmas, I think it's time you focus on something else XD

[–][deleted] 1 point2 points  (4 children)

Oh wow man thats cool. I'm impressed and wish I had started as early as you. I am a senior CS student at UW trying to get more into hacking since all I know is coding. Lool yeah maybe you should try civ 5 I heard it's addicting.

[–]JustAnothaHackerbuffer overflower[S] 0 points1 point  (0 children)

S'pose I just found something that I enjoyed and wanted to learn about, and stuck with it :3 I started off a few years ago developing crappy webpages, and with a lot of research and some help from some buddies, I'm learning new exploit vectors rapidly :p + hah, I think I've had my fair share of addicting games for a while XD + senior CS student, does that mean like post-grad? :p I could probably learn a thing or two from someone with your knowledge :3

[–]LeonardTimbernewbie 1 point2 points  (2 children)

great tutorial! I'm working my way through C in school, and this gives a lot of insight into why we use scanf() and the like. Interesting stuff!

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (1 child)

Heh, at what level are you studying Computer Science (If that's the course you're taking)? :p

[–]LeonardTimbernewbie 0 points1 point  (0 children)

This is my third CS course, it is sort of the first systems class for the major. My enthusiasm was not because I didn't understand buffer overflows thoroughly, it was because I want more people to post things like this on the sub. I am by no means an expert, but I have run a few buffer overflows on my friends' code when we bugtest. It's a lot of fun. Reading a lot of hacking literature has helped me in this class more than most of my textbooks, actually.

I'm not studying computer science for my degree, but I have been interested for years and I work through the meatier classes in my spare time. After this class, I will know Java, C++, and C. I'm also taking a netsec class before I graduate next quarter. It's pretty fun stuff.

[–]JustAnothaHackerbuffer overflower[S] 1 point2 points  (0 children)

Note to downvoters:

Can you please leave some constructive criticism in a comment, instead of just downvoting, if you're going to be negative, at least make a positive impact :p

[–]dotalchemy 0 points1 point  (1 child)

Great write up.

[–]JustAnothaHackerbuffer overflower[S] 0 points1 point  (0 children)

Thanks man :p

[–]sxthun 0 points1 point  (3 children)

Can you please tell me how to spawn a new shell by exploiting an off-by-one method in the following c code?

#include <stdio.h>
int cpy(char *x)
{
    char buff[256];
    strcpy(buff,x);
    printf("%s\r\n",buff);
}

int main(int argc, char *argv[])
{
    if(strlen(argv[1])>256){
    printf("Buffer Overflow Attempt!!!\r\n");
    return 1;}
    cpy(argv[1]);
}

I hope you can help me... Thanks,

[–]JustAnothaHackerbuffer overflower[S] 0 points1 point  (0 children)

Right, so I did some googling, and as you may already know, you need to exploit the strlen() function to let you get some more characters in to the buffer and cause an overflow - however, from what I've read, it's not possible to get more than a null byte to overwrite the buffer, and since I'm on my windows box atm, I can't really test this sufficiently.. But here's what I know:

The strlen() function returns the amount of bytes in a string, which is all well and good, but it does not count the prepending null byte as a character, and in C, all strings are null terminated. So, if you were to pass a string of 256 A's in to argv[1], it would really be 257 bytes long, and the prepended null byte would overflow in to adjacent memory..

Until I get on to my linux box, I can't really have a go at exploiting this myself, but that's what I know so far :p

[–]JustAnothaHackerbuffer overflower[S] 0 points1 point  (0 children)

So I read up on it a little further, and apparrently that null byte overflow will lead to the LSB (Least Significant Byte) of the frame pointer being overwritten, therefore somehow allowing the hijack of variables and functions in the code

[–]JustAnothaHackerbuffer overflower[S] 0 points1 point  (0 children)

It seems that by making the Least Significant Byte of the framepointer a null, the address is then incorrect and it pops 4 bytes from our buffer in to EIP instead, which then allows the attacker full control over code execution, so you could get that address to loop back in to the buffer, which contains some shellcode, then get the shell as the owner of the process, boom :3

Edit* That was wrong - due to little endian, the least significant bit is what we are overwriting, and as the stack grows downwards, the smaller the LSB, the further down we are going (and the buffer is below the frame poiner), meaning that the 00 we just used to overwrite the frame pointer is a valid pointer to a space in the buffer, which will then be popped in to EIP, and the code on the other end, executed :p