initial commit
This commit is contained in:
commit
6a18c72b0c
7
ChangeLog
Normal file
7
ChangeLog
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
0.2:
|
||||||
|
* Added auto-daemonize.
|
||||||
|
* Fixed lame getopt bug.
|
||||||
|
* Switched to autoconf project.
|
||||||
|
|
||||||
|
0.1:
|
||||||
|
Initial Version
|
54
INSTALL
Normal file
54
INSTALL
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
-- fakeroute v0.2 --
|
||||||
|
|
||||||
|
Install Instructions:
|
||||||
|
|
||||||
|
tar zxvf fakeroute-0.2.tar.gz
|
||||||
|
cd fakeroute-0.2
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
To use fakeroute, you must define a route file with your fake route. The file
|
||||||
|
should be a newline separated list of dotted quad IP addresses with your IP
|
||||||
|
address last. For example, 10.0.0.34 could have a route.conf that looks like:
|
||||||
|
|
||||||
|
216.102.187.130
|
||||||
|
165.87.161.74
|
||||||
|
4.24.4.146
|
||||||
|
4.0.1.122
|
||||||
|
198.137.241.43
|
||||||
|
198.116.142.34
|
||||||
|
63.199.8.242
|
||||||
|
|
||||||
|
...be careful not to include any leading or trailing blank newlines.
|
||||||
|
Optionally, you could include any IP address last that you wish to be the
|
||||||
|
destination of the remote traceroute. The above route will stop at:
|
||||||
|
"adsl-63-199-8-242.carcionelaw.com" as if it were the traceroute destination:
|
||||||
|
|
||||||
|
traceroute to localhost (127.0.0.1), 30 hops max, 40 byte packets
|
||||||
|
1 core4-g3-0.snfc21.pbi.net (216.102.187.130) 0.324 ms 0.247 ms 0.162 ms
|
||||||
|
2 sfra1sr3-so-1-1-1-0.ca.us.prserv.net (165.87.161.74) 0.164 ms 0.265 ms 0.159 ms
|
||||||
|
3 p3-0.washdc3-br2.bbnplanet.net (4.24.4.146) 0.166 ms 0.219 ms 0.156 ms
|
||||||
|
4 p5-0.vienna1-nbr2.bbnplanet.net (4.0.1.122) 0.162 ms 0.243 ms 0.170 ms
|
||||||
|
5 wh243.eop.gov (198.137.241.43) 0.162 ms 0.255 ms 0.159 ms
|
||||||
|
6 foundation.hq.nasa.gov (198.116.142.34) 0.168 ms 0.281 ms 0.164 ms
|
||||||
|
7 adsl-63-199-8-242.carcionelaw.com (63.199.8.242) 0.182 ms 0.240 ms 0.156 ms
|
||||||
|
|
||||||
|
|
||||||
|
To run, become root, and simply execute "fakeroute -f <route_file>".
|
||||||
|
|
||||||
|
To test your configuration, just traceroute to localhost.
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
|
||||||
|
Currently, fakeroute only works for UDP-based (ie: default unix) traceroute.
|
||||||
|
It does not work for unix traceroute with the -I option, or windows tracert.
|
||||||
|
Hopefully support for ICMP-based traceroute will come in a later version.
|
||||||
|
|
||||||
|
If you have any questions, comments, or problems, you can send email to:
|
||||||
|
|
||||||
|
moxie@thoughtcrime.org
|
||||||
|
|
||||||
|
|
2
Makefile.am
Normal file
2
Makefile.am
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
SUBDIRS = src
|
||||||
|
EXTRA_DIST = example-route.conf
|
54
README
Normal file
54
README
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
-- fakeroute v0.2 --
|
||||||
|
|
||||||
|
Install Instructions:
|
||||||
|
|
||||||
|
tar zxvf fakeroute-0.2.tar.gz
|
||||||
|
cd fakeroute-0.2
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
make install
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
To use fakeroute, you must define a route file with your fake route. The file
|
||||||
|
should be a newline separated list of dotted quad IP addresses with your IP
|
||||||
|
address last. For example, 10.0.0.34 could have a route.conf that looks like:
|
||||||
|
|
||||||
|
216.102.187.130
|
||||||
|
165.87.161.74
|
||||||
|
4.24.4.146
|
||||||
|
4.0.1.122
|
||||||
|
198.137.241.43
|
||||||
|
198.116.142.34
|
||||||
|
63.199.8.242
|
||||||
|
|
||||||
|
...be careful not to include any leading or trailing blank newlines.
|
||||||
|
Optionally, you could include any IP address last that you wish to be the
|
||||||
|
destination of the remote traceroute. The above route will stop at:
|
||||||
|
"adsl-63-199-8-242.carcionelaw.com" as if it were the traceroute destination:
|
||||||
|
|
||||||
|
traceroute to localhost (127.0.0.1), 30 hops max, 40 byte packets
|
||||||
|
1 core4-g3-0.snfc21.pbi.net (216.102.187.130) 0.324 ms 0.247 ms 0.162 ms
|
||||||
|
2 sfra1sr3-so-1-1-1-0.ca.us.prserv.net (165.87.161.74) 0.164 ms 0.265 ms 0.159 ms
|
||||||
|
3 p3-0.washdc3-br2.bbnplanet.net (4.24.4.146) 0.166 ms 0.219 ms 0.156 ms
|
||||||
|
4 p5-0.vienna1-nbr2.bbnplanet.net (4.0.1.122) 0.162 ms 0.243 ms 0.170 ms
|
||||||
|
5 wh243.eop.gov (198.137.241.43) 0.162 ms 0.255 ms 0.159 ms
|
||||||
|
6 foundation.hq.nasa.gov (198.116.142.34) 0.168 ms 0.281 ms 0.164 ms
|
||||||
|
7 adsl-63-199-8-242.carcionelaw.com (63.199.8.242) 0.182 ms 0.240 ms 0.156 ms
|
||||||
|
|
||||||
|
|
||||||
|
To run, become root, and simply execute "fakeroute -f <route_file>".
|
||||||
|
|
||||||
|
To test your configuration, just traceroute to localhost.
|
||||||
|
|
||||||
|
Bugs:
|
||||||
|
|
||||||
|
Currently, fakeroute only works for UDP-based (ie: default unix) traceroute.
|
||||||
|
It does not work for unix traceroute with the -I option, or windows tracert.
|
||||||
|
Hopefully support for ICMP-based traceroute will come in a later version.
|
||||||
|
|
||||||
|
If you have any questions, comments, or problems, you can send email to:
|
||||||
|
|
||||||
|
moxie@thoughtcrime.org
|
||||||
|
|
||||||
|
|
13
configure.ac
Normal file
13
configure.ac
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
ss this file with autoconf to produce a configure script.
|
||||||
|
AC_INIT(src/Fakeroute.cpp)
|
||||||
|
|
||||||
|
dnl Setup for automake
|
||||||
|
AM_INIT_AUTOMAKE(fakeroute, 0.2)
|
||||||
|
|
||||||
|
dnl Check for tools
|
||||||
|
AC_PROG_CC
|
||||||
|
AC_PROG_CXX
|
||||||
|
AC_PROG_INSTALL
|
||||||
|
|
||||||
|
# Finally create all the generated files
|
||||||
|
AC_OUTPUT(Makefile src/Makefile)
|
7
example-route.conf
Normal file
7
example-route.conf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
216.102.187.130
|
||||||
|
165.87.161.74
|
||||||
|
4.24.4.146
|
||||||
|
4.0.1.122
|
||||||
|
198.137.241.43
|
||||||
|
198.116.142.34
|
||||||
|
63.199.8.242
|
128
src/ConnectionManager.cpp
Normal file
128
src/ConnectionManager.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ConnectionManager.h"
|
||||||
|
#include "DestHostUnreachableFakeroutePacket.h"
|
||||||
|
#include "TimeToLiveExpiredFakeroutePacket.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
ConnectionManager::ConnectionManager(char* routeFile) : ENTRY_LIMIT(2) {
|
||||||
|
head = NULL;
|
||||||
|
tail = NULL;
|
||||||
|
|
||||||
|
routeCount = 0;
|
||||||
|
entryCount = 0;
|
||||||
|
|
||||||
|
loadRoutePath(routeFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
class FakeroutePacket* ConnectionManager::getPacketFor(char* sourceAddress, char* destinationAddress,
|
||||||
|
u_int16_t sourcePort, u_int16_t destinationPort)
|
||||||
|
{
|
||||||
|
class SourceIpEntry *entry = findEntryFor(sourceAddress);
|
||||||
|
char *sourceIp = getIpForHop((*entry).getTtl()/3);
|
||||||
|
|
||||||
|
class FakeroutePacket *spoofedPacket;
|
||||||
|
|
||||||
|
if (isTransitHop((*entry).getTtl()/3)) {
|
||||||
|
spoofedPacket = new TimeToLiveExpiredFakeroutePacket(sourcePort, destinationPort,
|
||||||
|
sourceIp, destinationAddress);
|
||||||
|
} else {
|
||||||
|
spoofedPacket = new DestHostUnreachableFakeroutePacket(sourcePort, destinationPort,
|
||||||
|
sourceIp, destinationAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
(*entry).incrementTtl(routeCount * 3);
|
||||||
|
|
||||||
|
return spoofedPacket;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SourceIpEntry* ConnectionManager::findEntryFor(char* sourceAddress) {
|
||||||
|
class SourceIpEntry *current;
|
||||||
|
|
||||||
|
for (current = head; current != NULL; current = (*current).getNext()) {
|
||||||
|
if (strcmp((*current).getSourceIp(), sourceAddress) == 0) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tail == NULL) {
|
||||||
|
head = tail = new SourceIpEntry(sourceAddress);
|
||||||
|
} else {
|
||||||
|
(*tail).setNext(new SourceIpEntry(sourceAddress));
|
||||||
|
tail = (*tail).getNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (++entryCount > ENTRY_LIMIT) {
|
||||||
|
releaseHeadNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
return tail;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionManager::releaseHeadNode(void) {
|
||||||
|
class SourceIpEntry *tmp = (*head).getNext();
|
||||||
|
delete head;
|
||||||
|
|
||||||
|
head = tmp;
|
||||||
|
entryCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConnectionManager::isTransitHop(u_int16_t hop) {
|
||||||
|
return (hop < routeCount -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* ConnectionManager::getIpForHop(u_int16_t hop) {
|
||||||
|
if (hop < routeCount-1) {
|
||||||
|
return routePath[hop];
|
||||||
|
} else {
|
||||||
|
return routePath[routeCount-1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConnectionManager::loadRoutePath(const char* routeFile) {
|
||||||
|
FILE *configFile;
|
||||||
|
char line[1024];
|
||||||
|
|
||||||
|
routePath = (char**)malloc(30 * sizeof(char*));
|
||||||
|
configFile = fopen(routeFile, "r");
|
||||||
|
|
||||||
|
if (configFile == NULL) {
|
||||||
|
fprintf(stderr, "ERROR: Specified route file does not exist, or no route file\nwas specified and default route.conf does not exist.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((fgets((char*)line, 1024, configFile)) != NULL) {
|
||||||
|
routePath[routeCount] = strdup((char*)line);
|
||||||
|
routeCount++;
|
||||||
|
}
|
||||||
|
}
|
62
src/ConnectionManager.h
Normal file
62
src/ConnectionManager.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONNECTION_MANAGER_H
|
||||||
|
#define CONNECTION_MANAGER_H
|
||||||
|
|
||||||
|
#include "SourceIpEntry.h"
|
||||||
|
#include "FakeroutePacket.h"
|
||||||
|
|
||||||
|
class ConnectionManager {
|
||||||
|
|
||||||
|
private:
|
||||||
|
const u_int16_t ENTRY_LIMIT;
|
||||||
|
|
||||||
|
class SourceIpEntry *head;
|
||||||
|
class SourceIpEntry *tail;
|
||||||
|
|
||||||
|
char** routePath;
|
||||||
|
|
||||||
|
u_int16_t routeCount;
|
||||||
|
u_int16_t entryCount;
|
||||||
|
|
||||||
|
class SourceIpEntry* findEntryFor(char* sourceAddress);
|
||||||
|
void loadRoutePath(const char* routePath);
|
||||||
|
void releaseHeadNode(void);
|
||||||
|
char* getIpForHop(u_int16_t hop);
|
||||||
|
int isTransitHop(u_int16_t hop);
|
||||||
|
|
||||||
|
public:
|
||||||
|
ConnectionManager(char* routeFile);
|
||||||
|
class FakeroutePacket* getPacketFor(char* sourceAddress, char* destinationAddress,
|
||||||
|
u_int16_t sourcePort, u_int16_t destinatonPort);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
47
src/DestHostUnreachableFakeroutePacket.cpp
Normal file
47
src/DestHostUnreachableFakeroutePacket.cpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DestHostUnreachableFakeroutePacket.h"
|
||||||
|
#include <netinet/ip_icmp.h>
|
||||||
|
|
||||||
|
DestHostUnreachableFakeroutePacket::DestHostUnreachableFakeroutePacket(u_int16_t localReceivedSourcePort,
|
||||||
|
u_int16_t localReceivedDestinationPort,
|
||||||
|
char* localSpoofedSourceAddress,
|
||||||
|
char* localSpoofedDestinationAddress) :
|
||||||
|
FakeroutePacket(localReceivedSourcePort, localReceivedDestinationPort,
|
||||||
|
localSpoofedSourceAddress, localSpoofedDestinationAddress)
|
||||||
|
{}
|
||||||
|
|
||||||
|
u_int16_t DestHostUnreachableFakeroutePacket::getIcmpType(void) {
|
||||||
|
return ICMP_UNREACH;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int16_t DestHostUnreachableFakeroutePacket::getIcmpCode(void) {
|
||||||
|
return ICMP_UNREACH_PORT;
|
||||||
|
}
|
47
src/DestHostUnreachableFakeroutePacket.h
Normal file
47
src/DestHostUnreachableFakeroutePacket.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DEST_HOST_UNREACHABLE_FAKEROUTE_PACKET_H
|
||||||
|
#define DEST_HOST_UNREACHABLE_FAKEROUTE_PACKET_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "FakeroutePacket.h"
|
||||||
|
|
||||||
|
class DestHostUnreachableFakeroutePacket : public FakeroutePacket {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
u_int16_t getIcmpType(void);
|
||||||
|
u_int16_t getIcmpCode(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
DestHostUnreachableFakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort,
|
||||||
|
char* spoofedSourceAddress, char* spoofedDestinationAddress);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
123
src/Fakeroute.cpp
Normal file
123
src/Fakeroute.cpp
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "TracerouteListener.h"
|
||||||
|
#include "TracerouteEvents.h"
|
||||||
|
#include "TracerouteReader.h"
|
||||||
|
#include "TraceroutePacket.h"
|
||||||
|
#include "ConnectionManager.h"
|
||||||
|
#include "FakeroutePacket.h"
|
||||||
|
|
||||||
|
void start(char*);
|
||||||
|
void printUsage(char*);
|
||||||
|
static void daemonize();
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
char* fileName = "route.conf";
|
||||||
|
int op;
|
||||||
|
|
||||||
|
if (getuid()) {
|
||||||
|
fprintf(stderr, "Must be root to run fakeroute.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((op = getopt(argc, argv, "hf:")) != -1) {
|
||||||
|
switch (op) {
|
||||||
|
case 'h':
|
||||||
|
printUsage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
case 'f':
|
||||||
|
fileName = optarg;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printUsage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
daemonize();
|
||||||
|
start(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printUsage(char* name) {
|
||||||
|
printf("Usage: %s [options]\n", name);
|
||||||
|
printf(" -h\t\tPrint Help (This)\n");
|
||||||
|
printf(" -f <fileName>\tLoad fake route information from\n\t\t<fileName> rather than route.conf\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void start(char* routeFile) {
|
||||||
|
int* fds;
|
||||||
|
int fdCount, i;
|
||||||
|
|
||||||
|
class TracerouteListener listener;
|
||||||
|
class TracerouteReader reader;
|
||||||
|
class ConnectionManager manager(routeFile);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
class TracerouteEvents events;
|
||||||
|
|
||||||
|
listener.listen(events);
|
||||||
|
|
||||||
|
fds = events.getActiveFds();
|
||||||
|
fdCount = events.getActiveFdCount();
|
||||||
|
|
||||||
|
for (i=0;i<fdCount;i++) {
|
||||||
|
class TraceroutePacket *traceroutePacket;
|
||||||
|
class FakeroutePacket *fakeroutePacket;
|
||||||
|
|
||||||
|
traceroutePacket = reader.readPacket(fds[i]);
|
||||||
|
fakeroutePacket = manager.getPacketFor((*traceroutePacket).getSourceAddress(),
|
||||||
|
(*traceroutePacket).getDestinationAddress(),
|
||||||
|
(*traceroutePacket).getSourcePort(),
|
||||||
|
(*traceroutePacket).getDestinationPort());
|
||||||
|
|
||||||
|
(*fakeroutePacket).sendOn(fds[i]);
|
||||||
|
|
||||||
|
delete fakeroutePacket;
|
||||||
|
delete traceroutePacket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void daemonize() {
|
||||||
|
switch (fork()) {
|
||||||
|
case -1:
|
||||||
|
perror("fork failed");
|
||||||
|
exit(1);
|
||||||
|
case 0:
|
||||||
|
if (setsid() == -1) exit(4);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
133
src/FakeroutePacket.cpp
Normal file
133
src/FakeroutePacket.cpp
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FakeroutePacket.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <netinet/ip.h>
|
||||||
|
#include <netinet/ip_icmp.h>
|
||||||
|
#include <netinet/udp.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "in_cksum.h"
|
||||||
|
|
||||||
|
FakeroutePacket::FakeroutePacket(u_int16_t localReceivedSourcePort,
|
||||||
|
u_int16_t localReceivedDestinationPort,
|
||||||
|
char* localSpoofedSourceAddress,
|
||||||
|
char* localSpoofedDestinationAddress) :
|
||||||
|
ICMP_HDR_SIZE(sizeof(struct icmp)),
|
||||||
|
IP_HDR_SIZE(sizeof(struct iphdr)),
|
||||||
|
UDP_HDR_SIZE(sizeof(struct udphdr))
|
||||||
|
{
|
||||||
|
receivedSourcePort = localReceivedSourcePort;
|
||||||
|
receivedDestinationPort = localReceivedDestinationPort;
|
||||||
|
spoofedSourceAddress = localSpoofedSourceAddress;
|
||||||
|
spoofedDestinationAddress = localSpoofedDestinationAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeroutePacket::sendOn(int fd) {
|
||||||
|
|
||||||
|
int sockfd;
|
||||||
|
int one = 1;
|
||||||
|
|
||||||
|
struct sockaddr_in packetTo;
|
||||||
|
unsigned char packet[IP_HDR_SIZE + ICMP_HDR_SIZE + UDP_HDR_SIZE];
|
||||||
|
|
||||||
|
memset((void*)packet, 0, sizeof(packet));
|
||||||
|
memset((void*)&packetTo, 0, sizeof(packetTo));
|
||||||
|
|
||||||
|
if ((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
|
||||||
|
fprintf(stderr, "Error Creating Raw Socket.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, (char*)&one, sizeof(one)) < 0) {
|
||||||
|
fprintf(stderr, "Error Setting Raw Socket Socket Option.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
packetTo.sin_family = AF_INET;
|
||||||
|
packetTo.sin_addr.s_addr = inet_addr(spoofedDestinationAddress);
|
||||||
|
|
||||||
|
buildIpHeader(spoofedSourceAddress, spoofedDestinationAddress, (char*)packet);
|
||||||
|
buildIcmpHeader((char*)(packet + IP_HDR_SIZE), IPPROTO_UDP);
|
||||||
|
buildUdpHeader((char*)(packet + IP_HDR_SIZE + ICMP_HDR_SIZE),
|
||||||
|
receivedSourcePort, receivedDestinationPort);
|
||||||
|
|
||||||
|
if (sendto(sockfd, packet, sizeof(packet), 0x0, (struct sockaddr*)&packetTo, sizeof(packetTo)) < 0) {
|
||||||
|
fprintf(stderr, "Packet Send Failed.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeroutePacket::buildUdpHeader(char* packet, u_int16_t sourcePort,
|
||||||
|
u_int16_t destinationPort)
|
||||||
|
{
|
||||||
|
struct udphdr* udphdr = (struct udphdr*)packet;
|
||||||
|
|
||||||
|
udphdr->source = htons(sourcePort);
|
||||||
|
udphdr->dest = htons(destinationPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeroutePacket::buildIcmpHeader(char* packet, int protocol) {
|
||||||
|
struct iphdr *fakeIpHdr;
|
||||||
|
struct icmp *icmpHeader = (struct icmp*)packet;
|
||||||
|
|
||||||
|
char fakePacket[IP_HDR_SIZE];
|
||||||
|
fakeIpHdr = (struct iphdr*)fakePacket;
|
||||||
|
fakeIpHdr->ihl = 5;
|
||||||
|
fakeIpHdr->version = 4;
|
||||||
|
fakeIpHdr->protocol = protocol;
|
||||||
|
|
||||||
|
icmpHeader->icmp_type = getIcmpType();
|
||||||
|
icmpHeader->icmp_code = getIcmpCode();
|
||||||
|
icmpHeader->icmp_ip = *(struct ip*)fakePacket;
|
||||||
|
icmpHeader->icmp_cksum = (int)in_cksum((unsigned short*)icmpHeader, ICMP_HDR_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FakeroutePacket::buildIpHeader(char* source, char* destination, char* packet) {
|
||||||
|
struct iphdr *ipHeader;
|
||||||
|
|
||||||
|
ipHeader = (struct iphdr*)packet;
|
||||||
|
ipHeader->ihl = 5;
|
||||||
|
ipHeader->version = 4;
|
||||||
|
ipHeader->tot_len = htons(IP_HDR_SIZE + ICMP_HDR_SIZE);
|
||||||
|
ipHeader->id = 31337;
|
||||||
|
ipHeader->ttl = 60;
|
||||||
|
ipHeader->protocol = IPPROTO_ICMP;
|
||||||
|
ipHeader->saddr = inet_addr(source);
|
||||||
|
ipHeader->daddr = inet_addr(destination);
|
||||||
|
ipHeader->check = (unsigned short)in_cksum((unsigned short*)ipHeader, IP_HDR_SIZE);
|
||||||
|
}
|
61
src/FakeroutePacket.h
Normal file
61
src/FakeroutePacket.h
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FAKEROUTE_PACKET_H
|
||||||
|
#define FAKEROUTE_PACKET_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
class FakeroutePacket {
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int ICMP_HDR_SIZE;
|
||||||
|
const int IP_HDR_SIZE;
|
||||||
|
const int UDP_HDR_SIZE;
|
||||||
|
|
||||||
|
u_int16_t receivedSourcePort;
|
||||||
|
u_int16_t receivedDestinationPort;
|
||||||
|
char* spoofedSourceAddress;
|
||||||
|
char* spoofedDestinationAddress;
|
||||||
|
|
||||||
|
virtual void buildUdpHeader(char* packet, u_int16_t sourcePort, u_int16_t destinationPort);
|
||||||
|
virtual void buildIcmpHeader(char* packet, int protocol);
|
||||||
|
virtual void buildIpHeader(char* source, char* destination, char* packet);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual u_int16_t getIcmpType(void) = 0;
|
||||||
|
virtual u_int16_t getIcmpCode(void) = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
FakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort,
|
||||||
|
char* spoofedSourceAddress, char* spoofedDestinationAddress);
|
||||||
|
virtual void sendOn(int fd);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
5
src/Makefile.am
Normal file
5
src/Makefile.am
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
AM_CFLAGS = -ggdb -Wall
|
||||||
|
AM_CXXFLAGS = -ggdb -Wall
|
||||||
|
|
||||||
|
bin_PROGRAMS = fakeroute
|
||||||
|
fakeroute_SOURCES = TracerouteListener.cpp TracerouteListener.h Fakeroute.cpp TracerouteEvents.cpp TracerouteEvents.h TraceroutePacket.cpp TraceroutePacket.h TracerouteReader.cpp TracerouteReader.h FakeroutePacket.cpp FakeroutePacket.h ConnectionManager.cpp ConnectionManager.h SourceIpEntry.cpp SourceIpEntry.h TimeToLiveExpiredFakeroutePacket.cpp TimeToLiveExpiredFakeroutePacket.h DestHostUnreachableFakeroutePacket.cpp DestHostUnreachableFakeroutePacket.h in_cksum.cpp in_cksum.h
|
64
src/SourceIpEntry.cpp
Normal file
64
src/SourceIpEntry.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SourceIpEntry.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
SourceIpEntry::SourceIpEntry(char* localSourceIp) {
|
||||||
|
sourceIp = strdup(localSourceIp);
|
||||||
|
ttl = 0;
|
||||||
|
next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceIpEntry::~SourceIpEntry() {
|
||||||
|
free(sourceIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* SourceIpEntry::getSourceIp() {
|
||||||
|
return sourceIp;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int16_t SourceIpEntry::getTtl() {
|
||||||
|
return ttl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceIpEntry::incrementTtl(int modValue) {
|
||||||
|
ttl = (ttl + 1) % modValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourceIpEntry::setNext(class SourceIpEntry *localNext) {
|
||||||
|
next = localNext;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SourceIpEntry* SourceIpEntry::getNext(void) {
|
||||||
|
return next;
|
||||||
|
}
|
52
src/SourceIpEntry.h
Normal file
52
src/SourceIpEntry.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SOURCE_IP_ENTRY_H
|
||||||
|
#define SOURCE_IP_ENTRY_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
class SourceIpEntry {
|
||||||
|
|
||||||
|
private:
|
||||||
|
char* sourceIp;
|
||||||
|
u_int16_t ttl;
|
||||||
|
class SourceIpEntry *next;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SourceIpEntry(char* localSourceIp);
|
||||||
|
~SourceIpEntry(void);
|
||||||
|
char* getSourceIp();
|
||||||
|
u_int16_t getTtl();
|
||||||
|
void incrementTtl(int modValue);
|
||||||
|
void setNext(class SourceIpEntry *next);
|
||||||
|
class SourceIpEntry* getNext(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
48
src/TimeToLiveExpiredFakeroutePacket.cpp
Normal file
48
src/TimeToLiveExpiredFakeroutePacket.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TimeToLiveExpiredFakeroutePacket.h"
|
||||||
|
|
||||||
|
#include <netinet/ip_icmp.h>
|
||||||
|
|
||||||
|
TimeToLiveExpiredFakeroutePacket::TimeToLiveExpiredFakeroutePacket(u_int16_t localReceivedSourcePort,
|
||||||
|
u_int16_t localReceivedDestinationPort,
|
||||||
|
char* localSpoofedSourceAddress,
|
||||||
|
char* localSpoofedDestinationAddress) :
|
||||||
|
FakeroutePacket(localReceivedSourcePort, localReceivedDestinationPort,
|
||||||
|
localSpoofedSourceAddress, localSpoofedDestinationAddress)
|
||||||
|
{}
|
||||||
|
|
||||||
|
u_int16_t TimeToLiveExpiredFakeroutePacket::getIcmpType(void) {
|
||||||
|
return ICMP_TIME_EXCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int16_t TimeToLiveExpiredFakeroutePacket::getIcmpCode(void) {
|
||||||
|
return ICMP_EXC_TTL;
|
||||||
|
}
|
47
src/TimeToLiveExpiredFakeroutePacket.h
Normal file
47
src/TimeToLiveExpiredFakeroutePacket.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TIME_TO_LIVE_EXPIRED_FAKEROUTE_PACKET_H
|
||||||
|
#define TIME_TO_LIVE_EXPIRED_FAKEROUTE_PACKET_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "FakeroutePacket.h"
|
||||||
|
|
||||||
|
class TimeToLiveExpiredFakeroutePacket : public FakeroutePacket {
|
||||||
|
|
||||||
|
protected:
|
||||||
|
u_int16_t getIcmpType(void);
|
||||||
|
u_int16_t getIcmpCode(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TimeToLiveExpiredFakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort,
|
||||||
|
char* spoofedSourceAddress, char* spoofedDestinationAddress);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
50
src/TracerouteEvents.cpp
Normal file
50
src/TracerouteEvents.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TracerouteEvents.h"
|
||||||
|
|
||||||
|
int* TracerouteEvents::getActiveFds(void) {
|
||||||
|
return activeFds;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TracerouteEvents::getActiveFdCount(void) {
|
||||||
|
return activeFdCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TracerouteEvents::setActiveFds(int* localActiveFds) {
|
||||||
|
activeFds = localActiveFds;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TracerouteEvents::setActiveFdCount(int localActiveFdCount) {
|
||||||
|
activeFdCount = localActiveFdCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
TracerouteEvents::~TracerouteEvents(void) {
|
||||||
|
free(activeFds);
|
||||||
|
}
|
48
src/TracerouteEvents.h
Normal file
48
src/TracerouteEvents.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRACEROUTE_EVENTS_H
|
||||||
|
#define TRACEROUTE_EVENTS_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
class TracerouteEvents {
|
||||||
|
private:
|
||||||
|
int* activeFds;
|
||||||
|
int activeFdCount;
|
||||||
|
|
||||||
|
public:
|
||||||
|
~TracerouteEvents(void);
|
||||||
|
int* getActiveFds(void);
|
||||||
|
int getActiveFdCount(void);
|
||||||
|
void setActiveFds(int* activeFds);
|
||||||
|
void setActiveFdCount(int activeFdCount);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
86
src/TracerouteListener.cpp
Normal file
86
src/TracerouteListener.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TracerouteListener.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
TracerouteListener::TracerouteListener(void) : FD_COUNT(31), LOW_ORDER_PORT(32768 + 666) {
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (i=0;i<31;i++) {
|
||||||
|
fds[i].fd = bindSocket(LOW_ORDER_PORT + i);
|
||||||
|
fds[i].events = POLLIN|POLLPRI;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TracerouteListener::listen(class TracerouteEvents &tracerouteEvents) {
|
||||||
|
int *activeFds;
|
||||||
|
int eventCount, i, index = 0;
|
||||||
|
|
||||||
|
if ((eventCount = poll(fds, (unsigned long)FD_COUNT, -1)) < 0) {
|
||||||
|
fprintf(stderr, "Error During Poll.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
activeFds = (int*)malloc(eventCount * sizeof(int));
|
||||||
|
|
||||||
|
for (i=0;i<FD_COUNT;i++) {
|
||||||
|
if ((fds[i].revents & POLLIN == POLLIN) ||
|
||||||
|
(fds[i].revents & POLLPRI == POLLPRI)) {
|
||||||
|
activeFds[index++] = fds[i].fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tracerouteEvents.setActiveFds(activeFds);
|
||||||
|
tracerouteEvents.setActiveFdCount(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TracerouteListener::bindSocket(int port) {
|
||||||
|
struct sockaddr_in localAddress;
|
||||||
|
int sockfd;
|
||||||
|
|
||||||
|
if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
|
||||||
|
fprintf(stderr, "Error Creating Socket.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset((void*)&localAddress, 0, sizeof(localAddress));
|
||||||
|
|
||||||
|
localAddress.sin_family = AF_INET;
|
||||||
|
localAddress.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
localAddress.sin_port = htons(port);
|
||||||
|
|
||||||
|
if ((bind(sockfd, (struct sockaddr*)&localAddress, sizeof(localAddress))) < 0) {
|
||||||
|
fprintf(stderr, "Error Binding Socket\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sockfd;
|
||||||
|
}
|
58
src/TracerouteListener.h
Normal file
58
src/TracerouteListener.h
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRACEROUTE_LISTENER_H
|
||||||
|
#define TRACEROUTE_LISTENER_H
|
||||||
|
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "TracerouteEvents.h"
|
||||||
|
|
||||||
|
class TracerouteListener {
|
||||||
|
|
||||||
|
private:
|
||||||
|
const int FD_COUNT;
|
||||||
|
const int LOW_ORDER_PORT;
|
||||||
|
struct pollfd fds[31];
|
||||||
|
|
||||||
|
int bindSocket(int port);
|
||||||
|
|
||||||
|
public:
|
||||||
|
TracerouteListener(void);
|
||||||
|
void listen(class TracerouteEvents &tracerouteEvents);
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
#endif
|
56
src/TraceroutePacket.cpp
Normal file
56
src/TraceroutePacket.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TraceroutePacket.h"
|
||||||
|
|
||||||
|
TraceroutePacket::TraceroutePacket(char* localSourceAddress, char* localDestinationAddress,
|
||||||
|
u_int16_t localSourcePort, u_int16_t localDestinationPort)
|
||||||
|
{
|
||||||
|
sourceAddress = localSourceAddress;
|
||||||
|
sourcePort = localSourcePort;
|
||||||
|
destinationAddress = localDestinationAddress;
|
||||||
|
destinationPort = localDestinationPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* TraceroutePacket::getSourceAddress(void) {
|
||||||
|
return sourceAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* TraceroutePacket::getDestinationAddress(void) {
|
||||||
|
return destinationAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int16_t TraceroutePacket::getSourcePort(void) {
|
||||||
|
return sourcePort;
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int16_t TraceroutePacket::getDestinationPort(void) {
|
||||||
|
return destinationPort;
|
||||||
|
}
|
||||||
|
|
56
src/TraceroutePacket.h
Normal file
56
src/TraceroutePacket.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRACEROUTE_PACKET_H
|
||||||
|
#define TRACEROUTE_PACKET_H
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
class TraceroutePacket {
|
||||||
|
|
||||||
|
private:
|
||||||
|
char* sourceAddress;
|
||||||
|
char* destinationAddress;
|
||||||
|
u_int16_t sourcePort;
|
||||||
|
u_int16_t destinationPort;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/* void setSourceAddress(char* localSourceAddress); */
|
||||||
|
/* void setSourcePort(u_int16_t localSourcePort); */
|
||||||
|
/* void setDestinationPort(u_int16_t localDestinationPort); */
|
||||||
|
TraceroutePacket(char* sourceAddress, char* destinationAddress,
|
||||||
|
u_int16_t sourcePort, u_int16_t destinationPort);
|
||||||
|
char* getSourceAddress(void);
|
||||||
|
char* getDestinationAddress(void);
|
||||||
|
u_int16_t getSourcePort(void);
|
||||||
|
u_int16_t getDestinationPort(void);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
65
src/TracerouteReader.cpp
Normal file
65
src/TracerouteReader.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "TracerouteReader.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
class TraceroutePacket* TracerouteReader::readPacket(int fd) {
|
||||||
|
char packet[32*1024];
|
||||||
|
|
||||||
|
struct sockaddr_in remoteAddress;
|
||||||
|
struct sockaddr_in localAddress;
|
||||||
|
|
||||||
|
unsigned int size = sizeof(remoteAddress);
|
||||||
|
|
||||||
|
memset((void*)&remoteAddress, 0, size);
|
||||||
|
memset((void*)&localAddress, 0, size);
|
||||||
|
|
||||||
|
if ((recvfrom(fd, packet, 32*1024, 0, (struct sockaddr*)&remoteAddress, &size)) < 0) {
|
||||||
|
fprintf(stderr, "Error receiving datagram.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((getsockname(fd, (struct sockaddr*)&localAddress, &size)) < 0) {
|
||||||
|
fprintf(stderr, "Error getting local name.");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TraceroutePacket(inet_ntoa(remoteAddress.sin_addr),
|
||||||
|
inet_ntoa(localAddress.sin_addr),
|
||||||
|
ntohs(remoteAddress.sin_port),
|
||||||
|
ntohs(localAddress.sin_port));
|
||||||
|
}
|
42
src/TracerouteReader.h
Normal file
42
src/TracerouteReader.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 2002, Matt Rosenfeld
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 4. Neither the name of this program nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TRACEROUTE_READER_H
|
||||||
|
#define TRACEROUTE_READER_H
|
||||||
|
|
||||||
|
#include "TraceroutePacket.h"
|
||||||
|
|
||||||
|
class TracerouteReader {
|
||||||
|
|
||||||
|
public:
|
||||||
|
class TraceroutePacket* readPacket(int fd);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
73
src/in_cksum.cpp
Normal file
73
src/in_cksum.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to Berkeley by
|
||||||
|
* Mike Muuss.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* in_cksum --
|
||||||
|
* Checksum routine for Internet Protocol family headers (C Version)
|
||||||
|
*/
|
||||||
|
unsigned short in_cksum(unsigned short *addr,int len)
|
||||||
|
{
|
||||||
|
register int sum = 0;
|
||||||
|
u_short answer = 0;
|
||||||
|
register u_short *w = addr;
|
||||||
|
register int nleft = len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Our algorithm is simple, using a 32 bit accumulator (sum), we add
|
||||||
|
* sequential 16 bit words to it, and at the end, fold back all the
|
||||||
|
* carry bits from the top 16 bits into the lower 16 bits.
|
||||||
|
*/
|
||||||
|
while (nleft > 1) {
|
||||||
|
sum += *w++;
|
||||||
|
nleft -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* mop up an odd byte, if necessary */
|
||||||
|
if (nleft == 1) {
|
||||||
|
*(u_char *)(&answer) = *(u_char *)w ;
|
||||||
|
sum += answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* add back carry outs from top 16 bits to low 16 bits */
|
||||||
|
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */
|
||||||
|
sum += (sum >> 16); /* add carry */
|
||||||
|
answer = ~sum; /* truncate to 16 bits */
|
||||||
|
return(answer);
|
||||||
|
}
|
6
src/in_cksum.h
Normal file
6
src/in_cksum.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef __IN_CKSUM_H__
|
||||||
|
#define __IN_CKSUM_H__
|
||||||
|
|
||||||
|
unsigned short in_cksum(unsigned short *addr,int len);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user