what you don't know can hurt you
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:

July 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jul 1st
    27 Files
  • 2
    Jul 2nd
    10 Files
  • 3
    Jul 3rd
    35 Files
  • 4
    Jul 4th
    27 Files
  • 5
    Jul 5th
    18 Files
  • 6
    Jul 6th
    0 Files
  • 7
    Jul 7th
    0 Files
  • 8
    Jul 8th
    28 Files
  • 9
    Jul 9th
    44 Files
  • 10
    Jul 10th
    24 Files
  • 11
    Jul 11th
    25 Files
  • 12
    Jul 12th
    11 Files
  • 13
    Jul 13th
    0 Files
  • 14
    Jul 14th
    0 Files
  • 15
    Jul 15th
    0 Files
  • 16
    Jul 16th
    0 Files
  • 17
    Jul 17th
    0 Files
  • 18
    Jul 18th
    0 Files
  • 19
    Jul 19th
    0 Files
  • 20
    Jul 20th
    0 Files
  • 21
    Jul 21st
    0 Files
  • 22
    Jul 22nd
    0 Files
  • 23
    Jul 23rd
    0 Files
  • 24
    Jul 24th
    0 Files
  • 25
    Jul 25th
    0 Files
  • 26
    Jul 26th
    0 Files
  • 27
    Jul 27th
    0 Files
  • 28
    Jul 28th
    0 Files
  • 29
    Jul 29th
    0 Files
  • 30
    Jul 30th
    0 Files
  • 31
    Jul 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