Skip to main content

Create a custom linux shell with limited customized commands

Here is a c Program I have tried to create  a custom shell in linux with limited commands


#include
#include
#include
#include
#include
using namespace std;

int main(int argc, char * argv[])
{
  string command;
cout << "\t This is a custom developed shell \n\n";
while (command != "myexit")
{

if ( command == "myexit")
system("exit");
else if ( command == "myfinger" )
{
char username[40];
char buf[32];
printf ("Enter the username:\n");
scanf ("%s",&username);
sprintf(buf, "finger %s", username);
system (buf);
}
else if ( command == "mydel" )
{
char filename[40];
char cmd1[40];
printf ("Enter the filename to delete:\n");
scanf ("%s",&filename);
sprintf(cmd1, "rm -rf %s", filename);
system (cmd1);
printf ("The file %s deleted \n", filename);
}
else if ( command == "mywhich" )
{
char cmmnd[40];
char cmd2[40];
printf ("Enter the command:\n");
scanf ("%s",&cmmnd);
sprintf(cmd2, "which %s", cmmnd);
system (cmd2);
}
else if ( command == "mycp" )
{
char target1[30];
char target2[30];
char cmd3[30];
printf ("Enter the source and then destination:\n");
scanf ("%s %s", &target1,&target2);
sprintf(cmd3, "cp %s %s", target1,target2);
system (cmd3);
}
else if ( command == "myhelp" )
cout << "\n Available options \n 1)mydel \n 2)myfinger \n 3)mywhich \n 4)mycp \n 5)myhelp \n \n";
else if ( command != "\0")
cout << "command not found \n";

cout << "myprompt >";
cin >> command;
}
return 0;

}
 



save this to a file... g++ filename.cpp -o filename

Comments

Popular posts from this blog

Modsecurity block rule for XMLRPC and wp-login attack

SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000134  <Locationmatch "/wp-login.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000135,msg:'ip address blocked for 5 minutes, more than 10 login attempts in 3 minutes.'"  SecRule RESPONSE_STATUS "^302" "phase:5,t:none,nolog,pass,setvar:ip.bf_counter=0,id:5000136"  SecRule RESPONSE_STATUS "^200" "phase:5,chain,t:none,nolog,pass,setvar:ip.bf_counter=+1,deprecatevar:ip.bf_counter=1/180,id:5000137"  SecRule ip:bf_counter "@gt 10" "t:none,setvar:user.bf_block=1,expirevar:user.bf_block=300,setvar:ip.bf_counter=0"  </Locationmatch>  SecAction phase:1,nolog,pass,initcol:ip=%{REMOTE_ADDR},initcol:user=%{REMOTE_ADDR},id:5000234  <Locationmatch "/xmlrpc.php">  SecRule user:bf_block "@gt 0" "deny,status:401,log,id:5000235,msg:'ip address blocked for 5 m...

Apache tuning documentation

Apache bench marking ======================= Things or checklist to be considered before the test     CPU: avoid power-saving mode. cpufreq-set -g performance.     File descriptors: raise the limit to (at least) the number of concurrent connections you wish to handle, using ulimit -n in your shell, or setrlimit(RLIMIT_NOFILE) in your server. Beware, some systems forbid you to raise the limit, you might need to investigate a bit to find how to unlock it.     Disable the logs of your server (you do not want to lose time logging thousands of requests instead of answering them).     Raise /proc/sys/net/somaxconn to the number of concurrent connections you want to handle. To understand why this is necessary, read the technical report or the excellent paper Measuring the Capacity of a Web Server (Banga and Druschel, Usenix 97). More on the fascinating topic of the accept() queue can be found in accept()able Strategies for Im...

Fix the permission and ownership

Usage ./scripts user1 user2 user3 You can also run a server-wide loop like this: for i in `ls -A /var/cpanel/users` ; do ./scripts $i ; done  code =========== #!/bin/bash if [ "$#" -lt "1" ];then echo "Must specify user" exit; fi USER=$@ for user in $USER do HOMEDIR=$(egrep "^${user}:" /etc/passwd | cut -d: -f6) if [ ! -f /var/cpanel/users/$user ]; then echo "$user user file missing, likely an invalid user" elif [ "$HOMEDIR" == "" ];then echo "Couldn't determine home directory for $user" else echo "Setting ownership for user $user" chown -R $user:$user $HOMEDIR chmod 711 $HOMEDIR chown $user:nobody $HOMEDIR/public_html $HOMEDIR/.htpasswds chown $user:mail $HOMEDIR/etc $HOMEDIR/etc/*/shadow $HOMEDIR/etc/*/passwd echo "Setting permissions for user $USER" find $HOMEDIR -type f -exec chmod 644 {} \; -print find $HOMEDIR -type d -exec chmod 755 {} \; -print find $HOMEDIR ...