Shellcode Generation using C


 
Thread Tools Search this Thread
Top Forums Programming Shellcode Generation using C
# 1  
Old 10-07-2007
Shellcode Generation using C

Hi,

I was just learning about buffer overflow attacks... I was curious as to how to generate a simple shellcode. I've written two codes - One is the typical program that has a vulnerability inside and the other is the shellcode.

main program:
Code:
void test();

int main() {
   test();
   return 0;
}

void test() {
   int *ret;
   ret = (int *)&ret + 2;
   (*ret) = (int)shellcode;
}


I was thinking of putting the shellcode into the shellcode found in the end which is a character array.

And as for the shellcode generation, I've written something like:

Code:
#include <unistd.h>

int main() {
  char buf[]="Hello World";
  write(1,buf,sizeof(buf));
  exit(0);
}


But I don't know how to generate the shellcode from this so that I can put it in the original program in the form of char shellcode[] = ...... How would I go about doing this? And yeah if this is the wrong forum, please move this post because I didn't know where else this has to be posted...
# 2  
Old 10-08-2007
Imagine a program which normally prints "Hello World".

Then there is another program which uses that output...

char buf[32];
FILE *fp=popen("hello","r");
fread(buf,1,256,fp);
pclose(fp);

.. and it so happens that this always works because "hello" never returns more than 32 characters. One day it returns more, and then overruns the buffer affecting the return address. The function then returns into hyperspace.
# 3  
Old 10-08-2007
And thats where the fun begins? Smilie That was a great explanation. Thank you... I was actually trying to spawn a shell after reading a couple of articles but somehow couldn't properly understand Shellcode generation because most of the online articles say "To keep this article simple, I'd skip shellcode generation" and that was the instant when I thought of going for simple things - To generate one for atleast Hello World... Its funny that I got a shellcode itself for "Hello World" generation but I'm not searching for the answer instead the solution...
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Cybersecurity

basic shellcode - why it runs on my system, if .data is not executable

Greetings, Suppose we have this piece of code, on Linux/i686 (my machine is Slackware Linux 13.1, 32 bit): char sc= /* 24 bytes */ "\x31\xc0" /* xorl %eax,%eax */ "\x50" /* pushl %eax ... (2 Replies)
Discussion started by: aigoia
2 Replies

2. UNIX for Dummies Questions & Answers

Difference Shellcode and Shell scripting

Heey guys I am new to Unix and got a question on scripting (bash etc.) I now and then stumble into some tutorials on shellcoding after which I completely lose it. The question is: what is the difference between shellcoding, shell scripting and shell programming. I searched on google, but it... (1 Reply)
Discussion started by: Kealthes
1 Replies

3. Programming

Passing arguments to shellcode

Is there any way I could pass arguments to shellcode. My goal is to store a program in a image file, and have another program read and run the code with arguments in memory. Currently I can store a program in a image file, then read it back to the hard-drive run it normally then delete it when... (5 Replies)
Discussion started by: image28
5 Replies

4. Shell Programming and Scripting

Help with excelsheet generation

Hi All, i have around 50 queries in sybase. We have a requirement where we need to write a unix script, which execute the query one by one & generate the excel sheet & send it to user. I have completed half of the part, where i am executing query one by one & putting the result into a .txt... (4 Replies)
Discussion started by: Amit.Sagpariya
4 Replies

5. Shell Programming and Scripting

Graph generation

How can I generate graphs using perl in unix solaris environment? Please suggest. (2 Replies)
Discussion started by: wadhwa.pooja
2 Replies

6. Shell Programming and Scripting

Report generation

Hello, I got a requirement in writing a KSH script in unix, please help me out the requirement is there are two folders Folder1 and Folder2 and there are same files in the different folders. like file1,file2 in folder1 and file1 and file2 in folder2. I would like to compare all the similar... (3 Replies)
Discussion started by: gmahesh2k
3 Replies

7. UNIX for Dummies Questions & Answers

report generation

Hello, I got a requirement in writing a sheel script in unix, please help me out the requirement is there are two folders Folder1 and Folder2 and there are same files in the different folders. like file1,file2 in folder1 and file1 and file2 in folder2. I would like to compare all the... (2 Replies)
Discussion started by: gmahesh2k
2 Replies
Login or Register to Ask a Question