buffer-overflow

sscanf function changes the content of another string

大憨熊 提交于 2019-12-02 14:06:56
问题 I am having problems reading strings with sscanf . I have dumbed down the code to focus on the problem. Below is a function in the whole code that is supposed to open a file and read something. But sscanf is acting strangely. For instance I declare a string called atm with the content 'ATOM' . Before the sscanf it prints this string as ATOM while after it is null. What could be the problem? I assume it must be an allocation problem but I could not find it. I tried some suggestions on other

Memory overwrite problem

放肆的年华 提交于 2019-12-01 10:12:39
问题 I have one C code app. which i was building using MS-VS2005. I had one output data buffer which was being allocated dynamically using malloc. For some test cases, the memory size which was being malloc'd was falling short than the the actual output size in bytes which was generated. That larger sized output was written into the smaller sized buffer causing buffer overflow. As a result of which the test-run was crashing with MSVS-2005 showing up a window "Heap corruption ...." I knew it had to

Writing a return-to-libc attack, but libc is loaded at 0x00 in memory

做~自己de王妃 提交于 2019-12-01 07:04:22
I'm writing a return to libc attack for my systems security class. First, the vulnerable code: //vuln.c #include <stdio.h> #include <stdlib.h> int loadconfig(void){ char buf[1024]; sprintf(buf, "%s/.config", getenv("HOME")); return 0; } int main(int argc, char **argv){ loadconfig(); return 0; } I want to use a return to libc attack. Compiling and debugging the program: $ gcc -g -fno-stack-protector -o vuln vuln.c $ gdb vuln (gdb) break loadconfig (gdb) run Reached breakpoint blah blah blah. (gdb) p $ebp $1 = (void *) 0xbfffefb0 (gdb) p system $2 = {<text variable, no debug info>} 0x0016db20

C Code how to change return address in the code?

徘徊边缘 提交于 2019-12-01 04:04:25
I just wrote a C Code which is below : #include<stdio.h> #include<string.h> void func(char *str) { char buffer[24]; int *ret; strcpy(buffer,str); } int main(int argc,char **argv) { int x; x=0; func(argv[1]); x=1; printf("\nx is 1\n"); printf("\nx is 0\n\n"); } Can please suggest me as to how to skip the line printf("\nx is 1\n"); . Earlier the clue which I got was to modify ret variable which is the return address of the function func . Can you suggest me as to how to change the return address in the above program so that printf("\nx is 1\n"); is skipped. I have posted this question because I

How does Visual Studio 2013 detect buffer overrun

时间秒杀一切 提交于 2019-12-01 03:50:51
Visual Studio 2013 C++ projects have a /GS switch to enable buffer security check validation at runtime. We are encountering many more STATUS_STACK_BUFFER_OVERRUN errors since upgrading to VS 2013, and suspect it has something to do with improved checking of buffer overrun in the new compiler. I've been trying to verify this and better understand how buffer overrun is detected. I'm befuddled by the fact that buffer overrun is reported even when the memory updated by a statement only changes the contents of another local variable on the stack in the same scope! So it must be checking not only

Inputting Non ASCII characters to scanf(“%s”)

百般思念 提交于 2019-12-01 02:22:59
问题 Is there a way one can issue non ascii hex characters to a scanf that uses %s ? I'm trying to insert hexadecimal chars like \x08\xDE\xAD and so on (to demonstrate buffer overflow). The input is not to a command line parameter, but to a scanf inside the program. 回答1: I assume you want to feed arbitrary data on stdin (since you read with scanf ). You can use the shell to create the data and pipe it into your program, e.g. printf '\x08\xDE\xAD' | yourprogram Note that this will only work as long

Valgrind giving error but everything seems fine

时光怂恿深爱的人放手 提交于 2019-12-01 00:41:08
This one seems like a duplicate of my previous post but it is not..... Here Valgrind giving the following error: udit@udit-Dabba ~/mec $ valgrind --leak-check=full sendip -v -p ipv6 -f file.txt -6s ::1 -p esp -es 0x20 -eq 0x40 -ei z30 -eI z100 -p tcp -ts 21 -td 21 ::2 ==4331== Memcheck, a memory error detector ==4331== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==4331== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info ==4331== Command: sendip -v -p ipv6 -f file.txt -6s ::1 -p esp -es 0x20 -eq 0x40 -ei z30 -eI z100 -p tcp -ts 21 -td 21 ::2 ==4331== esp

if one complains about gets(), why not do the same with scanf(“%s”,…)?

∥☆過路亽.° 提交于 2019-11-30 22:15:00
From man gets : Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead. Almost everywhere I see scanf being used in a way that should have the same problem ( buffer overflow/buffer overrun ): scanf("%s",string) . This problem exists in this case? Why there are no references about it in the scanf man page? Why gcc does not warn when compiling this

Set RTSP/UDP buffer size in FFmpeg/LibAV

回眸只為那壹抹淺笑 提交于 2019-11-30 16:10:46
Note : I'm aware ffmpeg and libav are different libraries . This is a problem common to both. Disclaimer : Duplicate of SO question marked as answered but actually didn't give a proper solution. Insufficient UDP buffer size causes broken streams for several high resolution video streams. In LibAV/FFMPEG it's possible to set the udp buffer size for udp urls (udp://...) by appending some options (buffer_size) to it. However, for RTSP urls this is not supported . These are the only solutions I've found: Rebuilding ffmpeg/libav changing the UDP_MAX_PKT_SIZE in the udp.c source file. Using a nasty

Format String Attack

故事扮演 提交于 2019-11-30 15:21:07
I have a small C program to be exploited. And I also understood the logic behind the attack to be performed. However, as much as I try, it is just not working for me. #include <stdio.h> #include <stdlib.h> #define SECRET1 0x44 #define SECRET2 0x55 int main(int argc, char *argv[]) { char user_input[100]; int *secret; int int_input; int a, b, c, d; /* other variables, not used here.*/ /* The secret value is stored on the heap */ secret = (int *) malloc(2*sizeof(int)); /* getting the secret */ secret[0] = SECRET1; secret[1] = SECRET2; printf("Please enter a decimal integer\n"); scanf("%d", &int