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

dumpfd.c

dumpfd.c
Posted Apr 9, 2001
Authored by vade79, realhalo | Site realhalo.org

Dumpfd.c dumps all process file descriptors to stdin. Based on dumpenv.c.

systems | unix
SHA-256 | 939194707c511f9499ce67f01c1e9d6b4f813addc5aac44b5612a41d4ed0d8be

dumpfd.c

Change Mirror Download
/* [DUMPFD: system tool -- version 1.1 ] *************************************
* system tool based on dumpenv.c, something made briefly before this. *
* dumps all process file descriptors to stdin. *
* *
* AUTHOR: *
* v9/vade79@realhalo.org, realhalo.org. *
* *
* dumpfd.c: program source code to dumpfd, for linux. (130l!262w!3681b) *
*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <glob.h>
#include <pwd.h>
#include <grp.h>
int total=0;
char id[]="$Id: dumpfd.c,v 1.1 2001/04/05 20:22:21 EST vade79 Exp $";
int main(){
int i=0;
glob_t gb;
setuid(geteuid());
if(getuid())
printe("dumpfd must run as root to process correctly",1);
gb.gl_offs=1;
glob("/proc/*",0,0,&gb);
while(gb.gl_pathc>i){
if(atoi((char *)basename(gb.gl_pathv[i]))
||!strcmp((char *)basename(gb.gl_pathv[i]),"0"))
getfd((char *)basename(gb.gl_pathv[i]));
i++;
}
globfree(&gb);
printf("total fd count: %d.\n",total);
exit(0);
}
int getfd(char *pid){
int i=0;
int chr=0;
char fddir[12+strlen(pid)];
char cmdfile[15+strlen(pid)];
char cmd[256];
char ln[4096];
char filetype[5];
char owner[8];
char group[8];
FILE *fd;
struct stat mod;
struct passwd *pwd;
struct group *grp;
glob_t gbfd;
sprintf(fddir,"/proc/%s/fd/*",pid);
sprintf(cmdfile,"/proc/%s/cmdline",pid);
if(!(fd=fopen(cmdfile,"r")))
printe("command line of the pid doesn't exist or isn't readable",0);
else{
bzero(cmd,sizeof(cmd));
while((chr=fgetc(fd))!=0x0&&chr!=0x20&&chr!=EOF)
if(isprint(chr))
if(i<sizeof(cmd))
cmd[i++]=chr;
}
fclose(fd);
if(!strlen(cmd)){
bzero(cmd,sizeof(cmd));
sprintf(cmd,"UNKNOWN");
}
else
cmd[i]=0x0;
gbfd.gl_offs=1;
switch(glob(fddir,0,0,&gbfd)){
case 1:
printe("getfd(): glob had a memory error",0);
break;
case 2:
printe("getfd(): glob had a read error",0);
break;
}
if(!gbfd.gl_pathc)
printf("*%c%s%c%.7s%c%.7s%c%.7s <no file descriptors currently in use>\n",
0x9,pid,0x9,owner,0x9,group,0x9,basename(cmd));
for(i=0;gbfd.gl_pathc>i;i++){
stat(gbfd.gl_pathv[i],&mod);
if(!(pwd=getpwuid(mod.st_uid)))
sprintf(owner,"%u",mod.st_uid);
else{
if(strlen(pwd->pw_name))
sprintf(owner,"%.7s",pwd->pw_name);
else
sprintf(owner,"%u",pwd->pw_uid);
}
if(!(grp=getgrgid(mod.st_gid)))
sprintf(group,"%u",mod.st_gid);
else{
if(strlen(pwd->pw_name))
sprintf(group,"%.7s",grp->gr_name);
else
sprintf(group,"%u",grp->gr_gid);
}
bzero(ln,sizeof(ln));
if(!readlink(gbfd.gl_pathv[i],ln,sizeof(ln)))
sprintf(ln,"UNKNOWN");
if(S_ISREG(mod.st_mode))
sprintf(filetype,"file");
else if(S_ISLNK(mod.st_mode))
sprintf(filetype,"link");
else if(S_ISDIR(mod.st_mode))
sprintf(filetype,"dir");
else if(S_ISCHR(mod.st_mode))
sprintf(filetype,"cdev");
else if(S_ISBLK(mod.st_mode))
sprintf(filetype,"bdev");
else if(S_ISFIFO(mod.st_mode))
sprintf(filetype,"fifo");
else if(S_ISSOCK(mod.st_mode))
sprintf(filetype,"sock");
else
sprintf(filetype,"none");
total++;
printf("%d%c%s%c%.7s%c%.7s%c%.7s%c%s%c%s%c%.24s\n",total,0x9,pid,0x9,owner,
0x9,group,0x9,basename(cmd),0x9,basename(gbfd.gl_pathv[i]),0x9,filetype,0x9,
strlen(ln)?ln:"UNKNOWN");
}
globfree(&gbfd);
return(0);
}
int printe(char *err,int quit){
printf("error: %s.\n",err);
if(quit)
exit(1);
}
Login or Register to add favorites

File Archive:

April 2024

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