Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/ipwn/cmd_misc.c
Views: 11766
/*1* Copyright (c) 2004-2005 vlad902 <vlad902 [at] gmail.com>2* This file is part of the Metasploit Framework.3* $Revision$4*/56#include <sys/types.h>7#include <sys/stat.h>8#include <stdlib.h>9#include <unistd.h>10#include <sys/socket.h>11#include <netinet/in.h>12#include <arpa/inet.h>13#include <string.h>14#include <errno.h>15#include <stdio.h>1617#include "cmd.h"181920/* Taken from solar eclipse's vuln.c */21void cmd_lsfd(int argc, char * argv[])22{23int fd;2425for(fd=0; fd <= 1024; fd++)26{27struct stat st;28char perm[10] = "---------";2930if (fstat(fd, &st) == 0)31{32char *type, *p;33char extra[1024];3435memset(extra, 0, sizeof(extra));3637if(S_ISREG(st.st_mode))38type = "file";3940if(S_ISDIR(st.st_mode))41type = "directory";4243if(S_ISCHR(st.st_mode))44{45type = "character";46p = ttyname(fd);47if (p != NULL)48strncpy(extra, p, sizeof(extra));49}5051if(S_ISBLK(st.st_mode))52type = "block";5354if(S_ISFIFO(st.st_mode))55type = "fifo";5657if(S_ISLNK(st.st_mode))58type = "symlink";5960if(S_ISSOCK(st.st_mode))61{62char locip[16], remip[16];63struct sockaddr_in loc, rem;64unsigned int slen = sizeof(struct sockaddr);6566memset(locip, 0, sizeof(locip));67memset(remip, 0, sizeof(remip));6869getsockname(fd, (struct sockaddr *)&loc, &slen);70getpeername(fd, (struct sockaddr *)&rem, &slen);7172strncpy(locip, (char *) inet_ntoa(loc.sin_addr), sizeof(locip));73strncpy(remip, (char *) inet_ntoa(rem.sin_addr), sizeof(remip));7475snprintf(extra, sizeof(extra), "%s:%u -> %s:%u",76locip, ntohs(loc.sin_port),77remip, ntohs(rem.sin_port));7879type = "socket";80}8182if(st.st_mode & S_IRUSR) perm[0] = 'r';83if(st.st_mode & S_IWUSR) perm[1] = 'w';84if(st.st_mode & S_IXUSR) perm[2] = 'x';85if(st.st_mode & S_IRGRP) perm[3] = 'r';86if(st.st_mode & S_IWGRP) perm[4] = 'w';87if(st.st_mode & S_IXGRP) perm[5] = 'x';88if(st.st_mode & S_IROTH) perm[6] = 'r';89if(st.st_mode & S_IWOTH) perm[7] = 'w';90if(st.st_mode & S_IXOTH) perm[8] = 'x';9192printf("[%d] [%s] dev=%d ino=%d uid=%d gid=%d rdev=%d size=%d %s (%s)\n",93fd,94perm,95(int)st.st_dev,96(int)st.st_ino,97st.st_uid,98st.st_gid,99(int)st.st_rdev,100(int)st.st_size,101type,102extra);103}104}105}106107108