NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
00001 /***************************************************************************** 00002 * 00003 * Copyright (C) 2002 Uppsala University. 00004 * Copyright (C) 2006 Malaga University. 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: Bj�n Wiberg <bjorn.wiberg@home.se> 00020 * Authors: Alfonso Ariza Quintana.<aarizaq@uma.ea> 00021 * 00022 *****************************************************************************/ 00023 // 00024 // Copyright (C) 2013 and modified by NESG (Network Engineering and Security Group), http://nesg.ugr.es, 00025 // - Gabriel Maciá Fernández (gmacia@ugr.es) 00026 // - Leovigildo Sánchez Casado (sancale@ugr.es) 00027 // - Rafael A. Rodríguez Gómez (rodgom@ugr.es) 00028 // - Roberto Magán Carrión (rmagan@ugr.es) 00029 // - Pedro García Teodoro (pgteodor@ugr.es) 00030 // - José Camacho Páez (josecamacho@ugr.es) 00031 // - Jesús E. Díaz Verdejo (jedv@ugr.es) 00032 // 00033 00034 00035 #ifndef NA_AODV_UU_H 00036 #define NA_AODV_UU_H 00037 00038 /* Constants for interface queue packet buffering/dropping */ 00039 #define IFQ_BUFFER 0 00040 #define IFQ_DROP 1 00041 #define IFQ_DROP_BY_DEST 2 00042 #define PKT_ENC 0x1 /* Packet is encapsulated */ 00043 #define PKT_DEC 0x2 /* Packet arrived at GW and has been decapsulated (and 00044 * should therefore be routed to the Internet */ 00045 // #define CONFIG_GATEWAY 00046 // #define DEBUG_HELLO 00047 00048 #ifndef NS_PORT 00049 #define NS_PORT 00050 #endif 00051 #ifndef OMNETPP 00052 #define OMNETPP 00053 #endif 00054 00055 /* This is a C++ port of AODV-UU for ns-2 */ 00056 #ifndef NS_PORT 00057 #error "To compile the ported version, NS_PORT must be defined!" 00058 #endif /* NS_PORT */ 00059 00060 #ifndef AODV_USE_STL 00061 #define AODV_USE_STL 00062 #endif 00063 00064 #ifndef AODV_USE_STL_RT 00065 #define AODV_USE_STL_RT 00066 #endif 00067 00068 #define AODV_GLOBAL_STATISTISTIC 00069 00070 /* Global definitions and lib functions */ 00071 #include "NA_aodv-uu/NA_params.h" 00072 #include "NA_aodv-uu/NA_defs_aodv.h" 00073 00074 /* System-dependent datatypes */ 00075 /* Needed by some network-related datatypes */ 00076 #include "ManetRoutingBase.h" 00077 #include "NA_aodv-uu/NA_list.h" 00078 #include "NA_aodv_msg_struct.h" 00079 #include "ICMPAccess.h" 00080 #include "Ieee80211Frame_m.h" 00081 00082 00083 /* Forward declaration needed to be able to reference the class */ 00084 class NA_AODVUU; 00085 00086 00087 00088 #ifndef IP_BROADCAST 00089 #define IP_BROADCAST ((u_int32_t) 0xffffffff) 00090 #endif /* !IP_BROADCAST */ 00091 00092 /* Extract global data types, defines and global declarations */ 00093 #undef NS_NO_GLOBALS 00094 #define NS_NO_DECLARATIONS 00095 00096 #include "NA_aodv-uu/NA_timer_queue_aodv.h" 00097 #include "NA_aodv-uu/NA_aodv_hello.h" 00098 #include "NA_aodv-uu/NA_aodv_rerr.h" 00099 #include "NA_aodv-uu/NA_aodv_rrep.h" 00100 #include "NA_aodv-uu/NA_aodv_rreq.h" 00101 #include "NA_aodv-uu/NA_aodv_socket.h" 00102 #include "NA_aodv-uu/NA_aodv_timeout.h" 00103 #include "NA_aodv-uu/NA_debug_aodv.h" 00104 #include "NA_aodv-uu/NA_routing_table.h" 00105 #include "NA_aodv-uu/NA_seek_list.h" 00106 #include "NA_aodv-uu/NA_locality.h" 00107 00108 #include "NA_packet_queue_omnet.h" 00109 00110 #undef NS_NO_DECLARATIONS 00111 00112 /* In omnet we don't care about byte order */ 00113 #undef ntohl 00114 #define ntohl(x) x 00115 #undef htonl 00116 #define htonl(x) x 00117 #undef htons 00118 #define htons(x) x 00119 #undef ntohs 00120 #define ntohs(x) x 00121 00122 /* NETATTACKS */ 00123 //#include <omnetpp.h> 00124 #include "common/log/NA_NesgLog.h" 00125 #include "NA_HackedModule.h" 00126 #include "NA_SinkholeMessage_m.h" 00127 // --------------- 00128 00129 00159 class NA_AODVUU : public ManetRoutingBase, public NA_HackedModule 00160 { 00161 00162 private: 00163 00167 NA_NesgLog log; 00168 00169 // BEGIN NA_SINKHOLE - sancale 00173 bool sinkholeAttackIsActive; 00174 00178 double sinkholeAttackProbability; 00179 00183 bool sinkOnlyWhenRouteInTable; 00184 00188 long numSents; 00189 00193 ParPtr seqnoAdded; 00194 00198 int numHops; 00199 00200 // END NA_SINKHOLE - sancale 00201 00202 char nodeName[50]; 00203 ICMPAccess icmpAccess; 00204 bool useIndex; 00205 bool isRoot; 00206 uint32_t costStatic; 00207 uint32_t costMobile; 00208 bool useHover; 00209 bool propagateProactive; 00210 struct timer proactive_rreq_timer; 00211 long proactive_rreq_timeout; 00212 bool isBroadcast (ManetAddress add) 00213 { 00214 if (this->isInMacLayer() && add==ManetAddress(MACAddress::BROADCAST_ADDRESS)) 00215 return true; 00216 if (!this->isInMacLayer() && add==ManetAddress(IPv4Address::ALLONES_ADDRESS)) 00217 return true; 00218 return false; 00219 } 00220 // cMessage messageEvent; 00221 typedef std::multimap<simtime_t, struct timer*> AodvTimerMap; 00222 AodvTimerMap aodvTimerMap; 00223 typedef std::map<ManetAddress, struct rt_table*> AodvRtTableMap; 00224 AodvRtTableMap aodvRtTableMap; 00225 00226 00227 public: 00228 static int log_file_fd; 00229 static bool log_file_fd_init; 00230 NA_AODVUU() {isRoot = false; is_init = false; log_file_fd_init = false; sendMessageEvent = new cMessage();/*&messageEvent;*/} 00231 ~NA_AODVUU(); 00232 00233 void packetFailed(IPv4Datagram *p); 00234 void packetFailedMac(Ieee80211DataFrame *); 00235 00236 // Routing information access 00237 virtual uint32_t getRoute(const ManetAddress &,std::vector<ManetAddress> &); 00238 virtual bool getNextHop(const ManetAddress &,ManetAddress &add,int &iface,double &); 00239 virtual bool isProactive(); 00240 virtual void setRefreshRoute(const ManetAddress &destination, const ManetAddress & nextHop,bool isReverse); 00241 virtual bool setRoute(const ManetAddress & destination,const ManetAddress &nextHop,const int &ifaceIndex,const int &hops,const ManetAddress &mask=ManetAddress::ZERO); 00242 virtual bool setRoute(const ManetAddress & destination,const ManetAddress &nextHop,const char *ifaceName,const int &hops,const ManetAddress &mask=ManetAddress::ZERO); 00243 00244 /* NETATTACKS */ 00245 void handleMessageFromAttackController(cMessage *msg); 00246 // --------------- 00247 00248 protected: 00249 bool is_init; 00250 void drop (cPacket *p,int cause = 0) 00251 { 00252 delete p; 00253 // icmpAccess.get()->sendErrorMessage(p, ICMP_DESTINATION_UNREACHABLE, cause); 00254 } 00255 int startAODVUUAgent(); 00256 void scheduleNextEvent(); 00257 const char *if_indextoname(int, char *); 00258 IPv4Datagram *pkt_encapsulate(IPv4Datagram *, IPv4Address); 00259 IPv4Datagram *pkt_decapsulate(IPv4Datagram *); 00260 virtual void handleMessage(cMessage *msg); 00261 virtual void finish(); 00262 00263 int numInitStages() const {return 5;} 00264 void initialize(int stage); 00265 00266 00267 cMessage * sendMessageEvent; 00268 00269 void recvAODVUUPacket(cMessage * p); 00270 void processPacket(IPv4Datagram *,unsigned int); 00271 00272 int initialized; 00273 int node_id; 00274 IPv4Address *gateWayAddress; 00275 00276 int NS_DEV_NR; 00277 int NS_IFINDEX; 00278 // cModule *ipmod; 00279 00280 /* 00281 Extract method declarations (and occasionally, variables) 00282 from header files 00283 */ 00284 #define NS_NO_GLOBALS 00285 #undef NS_NO_DECLARATIONS 00286 00287 #undef NA_AODV_NEIGHBOR_H 00288 #include "NA_aodv-uu/NA_aodv_neighbor.h" 00289 00290 #undef NA_AODV_HELLO_H 00291 #include "NA_aodv-uu/NA_aodv_hello.h" 00292 00293 #undef NA_AODV_RERR_H 00294 #include "NA_aodv-uu/NA_aodv_rerr.h" 00295 00296 #undef NA_AODV_RREP_H 00297 #include "NA_aodv-uu/NA_aodv_rrep.h" 00298 00299 #undef NA_AODV_RREQ_H 00300 #include "NA_aodv-uu/NA_aodv_rreq.h" 00301 00302 #undef NA_AODV_SOCKET_H 00303 #include "NA_aodv-uu/NA_aodv_socket.h" 00304 00305 #undef NA_AODV_TIMEOUT_H 00306 #include "NA_aodv-uu/NA_aodv_timeout.h" 00307 00308 #undef NA_DEBUG_H 00309 #include "NA_aodv-uu/NA_debug_aodv.h" 00310 00311 #undef NA_ROUTING_TABLE_H 00312 #include "NA_aodv-uu/NA_routing_table.h" 00313 00314 #undef NA_SEEK_LIST_H 00315 #include "NA_aodv-uu/NA_seek_list.h" 00316 00317 #undef NA_TIMER_QUEUE_H 00318 #include "NA_aodv-uu/NA_timer_queue_aodv.h" 00319 00320 #undef NA_LOCALITY_H 00321 #include "NA_aodv-uu/NA_locality.h" 00322 00323 #undef NA_PACKET_QUEUE_H 00324 #include "NA_packet_queue_omnet.h" 00325 00326 #undef NS_NO_GLOBALS 00327 00328 /* (Previously global) variables from main.c */ 00329 int log_to_file; 00330 int rt_log_interval; 00331 int unidir_hack; 00332 int rreq_gratuitous; 00333 int expanding_ring_search; 00334 int internet_gw_mode; 00335 int local_repair; 00336 int receive_n_hellos; 00337 int hello_jittering; 00338 int optimized_hellos; 00339 int ratelimit; 00340 int llfeedback; 00341 char *progname; 00342 int wait_on_reboot; 00343 struct timer worb_timer; 00344 00345 /* Parameters that are dynamic configuration values: */ 00346 int active_route_timeout; 00347 int ttl_start; 00348 int delete_period; 00349 00350 /* From aodv_hello.c */ 00351 struct timer hello_timer; 00352 #ifndef AODV_USE_STL 00353 /* From aodv_rreq.c */ 00354 list_t rreqRecords; 00355 #define rreq_records this->rreqRecords 00356 list_t rreqBlacklist; 00357 #define rreq_blacklist this->rreqBlacklist 00358 00359 /* From seek_list.c */ 00360 list_t seekHead; 00361 #define seekhead this->seekHead 00362 00363 /* From timer_queue_aodv.c */ 00364 list_t timeList; 00365 #define TQ this->timeList 00366 #else 00367 typedef std::vector <rreq_record *>RreqRecords; 00368 typedef std::map <ManetAddress, struct blacklist *>RreqBlacklist; 00369 typedef std::map <ManetAddress, seek_list_t*>SeekHead; 00370 00371 RreqRecords rreq_records; 00372 RreqBlacklist rreq_blacklist; 00373 SeekHead seekhead; 00374 #endif 00375 /* From debug.c */ 00376 // int log_file_fd; 00377 int log_rt_fd; 00378 int log_nmsgs; 00379 int debug; 00380 struct timer rt_log_timer; 00381 00382 /* From defs.h */ 00383 struct host_info this_host; 00384 struct dev_info dev_ifindex (int); 00385 struct dev_info dev_nr(int); 00386 unsigned int dev_indices[MAX_NR_INTERFACES]; 00387 00388 // inline int ifindex2devindex(unsigned int ifindex); 00389 int ifindex2devindex(unsigned int ifindex); 00390 #ifdef AODV_GLOBAL_STATISTISTIC 00391 static bool iswrite; 00392 static int totalSend; 00393 static int totalRreqSend; 00394 static int totalRreqRec; 00395 static int totalRrepSend; 00396 static int totalRrepRec; 00397 static int totalRrepAckSend; 00398 static int totalRrepAckRec; 00399 static int totalRerrSend; 00400 static int totalRerrRec; 00401 #else 00402 bool iswrite; 00403 int totalSend; 00404 int totalRreqSend; 00405 int totalRreqRec; 00406 int totalRrepSend; 00407 int totalRrepRec; 00408 int totalRrepAckSend; 00409 int totalRrepAckRec; 00410 int totalRerrSend; 00411 int totalRerrRec; 00412 #endif 00413 // used for break link notification 00414 //virtual void processPromiscuous(const cObject *details){}; 00415 virtual void processLinkBreak(const cObject *details); 00416 //virtual void processFullPromiscuous(const cObject *details){} 00417 virtual bool isOurType(cPacket *); 00418 virtual bool getDestAddress(cPacket *,ManetAddress &); 00419 00420 00421 }; 00422 00423 #if 0 00424 /* From defs.h (needs the AODVUU class declaration) */ 00425 inline int NS_CLASS ifindex2devindex(unsigned int ifindex) 00426 { 00427 int i; 00428 00429 for (i = 0; i < this_host.nif; i++) 00430 if (dev_indices[i] == ifindex) 00431 return i; 00432 00433 return -1; 00434 } 00435 #endif 00436 #endif /* AODV_UU_H */