![]() |
|
[C] Linux C++/C Dll injection + Code Injection Tutorial - Part Two - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Linux C++/C Dll injection + Code Injection Tutorial - Part Two (/showthread.php?tid=2228260) |
Linux C++/C Dll injection + Code Injection Tutorial - Part Two - g4143 - Feb 19, 2012 Main Page - https://hackforums.net/showthread.php?tid=2220892 Part Two - Preparing the injected code for both 32/64 bit GNU/Linux systems. This part is preparing the package to be injected. Its basically shell code what we're preparing here. Note: I know GNU/Linux (Intel/AMD) operates with both a 32 and a 64 bit environments so I'll prepare our package for 64 bit environment and let the user, if needed prepare the package for a 32 bit environment. The steps will be the same just use the 32 assembler code instead of the 64 bit assembler code. So if you have a 32 bit system then use the code that follows the 64 bit...Both 32 and 64 bit assembler code follows the same instructions. 64 bit assembler code hello.s Code .section .dataThe compile lines for hello.s are below Quote:as hello2.s -o hello2.o Once you have copied and compiled the code, run it and you should have the following output Code Injected, Code!And yes I know the program 'Seg faults' but that's O.K. because we're going to strip down this code. In a terminal run the objdump command and it will produce a text file named 'textfile' that contains a dump of the code hello. Code objdump -D hello>testfileHere's what textfile(objdump result) should look like. Code hello: file format elf64-x86-64Now armed with this info(textfile) you'll have to open hello in a hex editor and remove all the hex values except what's listed in textfile...The final product should look something like below(Note: this is what it'll look like in the hex editor). hexeditor result Code 55 48 89 E5 50 57 56 52 E8 00 00 00 00 5E 48 81 C6 28 00 00Congratulations, hello now contains our shell script that we'll inject into a running process. Well we'll inject it after two more tutorials. The 32 bit version follows32 bit version hello.s Code .section .datacompile lines Code as hello2.s -o hello2.oOutput from the 32 bit code. Code Injected, Code!The objdump line. Code objdump -D hello>testfileThe contents of textfile Code hello: file format elf32-i386Once you strip the hello file it should look like the output below..We're just stripping everything out of hello except what's in the textfile displayed above. Code 55 89 E5 50 53 51 52 E8 00 00 00 00 59 81 C1 20 00 00 00 B8Now that your've created the shell script(hello), you'll have to wait for the next to tutorials to inject it. Wow the responses are overwhelming... To give you an idea where we're going with this, check out the following code. It basically calls the shell code we created above. The 64 bit example - Only for 64 bit GNU/Linux operating systems. Code #include <stdio.h>The 32 bit example - Only for 32 bit GNU/Linux operating systems. Code #include <stdio.h>* - -Legacy- - Feb 21, 2012 Why the hell has no one posted? Just because you don't understand the code here, doesn't mean you should not post. I have to go to sleep but once again, I will try this out in the morning. Looks bloody complicated (probably because I don't know assembly) but just the concept is fantastic. Great work on this and did you come up with this all from scratch? Will post results when I can. * - g4143 - Feb 21, 2012 (Feb 21, 2012 12:43 AM)-Legacy- Wrote: Why the hell has no one posted? Just because you don't understand the code here, doesn't mean you should not post. I have to go to sleep but once again, I will try this out in the morning. Looks bloody complicated (probably because I don't know assembly) but just the concept is fantastic. Great work on this and did you come up with this all from scratch? Yep, I pretty much figure out everything from scratch. * - Terror32 - Feb 21, 2012 Very good tutorial keep the good work.Thank you for that. * - Nichole - Feb 21, 2012 I'm definitely looking forward to trying this out! Going to go back to your part one tutorial though, but I'll try it later today when the Linux is all set up! * - [H]ell - Feb 21, 2012 This is to much information for kids on this forum to understand. I advise you to go to another forum. It's what I did. * - g4143 - Feb 21, 2012 (Feb 21, 2012 07:52 AM)[H]ell Wrote: This is to much information for kids on this forum to understand. You are generally right but there is some hidden talent here. So which forum? * - tulamba - Feb 21, 2012 g4143 dude I have bookmarked it. I will give your thread its due share of importance and respect as my background is computer hardware. I saw your post in another thread where you had recommended one member to learn c and assembly. I am wondering if there is a book that addresses both aspects of it. To me,learning c without knowing assembly is like looking at only one side of the picture. Again, its my personal opinion, you and every body can disagree :) Kind Regards, * - Dbof - Feb 21, 2012 (Feb 21, 2012 07:52 AM)[H]ell Wrote: This is to much information for kids on this forum to understand. So where did you go to? I was actually looking for a similar forum, but I have never found anything. PM me 🤝 * - g4143 - Feb 21, 2012 (Feb 21, 2012 09:20 AM)tulamba Wrote: g4143 dude This is one thing I agree with 100 percent. Learn C and the when you have enough questions about how C handles things then start learning general assembler. A sound knowledge of general assembler programming will set a C programmer free. About books that address both C/ASM, I think it still has to be written. |