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:

November 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close