exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

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
SHA-256 | d04491b975521b75ef0b591b237c4372cec5f1be775b96ff57fb534aa0a5189f

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;
}
Login or Register to add favorites

File Archive:

March 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    16 Files
  • 2
    Mar 2nd
    0 Files
  • 3
    Mar 3rd
    0 Files
  • 4
    Mar 4th
    32 Files
  • 5
    Mar 5th
    28 Files
  • 6
    Mar 6th
    42 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    13 Files
  • 9
    Mar 9th
    0 Files
  • 10
    Mar 10th
    0 Files
  • 11
    Mar 11th
    15 Files
  • 12
    Mar 12th
    19 Files
  • 13
    Mar 13th
    21 Files
  • 14
    Mar 14th
    38 Files
  • 15
    Mar 15th
    15 Files
  • 16
    Mar 16th
    0 Files
  • 17
    Mar 17th
    0 Files
  • 18
    Mar 18th
    10 Files
  • 19
    Mar 19th
    32 Files
  • 20
    Mar 20th
    46 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    13 Files
  • 23
    Mar 23rd
    0 Files
  • 24
    Mar 24th
    0 Files
  • 25
    Mar 25th
    12 Files
  • 26
    Mar 26th
    31 Files
  • 27
    Mar 27th
    19 Files
  • 28
    Mar 28th
    42 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close