never stop questioning

elfrip.c

elfrip.c
Posted Jul 17, 2002
Authored by netric, PoWeR PoRK | Site netric.org

Elfrip is a tiny cat-like utility for ripping the code section out of a nasm generated elf image.

systems | unix
MD5 | 8438356e6d669cf90a0ac74d5a5536b6

elfrip.c

Change Mirror Download
/*
*
*[elfrip.c - By PoWeR_PoRK of netric (http://www.netric.org)]
* Tiny cat-like utility for ripping the code section out
* of an elf executable image.
*
* compile with "gcc elfrip.c -o elfrip"
* do a "./elfrip -h" for help with usage
*
* Made for scripting shellcode production sequences more
* easily. Used for nasm generated code, not tested with gas
* generated code but should work just as well (well, gas sucks
* so it might not ;))
*
*/

#include <stdio.h>

#define voffset 0x08048000

char usage[] =
"Usage: ./elfrip [-h][-i <inputelffile>]\n"
"cat like utility for ripping the code segment out of nasm generated elfs.\n"
"Example: ./elfrip -i shellcode.elf > shellcode.bin\n"
"This rips the code section of the elf image shellcode.elf into shellcode.bin\n\n"

"-h See this usage overview.\n"
"-i <inputelffile> Set for rip and set the path of the source elf image to rip from.\n";

int main(int argc, char **argv[])
{
char elfpath[41];
int count = 0;
unsigned int vaddr = 0;
unsigned int phdroffset = 0;
unsigned int codesize = 0;
FILE * elffile;

if(argc <= 1){
printf("%s", &usage);
exit(0);
}else if(argc > 1){
if(!strncmp(argv[1], "-h", 2)){
printf("%s", &usage);
exit(0);
}else if(argc == 3){
}else{
printf("%s", &usage);
exit(0);
}
}else{
printf("%s", &usage);
}

elffile = fopen((char *)argv[2], "r");
if(elffile == NULL){
perror("Error:Opening of file failed (typo?)");
exit(1);
}

fseek(elffile, 24, SEEK_SET);
fread(&vaddr, 1, 4, elffile);
fread(&phdroffset, 1, 4, elffile);

fseek(elffile, phdroffset+16, SEEK_SET);
fread(&codesize, 1, 4, elffile);

fseek(elffile, (vaddr - voffset), SEEK_SET);
if((codesize - (vaddr - voffset)) < 0){
perror("Error: Code segment size mixup, "
"prolly just a big assed gcc generated elf, use nasm instead");
exit(1);
}

for(count = 0; count < (codesize - (vaddr - voffset));count++){
if(feof(elffile) == 0){
putchar(fgetc(elffile));
}else{
perror("Error: EOF encountered during elf load, prolly not an elf "
"(either a gnome or just a particularly small person)");
exit(1);
}
}

return 0;
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

May 2012

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    37 Files
  • 2
    May 2nd
    53 Files
  • 3
    May 3rd
    33 Files
  • 4
    May 4th
    4 Files
  • 5
    May 5th
    10 Files
  • 6
    May 6th
    17 Files
  • 7
    May 7th
    19 Files
  • 8
    May 8th
    36 Files
  • 9
    May 9th
    34 Files
  • 10
    May 10th
    35 Files
  • 11
    May 11th
    20 Files
  • 12
    May 12th
    18 Files
  • 13
    May 13th
    11 Files
  • 14
    May 14th
    27 Files
  • 15
    May 15th
    58 Files
  • 16
    May 16th
    54 Files
  • 17
    May 17th
    25 Files
  • 18
    May 18th
    53 Files
  • 19
    May 19th
    9 Files
  • 20
    May 20th
    15 Files
  • 21
    May 21st
    25 Files
  • 22
    May 22nd
    32 Files
  • 23
    May 23rd
    35 Files
  • 24
    May 24th
    26 Files
  • 25
    May 25th
    25 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2012 Packet Storm. All rights reserved.

close