Skip to content

Commit

Permalink
Fixed null packet issue in TCP mode for pcap_next. Disable rp_filter …
Browse files Browse the repository at this point in the history
…now for all interfaces, if enabled. Resolved problems with modern security settings and spoofing.
  • Loading branch information
Markus-Go committed May 21, 2015
1 parent 92933cc commit a9f393f
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/bonesi.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ u_int32_t** srcIpsSpoof;
char** useragents;
int nuseragents = 0;
Url_array urls;
int rp_filter = NULL;
void INThandler(int);

TcpOption tcpOptions[NUM_TCP_OPTIONS];

Expand All @@ -130,6 +132,33 @@ int main(int argc, char *argv[]) {
srand(time(NULL)*getpid());
parseArgs(argc, argv);

char buf[1024];
FILE *f = NULL;
extern int errno;
signal(SIGINT, INThandler);

// we need to disable revesered path, otherwise we cannot spoof
f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "r");
if(!f) {
fprintf(stderr, "Can't open proc file system: %s. Make sure to disable rp_filter manually.\n", strerror( errno ));
}
else {
fgets(buf, 1023, f);
rp_filter = atoi(buf);
fclose(f);
}

if (rp_filter == 1) {
f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "w");
if(!f) {
fprintf(stderr, "Can't open proc file system: %s. Make sure to disable rp_filter manually.\n", strerror( errno ));
}
else {
fprintf(f,"0");
fclose(f);
}
}

char errbuf[LIBNET_ERRBUF_SIZE];
libnet_t *libnetHandle = libnet_init(LIBNET_RAW4, device, errbuf);
if (libnetHandle == NULL) {
Expand Down Expand Up @@ -358,6 +387,17 @@ int main(int argc, char *argv[]) {
if(proto == IPPROTO_TCP) {
pthread_join(pcapThread, NULL);
}
// set rp_filter back to original value ...
if (rp_filter == 1) {
f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "w");
if(!f) {
fprintf(stderr, "Can't open proc file system: %s. Make sure to disable rp_filter manually.\n", strerror( errno ));
}
else {
fprintf(f,"1");
fclose(f);
}
}
return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -629,6 +669,7 @@ void printArgs() {
printf("urls: %s\n", urlfilename);
printf("useragents:: %s\n", useragentfilename);
printf("stats file: %s\n", statsFilename);
printf("device: %s\n", device);
(maxPackets > 0) ? printf("maxPackets: %d\n", maxPackets)
: printf("maxPackets: infinite\n");
printf("format: ");
Expand Down Expand Up @@ -736,6 +777,10 @@ void acknowledge(libnet_t *libnetHandle, pcap_t* pcapHandle) {
//printf("achnowledge\n");
//static size_t x = 0;
sniffedPacket = pcap_next(pcapHandle, &header);
if (!sniffedPacket) {
//fprintf(stderr, "Error sniffing packet: %s\n", pcap_geterr(pcapHandle));
return;
}
ip = (struct iphdr*) (sniffedPacket + sizeof(struct ether_header));
u_int32_t sIp = ip->daddr; //IP we want to send to
tcp = (struct tcphdr*) (sniffedPacket + sizeof(struct ether_header) + sizeof(struct iphdr));
Expand Down Expand Up @@ -1053,3 +1098,22 @@ void sendAck(libnet_t *libnetHandle, const struct iphdr* ip, const struct tcphdr
}
}
}

void INThandler(int sig) {
char buf[1024];
FILE *f = NULL;
extern int errno;

signal(sig, SIG_IGN);
if (rp_filter == 1) {
f = fopen("/proc/sys/net/ipv4/conf/all/rp_filter", "w");
if(!f) {
fprintf(stderr, "Can't open proc file system: %s. Make sure to disable rp_filter manually.\n", strerror( errno ));
}
else {
fprintf(f,"1");
fclose(f);
}
}
exit(EXIT_SUCCESS);
}

0 comments on commit a9f393f

Please sign in to comment.