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_base.c
Views: 11766
/*1* Copyright (c) 2004-2005 vlad902 <vlad902 [at] gmail.com>2* Copyright (c) 2007 H D Moore <hdm [at] metasploit.com>3* This file is part of the Metasploit Framework.4* $Revision$5*/67#include <sys/types.h>8#include <sys/wait.h>9#include <stdlib.h>10#include <unistd.h>11#include <string.h>12#include <errno.h>13#include <signal.h>14#include <stdio.h>15#include <string.h>1617#include "cmd.h"181920void cmd_help(int argc, char * argv[])21{22printf( "Available commands:\n"23" help Show this help screen\n"24" fork Fork off another shelldemo process\n"25" exec <cmd> Execute <cmd>\n"26" system <cmd> Fork and execute <cmd> on std(in/out/err)\n"27" quit Exit the shell\n"2829"\n"30" open <path> Open a file and return the file descriptor\n"31" lseek <fd> <offset> <whence> Reposition <fd>\n"32" read <fd> [bytes] Read <bytes> from file descriptor\n"33" write <fd> [bytes] Write [bytes] (or until \"EOF\") to <fd>\n"34" close <fd> Close specified file descriptor\n"35" dup <old_fd> Duplicate <old_fd> and return new reference\n"36" dup2 <old_fd> <new_fd> Duplicate <old_fd> to <new_fd>\n"3738"\n"39" ls [path] Print information/contents about [path] (default: .)\n"40" getcwd Get current working directory\n"41" pwd Get current working directory\n"42" cd Set current working directory\n"43" chmod <permission> <path> Change <path> permissions to <permission>\n"44" chown <user> <path> Change <path> owner to <user>\n"45" chgrp <group> <path> Change <path> group to <group>\n"46" chdir <path> Change working directory to <path>\n"47" mkdir <path> [permission] Create <path> directory with [permission] (default: 755)\n"48" rmdir <path> Remove <path> directory\n"49" rename <old_file> <new_file> Rename <old_file> to <new_file>\n"50" unlink <path> Remove <path> file\n"51" chroot <path> Change root directory to <path>\n"52" link <file> <reference> Hard link <reference> to <file>\n"53" symlink <file> <reference> Symbolically link <reference> to <file>\n"54" cp <file> <file> Copy a file from one directory to another\n"5556"\n"57" getid Print information about [e][ug]id\n"58" setuid <uid> Set UID to <uid>\n"59" setgid <gid> Set GID to <gid>\n"6061"\n"62" kill <pid> [signal] Send <pid> [signal] (default: 9)\n"63" getpid Print current process ID\n"64" getppid Print parent process ID\n"65" ps Print process list\n"6667"\n"68" time Display the current system time\n"69" uname Get kernel information\n"70" hostname [name] Print (or set) the hostname\n"71" reboot Reboot the computer\n"72" shutdown Shutdown the computer\n"73" halt Halt the computer\n"7475"\n"76" lsfd Show information about open file descriptors\n"7778"\n"79" download <url> <file> Download a file to disk over HTTP\n"8081"\n"82"Warning! Before using any of the following you are recommended to fork for your own safety!\n"83" fchdir_breakchroot <temp_dir> Use <temp_dir> to attempt to break out of chroot\n");84}858687/* XXX: sig_chld stuff is dirty, get rid of it */88void cmd_fork(int argc, char * argv[])89{90pid_t fork_pid;9192signal(SIGCHLD, &sig_chld_ignore);93if((fork_pid = fork()) != 0)94{95while(waitpid(fork_pid, NULL, WNOHANG) <= 0)96usleep(300);97}98signal(SIGCHLD, &sig_chld_waitpid);99}100101void cmd_exec(int argc, char * argv[])102{103int i;104char *prog;105106argv++;107108prog = argv[0];109110printf("Executing");111for(i=0; argv[i]; i++) {112printf(" %s", argv[i]);113}114printf("\n");115116execve(prog, argv, NULL);117perror("execve");118}119120void cmd_system(int argc, char * argv[])121{122pid_t fork_pid;123124signal(SIGCHLD, &sig_chld_ignore);125if((fork_pid = fork()) != 0)126{127while(waitpid(fork_pid, NULL, WNOHANG) <= 0)128usleep(300);129} else {130cmd_exec(argc, argv);131exit(0);132}133signal(SIGCHLD, &sig_chld_waitpid);134}135136void cmd_quit(int argc, char * argv[])137{138exit(0);139}140141142void cmd_script(int argc, char * argv[])143{144FILE *fd;145char buff[2048];146147fd = fopen(argv[1], "r");148if (fd == NULL) {149perror("fopen");150return;151}152153printf("Executing script %s\n", argv[1]);154while (fgets(buff, sizeof(buff), fd)) {155chomp(buff);156process_input(buff, sizeof(buff));157}158159fclose(fd);160}161162163164