LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-05-2008, 03:15 AM   #1
bloomstar7
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 0
How to Execute the ELF Binary which already resides inside the memory


Hi Guyz,

Is there any way to execute the ELF binary which already resides inside the memory. If so could you please let me know.

Thanks in Advance,
Bloom Star
 
Old 09-05-2008, 01:22 PM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
How do you know a binary resides in memory? Are you referring to shared libraries? or sharefd memory?
 
Old 09-06-2008, 04:07 AM   #3
bloomstar7
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Actually in my current scenario, we are extracting the elf binary and keeping it in memory. I just want to execute that binary directly from memory itself.
I know there are ways to load and execute the elf binary once i copy that to the file system. But i want to avoid keeping it in the file system.
 
Old 09-06-2008, 04:43 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Could you please explain why you consider a scenario like that?
 
Old 09-06-2008, 11:58 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Security is one reason why you might do this. I am contemplating something similar because I need to put a public key in some code. What I myself might be doing is encrypting the entire code module that contains the code to create the key, then loading the module from disk at runtime, decrypting it on the fly, and executing it.

That said, I don't know how to execute it once loaded either. I'll be researching it, but if someone here already knows the answer, that would be great.
 
Old 09-06-2008, 01:08 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
With "you" I actually meant bloomstar7 and "explain" not in a roundabout or theoretical way?
 
Old 09-06-2008, 01:26 PM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I know you meant bloomstar. I weighed in because I am looking at the exact same problem, and I have a perfectly legitimate reason for wanting to do it.
 
Old 09-06-2008, 07:49 PM   #8
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
comment removed
 
Old 09-07-2008, 07:57 AM   #9
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I contemplated this several years ago because I wanted to create an encrypted binary. That said, I never got around to figuring it out.

The problem with having the file itself loaded into memory is that nothing is mapped how it should be. The dynamic loader counts on a tangible file to map symbols into a process image and I don't know if it can do that with something already in memory. You might be stuck writing your own version of the dynamic loader that works from a memory location.

ELF programs are generally preceded by a small program in ld.so that loads all of the appropriate symbols from shared libraries. This program reads the executable file itself for its dependencies. I don't know if the loader even loads the entire binary file at once. In any case, it isn't just a matter of putting the program into memory and saying "go!"

How trivial is the binary "file"? Is it out of the question to just write it to a real file and execute it from there?
ta0kira
 
Old 09-07-2008, 09:25 AM   #10
bloomstar7
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
As i explained above i choose this scenario because of security concern. Actually my ELF contains the security information which i want to avoid keeping it on the file system.

As per the current comments it looks like there is no way of executing the ELF directly form the memory itself. If there is a way please feel free to comment it.

And as of the other option, i am thinking of keeping it at some random location inside the file system, loading it using "execve" command and immediately deleting it form the file system. It means my ELF will present on file system at some random location for small amount of time. For doing this all of my ELF should be loaded in to the memory when i execute "execve" command. I am not sure whether "execve" command loads whole ELF in to the memory or not.(ofcourse if i have enough ram to fit whole of my elf).

Here just i want to confirm whether there is any way or option to force loading whole ELF in to the memory in single time? If so please let me know.

Please feel free to comment your opinions if you feel there is any other better way of doing it.
 
Old 09-07-2008, 09:34 AM   #11
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Well, how does the binary get into memory? Is it compiled into its location, or does it originate from an encrypted file? Have you thought about creating an ext2 image just large enough to hold the binary, then encrypting that image with a loopback?
ta0kira
 
Old 09-08-2008, 09:46 AM   #12
bloomstar7
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Yes. Binary came in to memory by extracting the encrypted file. I am not sure of how to create the ext2 image of the binary. If you don't mind could you please explain me a little bit.
 
Old 09-08-2008, 04:28 PM   #13
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
This can be a little complex, depending on if your system has dm-crypt or just losetup. Is /usr/sbin/cryptsetup a valid program on your system? I'll have to formulate something simple because I've been using my own scripts for this for 3+ years and they do a whole lot more than what you need.
ta0kira
 
Old 04-01-2010, 07:21 AM   #14
kralizec
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Rep: Reputation: 0
I know this is an ooooooold post... but... I'm trying to do the same thing at the moment... anyone got news on getting executed an elf that's already in ram?
 
Old 04-01-2010, 01:34 PM   #15
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
XIP -execute-in-place?
 
  


Reply

Tags
loader



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot Execute Binary rightsidedown Linux - Software 8 05-10-2011 12:41 AM
RHE3.0 elf binary will it work on RHE4.0 URGENT dayalan_cse Linux - Enterprise 3 10-28-2006 08:36 AM
very new to C, how to execute command inside C? neurotic85 Programming 5 09-05-2005 08:19 AM
How to compile into ELF binary? kornerr Programming 3 06-29-2005 11:37 AM
Reading Memory Value from ELF Binary Damaged Soul Programming 4 11-24-2004 11:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration