diff --git a/src/ConnectionManager.cpp b/src/ConnectionManager.cpp index a1a5bfe..dca8ce7 100644 --- a/src/ConnectionManager.cpp +++ b/src/ConnectionManager.cpp @@ -55,10 +55,10 @@ class FakeroutePacket* ConnectionManager::getPacketFor(char* sourceAddress, char if (isTransitHop((*entry).getTtl()/3)) { spoofedPacket = new TimeToLiveExpiredFakeroutePacket(sourcePort, destinationPort, - sourceIp, destinationAddress); + sourceIp, destinationAddress, sourceAddress); } else { spoofedPacket = new DestHostUnreachableFakeroutePacket(sourcePort, destinationPort, - sourceIp, destinationAddress); + sourceIp, destinationAddress, sourceAddress); } (*entry).incrementTtl(routeCount * 3); diff --git a/src/DestHostUnreachableFakeroutePacket.cpp b/src/DestHostUnreachableFakeroutePacket.cpp index 0274bed..3eeecac 100644 --- a/src/DestHostUnreachableFakeroutePacket.cpp +++ b/src/DestHostUnreachableFakeroutePacket.cpp @@ -33,9 +33,10 @@ DestHostUnreachableFakeroutePacket::DestHostUnreachableFakeroutePacket(u_int16_t localReceivedSourcePort, u_int16_t localReceivedDestinationPort, char* localSpoofedSourceAddress, - char* localSpoofedDestinationAddress) : + char* localSpoofedDestinationAddress, + char* localReceivedSourceAddress) : FakeroutePacket(localReceivedSourcePort, localReceivedDestinationPort, - localSpoofedSourceAddress, localSpoofedDestinationAddress) + localSpoofedSourceAddress, localSpoofedDestinationAddress, localReceivedSourceAddress) {} u_int16_t DestHostUnreachableFakeroutePacket::getIcmpType(void) { diff --git a/src/DestHostUnreachableFakeroutePacket.h b/src/DestHostUnreachableFakeroutePacket.h index fb30f32..b039444 100644 --- a/src/DestHostUnreachableFakeroutePacket.h +++ b/src/DestHostUnreachableFakeroutePacket.h @@ -41,7 +41,7 @@ class DestHostUnreachableFakeroutePacket : public FakeroutePacket { public: DestHostUnreachableFakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort, - char* spoofedSourceAddress, char* spoofedDestinationAddress); + char* spoofedSourceAddress, char* spoofedDestinationAddress, char* receivedSourceAddress); }; #endif diff --git a/src/FakeroutePacket.cpp b/src/FakeroutePacket.cpp index 0b2c379..dfac219 100644 --- a/src/FakeroutePacket.cpp +++ b/src/FakeroutePacket.cpp @@ -46,17 +46,21 @@ FakeroutePacket::FakeroutePacket(u_int16_t localReceivedSourcePort, u_int16_t localReceivedDestinationPort, char* localSpoofedSourceAddress, - char* localSpoofedDestinationAddress) : + char* localSpoofedDestinationAddress, + char* localReceivedSourceAddress) : ICMP_HDR_SIZE(sizeof(struct icmp)), IP_HDR_SIZE(sizeof(struct iphdr)), UDP_HDR_SIZE(sizeof(struct udphdr)) { receivedSourcePort = localReceivedSourcePort; receivedDestinationPort = localReceivedDestinationPort; + receivedSourceAddress = localReceivedSourceAddress; spoofedSourceAddress = localSpoofedSourceAddress; spoofedDestinationAddress = localSpoofedDestinationAddress; } +FakeroutePacket::~FakeroutePacket() {} + void FakeroutePacket::sendOn(int fd) { int sockfd; @@ -81,10 +85,10 @@ void FakeroutePacket::sendOn(int fd) { 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); + buildIcmpHeader((char*)(packet + IP_HDR_SIZE), IPPROTO_UDP); + buildIpHeader(spoofedSourceAddress, receivedSourceAddress, (char*)packet); if (sendto(sockfd, packet, sizeof(packet), 0x0, (struct sockaddr*)&packetTo, sizeof(packetTo)) < 0) { fprintf(stderr, "Packet Send Failed."); @@ -99,22 +103,25 @@ void FakeroutePacket::buildUdpHeader(char* packet, u_int16_t sourcePort, udphdr->source = htons(sourcePort); udphdr->dest = htons(destinationPort); + udphdr->len = htons(UDP_BODY_SIZE); } void FakeroutePacket::buildIcmpHeader(char* packet, int protocol) { struct iphdr *fakeIpHdr; struct icmp *icmpHeader = (struct icmp*)packet; - char fakePacket[IP_HDR_SIZE]; + char fakePacket[IP_HDR_SIZE] = {0}; fakeIpHdr = (struct iphdr*)fakePacket; fakeIpHdr->ihl = 5; fakeIpHdr->version = 4; fakeIpHdr->protocol = protocol; + fakeIpHdr->saddr = inet_addr(receivedSourceAddress); + fakeIpHdr->daddr = inet_addr(spoofedDestinationAddress); 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); + icmpHeader->icmp_cksum = (unsigned short)in_cksum((unsigned short*)packet, ICMP_HDR_SIZE + 8); } void FakeroutePacket::buildIpHeader(char* source, char* destination, char* packet) { diff --git a/src/FakeroutePacket.h b/src/FakeroutePacket.h index 7f2bf6a..1d87223 100644 --- a/src/FakeroutePacket.h +++ b/src/FakeroutePacket.h @@ -38,11 +38,13 @@ class FakeroutePacket { const int ICMP_HDR_SIZE; const int IP_HDR_SIZE; const int UDP_HDR_SIZE; + const int UDP_BODY_SIZE = 40; u_int16_t receivedSourcePort; u_int16_t receivedDestinationPort; char* spoofedSourceAddress; char* spoofedDestinationAddress; + char* receivedSourceAddress; virtual void buildUdpHeader(char* packet, u_int16_t sourcePort, u_int16_t destinationPort); virtual void buildIcmpHeader(char* packet, int protocol); @@ -54,7 +56,7 @@ class FakeroutePacket { public: FakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort, - char* spoofedSourceAddress, char* spoofedDestinationAddress); + char* spoofedSourceAddress, char* spoofedDestinationAddress, char* receivedSourceAddress); virtual ~FakeroutePacket(); virtual void sendOn(int fd); }; diff --git a/src/TimeToLiveExpiredFakeroutePacket.cpp b/src/TimeToLiveExpiredFakeroutePacket.cpp index 6acab91..55f527e 100644 --- a/src/TimeToLiveExpiredFakeroutePacket.cpp +++ b/src/TimeToLiveExpiredFakeroutePacket.cpp @@ -34,9 +34,10 @@ TimeToLiveExpiredFakeroutePacket::TimeToLiveExpiredFakeroutePacket(u_int16_t localReceivedSourcePort, u_int16_t localReceivedDestinationPort, char* localSpoofedSourceAddress, - char* localSpoofedDestinationAddress) : + char* localSpoofedDestinationAddress, + char* localReceivedSourceAddress) : FakeroutePacket(localReceivedSourcePort, localReceivedDestinationPort, - localSpoofedSourceAddress, localSpoofedDestinationAddress) + localSpoofedSourceAddress, localSpoofedDestinationAddress, localReceivedSourceAddress) {} u_int16_t TimeToLiveExpiredFakeroutePacket::getIcmpType(void) { diff --git a/src/TimeToLiveExpiredFakeroutePacket.h b/src/TimeToLiveExpiredFakeroutePacket.h index 25e1d92..92624d0 100644 --- a/src/TimeToLiveExpiredFakeroutePacket.h +++ b/src/TimeToLiveExpiredFakeroutePacket.h @@ -38,10 +38,12 @@ class TimeToLiveExpiredFakeroutePacket : public FakeroutePacket { protected: u_int16_t getIcmpType(void); u_int16_t getIcmpCode(void); + char* receivedSourceAddress; public: TimeToLiveExpiredFakeroutePacket(u_int16_t receivedSourcePort, u_int16_t receivedDestinationPort, - char* spoofedSourceAddress, char* spoofedDestinationAddress); + char* spoofedSourceAddress, char* spoofedDestinationAddress, char* receivedSourceAddress); + }; #endif