extract.c

by Phrack Staff — raw txt

Issue 51 contents
  1. Introduction
  2. Phrack Loopback
  3. Line Noise
  4. Phrack Prophile on Swamp Ratte
  5. File Descriptor Hijacking
  6. LOKI2 (the implementation)
  7. Juggernaut 1.0 - 1.2 patchfile
  8. Shared Library Redirection
  9. Bypassing Integrity Checking Systems
  10. Stealth RPC scanning
  11. The Art of Scanning
  12. The Eternity Service
  13. Monoalphabetic cipher cryptanalysis
  14. Phrack Magazine Article Index Guide
  15. A Brief introduction to CCS7
  16. Phrack World News
  17. extract.c

---[  Phrack Magazine   Volume 7, Issue 51 September 01, 1997, article 17 of 17


-------------------------[  Phrack Magzine Extraction Utility


--------[  Phrack Staff

    This time around, you have the option of using the C version of extract, 
or the PERL version, contributed by Daos.


---------------------8<------------CUT-HERE----------->8---------------------
 
/*  extract.c by Phrack Staff and sirsyko 
 *
 *  (c) Phrack Magazine, 1997 
 *
 *  Extracts textfiles from a specially tagged flatfile into a hierarchical 
 *  directory strcuture. Use to extract source code from any of the articles 
 *  in Phrack Magazine (first appeared in Phrack 50).
 *
 *  gcc -o extract extract.c
 *  
 *  ./extract filename   
 */   

 
#include <stdio.h>
#include <sys/stat.h>
#include <string.h>

int main(int argc, char **argv){ 

    char *s="<++> ",*e="<-->",b[256],*bp; 
    FILE *f,*o = NULL; 
    int l, n, i=0; 

    l = strlen(s); 
    n = strlen(e); 

    if(argc<2) {
        printf("Usage: %s <inputfile>\n",argv[0]);
        exit(1); 
    }

    if(! (f=fopen(argv[1], "r"))) {
        printf("Could not open input file.\n");
	exit(1);
    }

    while(fgets(b, 256, f)){ 

        if(!strncmp (b, s, l)){ 
	    b[strlen(b)-1] = '\0'; 

	    if((bp=strchr(b+l+1,'/')))
	        while (bp){ 
		    *bp='\0';
		    mkdir(b+l, 0700); 
		    *bp='/';
		    bp=strchr(bp+1,'/'); 
		}
	    if((o = fopen(b+l, "w"))) 
	        printf("- Extracting %s\n",b+l);
	    else {
		printf("Could not extract '%s'\n",b+l);
		exit(1);
	    }
	} 
        else if(!strncmp (b, e, n)){
	    if(o) fclose(o);
	    else {
	        printf("Error closing file.\n");
		exit(1);
	    }
        } 
        else if(o) {
            fputs(b, o);
            i++;
        }
    }
    if(!i) printf("No extraction tags found.\n");
    return(0);
}

---------------------8<------------CUT-HERE----------->8---------------------

# Daos <daos@nym.alias.net>

<++> extract.pl
#!/bin/sh -- # -*- perl -*- -n
eval 'exec perl $0 -S ${1+"$@"}' if 0;

$opening=0;

if (/^\<\+\+\>/) {$curfile = substr($_ , 5); $opening=1;};
if (/^\<\-\-\>/) {close ct_ex; $opened=0;}; 
if ($opening) {                        
        chop $curfile;                 
        $sex_dir= substr( $curfile, 0, ((rindex($curfile,'/'))) ) if ($curfile =~ m/\//);
        eval {mkdir $sex_dir, "0777";}; 
        open(ct_ex,">$curfile"); 
        print "Attempting extraction of $curfile\n";
        $opened=1; 
}
if ($opened && !$opening) {print ct_ex $_}; 
<-->

----[  EOF