underhanded | The ultimate underhanded dotfiles | Configuration Management library
kandi X-RAY | underhanded Summary
kandi X-RAY | underhanded Summary
The ultimate underhanded dotfiles. In particular, these are intended to be clever and devious, not (just) mean.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of underhanded
underhanded Key Features
underhanded Examples and Code Snippets
Community Discussions
Trending Discussions on underhanded
QUESTION
I have the following C program which requests some memory (str1
), reads the content of a file into that space then frees it. Next, a block of the same size (str2
) is requested, and the content is printed to stdout.
What I want is for str2
to contain the content of str1
so that the output is always the content of the file.
I am aware that what I am doing is undefined behaviour, in that I can't guarantee what the content of memory that has been allocated will contain. However, I'm trying to do some underhanded stuff for a demonstration where data from a file can be exfiltrated without it being obvious in a code review.
Almost all the time, I receive a block of memory at the same address for both str1
and str2
, and most of the time when I run the program on macOS and Windows, the content of the file is printed. It seems to never happen on Linux (on Linux, calling free()
seems to zero out the memory block).
Is there a way of making this more reliable on Windows and macOS, and is there any explanation for why it doesn't work at all on Linux?
My code is:
...ANSWER
Answered 2021-Mar-03 at 09:32Is there a way to reliably malloc the same block of memory as a previously freed block
Yes, use realloc
instead of free
+ malloc
. Otherwise there's no reliable or safe way to get the exact amount at the same address.
I receive a block of memory at the same address for both str1 and str2
Well there's not much else going on in this simple program, so perhaps no wonder. There's no guarantees though. Also, unless you actually do a write access to the heap, the memory allocation might not actually be called. So str2
could just be some random address in case the whole malloc call gets optimized away. Or alternatively, malloc is called but the OS never allocates any actual memory.
is there any explanation for why it doesn't work at all on Linux?
I don't know but I suspect ASLR might have something to with it. Some Linux guru will have to answer that part.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install underhanded
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page