buffer-overflow

return to libc - problem

浪尽此生 提交于 2019-12-03 13:52:17
I'm having problems with return-to-libc exploit. The problem is that nothing happens, but no segmentation fault (and yes I'm actually overflowing the stack). This is my program: int main(int argc, char **argv) { char array[512]; gets(array); } I'm using gets instead of strcopy, because my addresses start with 0x00 and strcpy thinks it's the end of a string, so I can't use it. Here are the addresses that I need: $ gdb main core (gdb) p system $1 = {<text variable, no debug info>} 0x179680 <system> (gdb) p exit $2 = {<text variable, no debug info>} 0x16f6e0 <exit> (gdb) x/s 0xbffffe3f 0xbffffe3f

What is the most hardened set of options for GCC compiling C/C++?

痞子三分冷 提交于 2019-12-03 12:48:46
What set of GCC options provide the best protection against memory corruption vulnerabilities such as Buffer Overflows, and Dangling Pointers? Does GCC provide any type of ROP chain mitigation? Are there performance concerns or other issues that would prevent this GCC option from being on a mission critical application in production? I am looking at the Debian Hardening Guide as well as GCC Mudflap . Here are the following configurations I am considering: -D_FORTIFY_SOURCE=2 -fstack-protector --param ssp-buffer-size=4 -fPIE -pie -Wl,-z,relro,-z,now (ld -z relro and ld -z now) Are there any

Secure C and the universities - trained for buffer overflow

随声附和 提交于 2019-12-03 08:49:07
I recently finished a university course in C. Therefore I lack experience, of course. Some universities tend to teach their students secure programming, or at least some elements . There's even a video (taken from here ). Being in C, copying strings, requires - as far as I know - strcpy or string.h functions. How do you use it securely in every-day programming? Do you have some functions, which handle allocation to prevent buffer overflows? There's the CERT secure coding standard for C . It's offering examples and compliant solutions: int main(int argc, char *argv[]) { /* ... */ char prog_name

How to replace the return address on the stack using a buffer overflow attack

旧城冷巷雨未停 提交于 2019-12-03 08:39:15
For a homework assignment, I am performing a series of buffer overflow attacks. I was given a program to disassemble, the source code in C for a function that improperly calls gets() , and the source code for several other functions that I am supposed to force the program to call. For one of the tasks, I have to: Inject some code that changes a value, then Return to one of the aforementioned methods The main thing that I don't understand where the program looks in the stack when determining where to return. Where is the return address for a method stored on the stack? The program was compiled

Why do I get access violations when a control's class name is very, very long?

我的梦境 提交于 2019-12-03 05:35:58
I subclassed a control in order so I can add a few fields that I need, but now when I create it at runtime I get an Access Violation . Unfortunately this Access Violation doesn't happen at the place where I'm creating the control, and even those I'm building with all debug options enabled (including "Build with debug DCU's") the stack trace doesn't help me at all! In my attempt to reproduce the error I tried creating a console application, but apparently this error only shows up in a Forms application, and only if my control is actually shown on a form! Here are the steps to reproduce the

How does a NOP sled work?

隐身守侯 提交于 2019-12-03 01:17:55
问题 I can't find a good source that answers this question. I know that a nop sled is a technique used to circumvent stack randomization in a buffer overflow attack, but I can't get my head around how it works. What's a simple example that illustrates this method? What do terms like 128-byte nop sled mean? 回答1: Some attacks consist of making the program jump to a specific address and continue running from there. The injected code has to be loaded previously somehow in that exact location. Stack

Why is this code vulnerable to buffer overflow attacks?

心不动则不痛 提交于 2019-12-03 00:04:34
问题 int func(char* str) { char buffer[100]; unsigned short len = strlen(str); if(len >= 100) { return (-1); } strncpy(buffer,str,strlen(str)); return 0; } This code is vulnerable to a buffer overflow attack, and I'm trying to figure out why. I'm thinking it has to do with len being declared a short instead of an int , but I'm not really sure. Any ideas? 回答1: On most compilers the maximum value of an unsigned short is 65535. Any value above that gets wrapped around, so 65536 becomes 0, and 65600

heap overflow attacks

核能气质少年 提交于 2019-12-02 22:28:52
How heap overflow attacks are done? In case of stackoverflow attacks, the attacker replaces the function return address with his address. How this is done in heap overflow attacks? Also, is it possible to run code from heap? Michael Note this varies by platform, and my example is overly simplified. It basically comes down to heap managers having linked lists that could be overrun, and you can use the linked list pointers to overwrite random parts of the process's memory. Imagine I have a naive heap implementation whose control blocks are like this: struct HeapBlockHeader { HeapBlockHeader*

Why buffer overflow doesn't affect to this code?

安稳与你 提交于 2019-12-02 21:48:09
问题 I have the following code: int main(int argc, char *argv[]) { char ch[10]; printf("String 10 max. :: "); gets( ch ); printf("String: %s\n", ch); return 0; } When I run this with "12345678" as ch it runs well. The strange thing is when I run with "123456789012345678901234567890" ! The second printf prints ALL the string (the 30 chars) to the screen. Why does this happen? Why doesn't my code crash? Thanks for your time, Azteca 回答1: You're not seeing any effect because you don't have any more

Shellcode for a simple stack overflow: Exploited program with shell terminates directly after execve(“/bin/sh”)

允我心安 提交于 2019-12-02 16:22:14
I played around with buffer overflows on Linux (amd64) and tried exploiting a simple program, but it failed. I disabled the security features (address space layout randomization with sysctl -w kernel.randomize_va_space=0 and nx bit in the bios). It jumps to the stack and executes the shellcode, but it doesn't start a shell. The execve syscall succeeds but afterwards it just terminates. Any idea what's wrong? Running the shellcode standalone works just fine. Bonus question: Why do I need to set rax to zero before calling printf? (See comment in the code) Vulnerable file buffer.s : .data .fmtsp: