Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | """ |
| 3 | 2015-2016 |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 4 | Copyright 2016 Open Networking Foundation (ONF) |
Jeremy Songster | ae01bba | 2016-07-11 15:39:17 -0700 | [diff] [blame] | 5 | |
| 6 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 7 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 8 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 9 | |
| 10 | TestON is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation, either version 2 of the License, or |
| 13 | ( at your option ) any later version. |
| 14 | |
| 15 | TestON is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | ScapyCliDriver is the basic driver which will handle the Scapy functions |
| 24 | |
| 25 | TODO: Add Explanation on how to install scapy |
| 26 | """ |
| 27 | import pexpect |
| 28 | import re |
| 29 | import sys |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 30 | import os |
| 31 | from drivers.common.cli.emulatordriver import Emulator |
| 32 | |
| 33 | |
| 34 | class ScapyCliDriver( Emulator ): |
| 35 | |
| 36 | """ |
| 37 | ScapyCliDriver is the basic driver which will handle |
| 38 | the Scapy functions""" |
| 39 | def __init__( self ): |
Devin Lim | dc78e20 | 2017-06-09 18:30:07 -0700 | [diff] [blame] | 40 | super( ScapyCliDriver, self ).__init__() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 41 | self.handle = self |
| 42 | self.name = None |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 43 | self.home = "~/" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 44 | self.wrapped = sys.modules[ __name__ ] |
| 45 | self.flag = 0 |
| 46 | # TODO: Refactor driver to use these everywhere |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 47 | self.hostPrompt = "\$" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 48 | self.scapyPrompt = ">>>" |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 49 | self.sudoRequired = True |
| 50 | self.ifaceName = None |
Jon Hall | b0c6ae0 | 2021-09-01 10:53:39 -0700 | [diff] [blame] | 51 | self.scapyPath = "scapy" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 52 | |
| 53 | def connect( self, **connectargs ): |
| 54 | """ |
| 55 | Here the main is the TestON instance after creating |
| 56 | all the log handles.""" |
| 57 | try: |
| 58 | for key in connectargs: |
| 59 | vars( self )[ key ] = connectargs[ key ] |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 60 | for key in self.options: |
| 61 | if key == "home": |
| 62 | self.home = self.options[ key ] |
| 63 | elif key == "name": |
| 64 | self.name = self.options[ key ] |
| 65 | elif key == "sudo_required": |
| 66 | self.sudoRequired = False if self.options[ key ] == "false" else True |
| 67 | elif key == "ifaceName": |
| 68 | self.ifaceName = self.options[ key ] |
Jon Hall | b0c6ae0 | 2021-09-01 10:53:39 -0700 | [diff] [blame] | 69 | elif key == "scapy_path": |
| 70 | self.scapyPath = self.options[ key ] |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 71 | if self.ifaceName is None: |
| 72 | self.ifaceName = self.name + "-eth0" |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 73 | |
| 74 | # Parse route config |
| 75 | self.routes = [] |
| 76 | routes = self.options.get( 'routes' ) |
| 77 | if routes: |
| 78 | for route in routes: |
| 79 | route = routes[ route ] |
| 80 | iface = route.get( 'interface' ) |
| 81 | if not iface: |
| 82 | iface = None |
| 83 | self.routes.append( { 'network': route[ 'network' ], |
| 84 | 'netmask': route[ 'netmask' ], |
| 85 | 'gw': route.get( 'gw' ), |
| 86 | 'interface': iface } ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 87 | try: |
| 88 | if os.getenv( str( self.ip_address ) ) is not None: |
| 89 | self.ip_address = os.getenv( str( self.ip_address ) ) |
| 90 | else: |
| 91 | main.log.info( self.name + |
| 92 | ": Trying to connect to " + |
| 93 | self.ip_address ) |
| 94 | |
| 95 | except KeyError: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 96 | main.log.info( self.name + ": Invalid host name," + |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 97 | " connecting to local host instead" ) |
| 98 | self.ip_address = 'localhost' |
| 99 | except Exception as inst: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 100 | main.log.error( self.name + ": Uncaught exception: " + str( inst ) ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 101 | |
| 102 | self.handle = super( |
| 103 | ScapyCliDriver, |
| 104 | self ).connect( |
| 105 | user_name=self.user_name, |
| 106 | ip_address=self.ip_address, |
| 107 | port=None, |
| 108 | pwd=self.pwd ) |
| 109 | |
| 110 | if self.handle: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 111 | main.log.info( self.name + ": Connection successful to the host " + |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 112 | self.user_name + |
| 113 | "@" + |
| 114 | self.ip_address ) |
You Wang | 4cc6191 | 2018-08-28 10:10:58 -0700 | [diff] [blame] | 115 | return self.handle |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 116 | else: |
| 117 | main.log.error( "Connection failed to the host " + |
| 118 | self.user_name + |
| 119 | "@" + |
| 120 | self.ip_address ) |
Jon Hall | 3a03cad | 2021-04-07 11:21:55 -0700 | [diff] [blame] | 121 | main.log.error( "Failed to connect to the Host" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 122 | return main.FALSE |
| 123 | except pexpect.EOF: |
| 124 | main.log.error( self.name + ": EOF exception found" ) |
| 125 | main.log.error( self.name + ": " + self.handle.before ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 126 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 127 | except Exception: |
| 128 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 129 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 130 | |
| 131 | def disconnect( self ): |
| 132 | """ |
| 133 | Called at the end of the test to stop the scapy component and |
| 134 | disconnect the handle. |
| 135 | """ |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 136 | main.log.debug( self.name + ": Disconnecting" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 137 | response = main.TRUE |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 138 | try: |
| 139 | if self.handle: |
| 140 | self.handle.sendline( "exit" ) |
| 141 | self.handle.expect( "closed" ) |
| 142 | except pexpect.EOF: |
| 143 | main.log.error( self.name + ": EOF exception found" ) |
| 144 | main.log.error( self.name + ": " + self.handle.before ) |
| 145 | except Exception: |
| 146 | main.log.exception( self.name + ": Connection failed to the host" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 147 | response = main.FALSE |
| 148 | return response |
| 149 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 150 | def startScapy( self, mplsPath="", ifaceName=None, enableGtp=False ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 151 | """ |
| 152 | Start the Scapy cli |
| 153 | optional: |
| 154 | mplsPath - The path where the MPLS class is located |
| 155 | NOTE: This can be a relative path from the user's home dir |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 156 | ifaceName - the name of the default interface to use. |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 157 | enableGtp - True if you want to generate GTP traffic |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 158 | """ |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 159 | mplsLines = [ 'import imp', |
| 160 | 'imp.load_source( "mplsClass", "{}mplsClass.py" )'.format( mplsPath ), |
| 161 | 'from mplsClass import MPLS', |
| 162 | 'bind_layers(Ether, MPLS, type = 0x8847)', |
| 163 | 'bind_layers(MPLS, MPLS, bottom_of_label_stack = 0)', |
| 164 | 'bind_layers(MPLS, IP)' ] |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 165 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 166 | # TODO: add GTPPDUSessionContainer when scapy is updated |
| 167 | gtpLines = [ 'from scapy.contrib.gtp import GTP_U_Header'] |
| 168 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 169 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 170 | main.log.debug( self.name + ": Starting scapy" ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 171 | if self.sudoRequired: |
Jon Hall | b0c6ae0 | 2021-09-01 10:53:39 -0700 | [diff] [blame] | 172 | self.handle.sendline( "sudo %s" % self.scapyPath ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 173 | else: |
Jon Hall | b0c6ae0 | 2021-09-01 10:53:39 -0700 | [diff] [blame] | 174 | self.handle.sendline( self.scapyPath ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 175 | i = self.handle.expect( [ "not found", "password for", self.scapyPrompt ] ) |
| 176 | if i == 1: |
| 177 | main.log.debug( "Sudo asking for password" ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 178 | self.handle.sendline( self.pwd ) |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 179 | i = self.handle.expect( [ "not found", self.scapyPrompt ] ) |
| 180 | if i == 0: |
| 181 | output = self.handle.before + self.handle.after |
| 182 | self.handle.expect( self.prompt ) |
| 183 | output += self.handle.before + self.handle.after |
| 184 | main.log.debug( self.name + ": Scapy not installed, aborting test. \n" + output ) |
| 185 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 186 | self.handle.sendline( "conf.color_theme = NoTheme()" ) |
| 187 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 188 | response = self.cleanOutput( self.handle.before ) |
| 189 | self.handle.sendline( "conf.fancy_prompt = False" ) |
| 190 | self.handle.expect( self.scapyPrompt ) |
| 191 | response = self.cleanOutput( self.handle.before ) |
| 192 | self.handle.sendline( "conf.interactive = False" ) |
| 193 | self.handle.expect( "interactive" ) |
| 194 | self.handle.expect( self.scapyPrompt ) |
| 195 | response = self.cleanOutput( self.handle.before ) |
| 196 | self.handle.sendline( "" ) |
| 197 | self.handle.expect( self.scapyPrompt ) |
| 198 | response = self.cleanOutput( self.handle.before ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 199 | if mplsPath: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 200 | main.log.debug( self.name + ": Adding MPLS class" ) |
| 201 | main.log.debug( self.name + ": MPLS class path: " + mplsPath ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 202 | for line in mplsLines: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 203 | main.log.debug( self.name + ": sending line: " + line ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 204 | self.handle.sendline( line ) |
| 205 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 206 | response = self.cleanOutput( self.handle.before ) |
| 207 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 208 | if enableGtp: |
| 209 | for line in gtpLines: |
| 210 | main.log.debug( self.name + ": sending line: " + line ) |
| 211 | self.handle.sendline( line ) |
| 212 | self.handle.expect( self.scapyPrompt ) |
| 213 | response = self.cleanOutput( self.handle.before ) |
| 214 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 215 | # Set interface |
| 216 | if ifaceName: |
| 217 | self.handle.sendline( 'conf.iface = "' + ifaceName + '"' ) |
| 218 | self.clearBuffer() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 219 | return main.TRUE |
| 220 | except pexpect.TIMEOUT: |
| 221 | main.log.exception( self.name + ": Command timed out" ) |
| 222 | return main.FALSE |
| 223 | except pexpect.EOF: |
| 224 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 225 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 226 | except Exception: |
| 227 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 228 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 229 | |
| 230 | def stopScapy( self ): |
| 231 | """ |
| 232 | Exit the Scapy cli |
| 233 | """ |
| 234 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 235 | main.log.debug( self.name + ": Stopping scapy" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 236 | self.handle.sendline( "exit()" ) |
| 237 | self.handle.expect( self.hostPrompt ) |
| 238 | return main.TRUE |
| 239 | except pexpect.TIMEOUT: |
| 240 | main.log.exception( self.name + ": Command timed out" ) |
| 241 | return main.FALSE |
| 242 | except pexpect.EOF: |
| 243 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 244 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 245 | except Exception: |
| 246 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 247 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 248 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 249 | |
| 250 | def buildGTP( self, ipVersion=4, **kwargs ): |
| 251 | """ |
| 252 | Build a GTP frame. |
| 253 | |
| 254 | Will create a frame class with the given options. If a field is |
| 255 | left blank it will default to the below value unless it is |
| 256 | overwritten by the next frame. |
| 257 | Default frame: |
| 258 | ###[ GTP_U_Header ]### |
| 259 | gtp_type=g_pdu |
| 260 | |
| 261 | Returns main.TRUE or main.FALSE on error |
| 262 | """ |
| 263 | |
| 264 | try: |
| 265 | main.log.debug( self.name + ": Building GTP Frame" ) |
| 266 | # Set the UDP frame |
| 267 | cmd = 'gtp = GTP_U_Header( ' |
| 268 | options = [] |
| 269 | for key, value in kwargs.iteritems(): |
| 270 | options.append( str( key ) + "=" + str( value ) ) |
| 271 | cmd += ", ".join( options ) |
| 272 | cmd += ' )' |
| 273 | self.handle.sendline( cmd ) |
| 274 | self.handle.expect( self.scapyPrompt ) |
| 275 | response = self.cleanOutput( self.handle.before ) |
| 276 | if "Traceback" in response: |
| 277 | # KeyError, SyntaxError, ... |
| 278 | main.log.error( "Error in sending command: " + response ) |
| 279 | return main.FALSE |
| 280 | if str( ipVersion ) is '4': |
| 281 | self.handle.sendline( "packet = ether/ip/udp/gtp" ) |
| 282 | elif str( ipVersion ) is '6': |
| 283 | self.handle.sendline( "packet = ether/ipv6/udp/gtp" ) |
| 284 | else: |
| 285 | main.log.error( "Unrecognized option for ipVersion, given " + |
| 286 | repr( ipVersion ) ) |
| 287 | return main.FALSE |
| 288 | self.handle.expect( self.scapyPrompt ) |
| 289 | response = self.cleanOutput( self.handle.before ) |
| 290 | if "Traceback" in response: |
| 291 | # KeyError, SyntaxError, ... |
| 292 | main.log.error( "Error in sending command: " + response ) |
| 293 | return main.FALSE |
| 294 | return main.TRUE |
| 295 | except pexpect.TIMEOUT: |
| 296 | main.log.exception( self.name + ": Command timed out" ) |
| 297 | return main.FALSE |
| 298 | except pexpect.EOF: |
| 299 | main.log.exception( self.name + ": connection closed." ) |
| 300 | main.cleanAndExit() |
| 301 | except Exception: |
| 302 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 303 | main.cleanAndExit() |
| 304 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 305 | def buildEther( self, **kwargs ): |
| 306 | """ |
| 307 | Build an Ethernet frame |
| 308 | |
| 309 | Will create a frame class with the given options. If a field is |
| 310 | left blank it will default to the below value unless it is |
| 311 | overwritten by the next frame. |
| 312 | Default frame: |
| 313 | ###[ Ethernet ]### |
| 314 | dst= ff:ff:ff:ff:ff:ff |
| 315 | src= 00:00:00:00:00:00 |
| 316 | type= 0x800 |
| 317 | |
| 318 | Returns main.TRUE or main.FALSE on error |
| 319 | """ |
| 320 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 321 | main.log.debug( self.name + ": Building Ethernet Frame" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 322 | # Set the Ethernet frame |
| 323 | cmd = 'ether = Ether( ' |
| 324 | options = [] |
| 325 | for key, value in kwargs.iteritems(): |
| 326 | if isinstance( value, str ): |
| 327 | value = '"' + value + '"' |
| 328 | options.append( str( key ) + "=" + str( value ) ) |
| 329 | cmd += ", ".join( options ) |
| 330 | cmd += ' )' |
| 331 | self.handle.sendline( cmd ) |
| 332 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 333 | response = self.cleanOutput( self.handle.before ) |
| 334 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 335 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 336 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 337 | return main.FALSE |
| 338 | self.handle.sendline( "packet = ether" ) |
| 339 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 340 | response = self.cleanOutput( self.handle.before ) |
| 341 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 342 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 343 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 344 | return main.FALSE |
| 345 | return main.TRUE |
| 346 | except pexpect.TIMEOUT: |
| 347 | main.log.exception( self.name + ": Command timed out" ) |
| 348 | return main.FALSE |
| 349 | except pexpect.EOF: |
| 350 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 351 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 352 | except Exception: |
| 353 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 354 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 355 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 356 | def buildIP( self, vlan=False, overGtp=False, **kwargs ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 357 | """ |
| 358 | Build an IP frame |
| 359 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 360 | If overGtp is True, it creates an inner IPv4 frame. The outer IP header |
| 361 | must be IPv4. |
| 362 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 363 | Will create a frame class with the given options. If a field is |
| 364 | left blank it will default to the below value unless it is |
| 365 | overwritten by the next frame. |
| 366 | Default frame: |
| 367 | ###[ IP ]### |
| 368 | version= 4 |
| 369 | ihl= None |
| 370 | tos= 0x0 |
| 371 | len= None |
| 372 | id= 1 |
| 373 | flags= |
| 374 | frag= 0 |
| 375 | ttl= 64 |
| 376 | proto= hopopt |
| 377 | chksum= None |
| 378 | src= 127.0.0.1 |
| 379 | dst= 127.0.0.1 |
| 380 | \options\ |
| 381 | |
| 382 | Returns main.TRUE or main.FALSE on error |
| 383 | """ |
| 384 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 385 | main.log.debug( self.name + ": Building IP Frame" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 386 | # Set the IP frame |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 387 | if overGtp: |
| 388 | cmd = 'inner_ip = IP( ' |
| 389 | else: |
| 390 | cmd = 'ip = IP( ' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 391 | options = [] |
| 392 | for key, value in kwargs.iteritems(): |
| 393 | if isinstance( value, str ): |
| 394 | value = '"' + value + '"' |
| 395 | options.append( str( key ) + "=" + str( value ) ) |
| 396 | cmd += ", ".join( options ) |
| 397 | cmd += ' )' |
| 398 | self.handle.sendline( cmd ) |
| 399 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 400 | response = self.cleanOutput( self.handle.before ) |
| 401 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 402 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 403 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 404 | return main.FALSE |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 405 | if vlan: |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 406 | if overGtp: |
| 407 | self.handle.sendline( "packet = ether/vlan/ip/udp/gtp/inner_ip" ) |
| 408 | else: |
| 409 | self.handle.sendline( "packet = ether/vlan/ip" ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 410 | else: |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 411 | if overGtp: |
| 412 | self.handle.sendline( "packet = ether/ip/udp/gtp/inner_ip" ) |
| 413 | else: |
| 414 | self.handle.sendline( "packet = ether/ip" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 415 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 416 | response = self.cleanOutput( self.handle.before ) |
| 417 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 418 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 419 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 420 | return main.FALSE |
| 421 | return main.TRUE |
| 422 | except pexpect.TIMEOUT: |
| 423 | main.log.exception( self.name + ": Command timed out" ) |
| 424 | return main.FALSE |
| 425 | except pexpect.EOF: |
| 426 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 427 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 428 | except Exception: |
| 429 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 430 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 431 | |
Siddesh | a19e3c8 | 2021-06-09 22:45:27 +0000 | [diff] [blame] | 432 | def buildVLAN( self, **kwargs ): |
| 433 | """ |
| 434 | Build a VLAN frame |
| 435 | """ |
| 436 | try: |
| 437 | main.log.debug( self.name + ": Building VLAN Frame" ) |
| 438 | # Set the IP frame |
| 439 | cmd = 'vlan = Dot1Q( ' |
| 440 | options = [] |
| 441 | for key, value in kwargs.iteritems(): |
| 442 | if isinstance( value, str ): |
| 443 | value = '"' + value + '"' |
| 444 | options.append( str( key ) + "=" + str( value ) ) |
| 445 | cmd += ", ".join( options ) |
| 446 | cmd += ' )' |
| 447 | self.handle.sendline( cmd ) |
| 448 | self.handle.expect( self.scapyPrompt ) |
| 449 | response = self.cleanOutput( self.handle.before ) |
| 450 | if "Traceback" in response: |
| 451 | # KeyError, SyntaxError, ... |
| 452 | main.log.error( "Error in sending command: " + response ) |
| 453 | return main.FALSE |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 454 | self.handle.sendline( "packet = ether/vlan" ) |
Siddesh | a19e3c8 | 2021-06-09 22:45:27 +0000 | [diff] [blame] | 455 | self.handle.expect( self.scapyPrompt ) |
| 456 | response = self.cleanOutput( self.handle.before ) |
| 457 | if "Traceback" in response: |
| 458 | # KeyError, SyntaxError, ... |
| 459 | main.log.error( "Error in sending command: " + response ) |
| 460 | return main.FALSE |
| 461 | return main.TRUE |
| 462 | except pexpect.TIMEOUT: |
| 463 | main.log.exception( self.name + ": Command timed out" ) |
| 464 | return main.FALSE |
| 465 | except pexpect.EOF: |
| 466 | main.log.exception( self.name + ": connection closed." ) |
| 467 | main.cleanAndExit() |
| 468 | except Exception: |
| 469 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 470 | main.cleanAndExit() |
| 471 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 472 | def buildIPv6( self, vlan=False, overGtp=False, **kwargs ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 473 | """ |
| 474 | Build an IPv6 frame |
| 475 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 476 | If overGtp is True, it creates an inner IPv6 frame. The outer ip header |
| 477 | must be IPv6. |
| 478 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 479 | Will create a frame class with the given options. If a field is |
| 480 | left blank it will default to the below value unless it is |
| 481 | overwritten by the next frame. |
| 482 | Default frame: |
| 483 | ###[ IPv6 ]### |
| 484 | version= 6 |
| 485 | tc= 0 |
| 486 | fl= 0 |
| 487 | plen= None |
| 488 | nh= No Next Header |
| 489 | hlim= 64 |
| 490 | src= ::1 |
| 491 | dst= ::1 |
| 492 | |
| 493 | Returns main.TRUE or main.FALSE on error |
| 494 | """ |
| 495 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 496 | main.log.debug( self.name + ": Building IPv6 Frame" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 497 | # Set the IPv6 frame |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 498 | if overGtp: |
| 499 | cmd = 'inner_ipv6 = IPv6( ' |
| 500 | else: |
| 501 | cmd = 'ipv6 = IPv6( ' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 502 | options = [] |
| 503 | for key, value in kwargs.iteritems(): |
| 504 | if isinstance( value, str ): |
| 505 | value = '"' + value + '"' |
| 506 | options.append( str( key ) + "=" + str( value ) ) |
| 507 | cmd += ", ".join( options ) |
| 508 | cmd += ' )' |
| 509 | self.handle.sendline( cmd ) |
| 510 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 511 | response = self.cleanOutput( self.handle.before ) |
| 512 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 513 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 514 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 515 | return main.FALSE |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 516 | if vlan: |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 517 | if overGtp: |
| 518 | self.handle.sendline( "packet = ether/vlan/ipv6/udp/gtp/inner_ipv6" ) |
| 519 | else: |
| 520 | self.handle.sendline( "packet = ether/vlan/ipv6" ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 521 | else: |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 522 | if overGtp: |
| 523 | self.handle.sendline( "packet = ether/ipv6/udp/gtp/inner_ipv6" ) |
| 524 | else: |
| 525 | self.handle.sendline( "packet = ether/ipv6" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 526 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 527 | response = self.cleanOutput( self.handle.before ) |
| 528 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 529 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 530 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 531 | return main.FALSE |
| 532 | return main.TRUE |
| 533 | except pexpect.TIMEOUT: |
| 534 | main.log.exception( self.name + ": Command timed out" ) |
| 535 | return main.FALSE |
| 536 | except pexpect.EOF: |
| 537 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 538 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 539 | except Exception: |
| 540 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 541 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 542 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 543 | def buildTCP( self, ipVersion=4, overGtp=False, **kwargs ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 544 | """ |
| 545 | Build an TCP frame |
| 546 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 547 | If overGtp is True, it creates an inner TCP frame, in this case ipVersion |
| 548 | signals the IP version of both outer and inner headers. |
| 549 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 550 | Will create a frame class with the given options. If a field is |
| 551 | left blank it will default to the below value unless it is |
| 552 | overwritten by the next frame. |
| 553 | |
| 554 | NOTE: Some arguments require quotes around them. It's up to you to |
| 555 | know which ones and to add them yourself. Arguments with an asterisk |
| 556 | do not need quotes. |
| 557 | |
| 558 | Options: |
| 559 | ipVersion - Either 4 (default) or 6, indicates what Internet Protocol |
| 560 | frame to use to encapsulate into |
| 561 | Default frame: |
| 562 | ###[ TCP ]### |
| 563 | sport= ftp_data * |
| 564 | dport= http * |
| 565 | seq= 0 |
| 566 | ack= 0 |
| 567 | dataofs= None |
| 568 | reserved= 0 |
| 569 | flags= S |
| 570 | window= 8192 |
| 571 | chksum= None |
| 572 | urgptr= 0 |
| 573 | options= {} |
| 574 | |
| 575 | Returns main.TRUE or main.FALSE on error |
| 576 | """ |
| 577 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 578 | main.log.debug( self.name + ": Building TCP" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 579 | # Set the TCP frame |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 580 | if overGtp: |
| 581 | cmd = 'inner_tcp = TCP( ' |
| 582 | else: |
| 583 | cmd = 'tcp = TCP( ' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 584 | options = [] |
| 585 | for key, value in kwargs.iteritems(): |
| 586 | options.append( str( key ) + "=" + str( value ) ) |
| 587 | cmd += ", ".join( options ) |
| 588 | cmd += ' )' |
| 589 | self.handle.sendline( cmd ) |
| 590 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 591 | response = self.cleanOutput( self.handle.before ) |
| 592 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 593 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 594 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 595 | return main.FALSE |
| 596 | if str( ipVersion ) is '4': |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 597 | if overGtp: |
| 598 | self.handle.sendline( "packet = ether/ip/udp/gtp/inner_ip/inner_tcp" ) |
| 599 | else: |
| 600 | self.handle.sendline( "packet = ether/ip/tcp" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 601 | elif str( ipVersion ) is '6': |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 602 | if overGtp: |
| 603 | self.handle.sendline( "packet = ether/ipv6/udp/gtp/inner_ipv6/inner_tcp" ) |
| 604 | else: |
| 605 | self.handle.sendline( "packet = ether/ipv6/tcp" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 606 | else: |
| 607 | main.log.error( "Unrecognized option for ipVersion, given " + |
| 608 | repr( ipVersion ) ) |
| 609 | return main.FALSE |
| 610 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 611 | response = self.cleanOutput( self.handle.before ) |
| 612 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 613 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 614 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 615 | return main.FALSE |
| 616 | return main.TRUE |
| 617 | except pexpect.TIMEOUT: |
| 618 | main.log.exception( self.name + ": Command timed out" ) |
| 619 | return main.FALSE |
| 620 | except pexpect.EOF: |
| 621 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 622 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 623 | except Exception: |
| 624 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 625 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 626 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 627 | def buildUDP( self, ipVersion=4, overGtp=False, **kwargs ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 628 | """ |
| 629 | Build an UDP frame |
| 630 | |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 631 | If overGtp is True, it creates an inner UDP frame, in this case ipVersion |
| 632 | signals the IP version of both outer and inner headers. |
| 633 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 634 | Will create a frame class with the given options. If a field is |
| 635 | left blank it will default to the below value unless it is |
| 636 | overwritten by the next frame. |
| 637 | |
| 638 | NOTE: Some arguments require quotes around them. It's up to you to |
| 639 | know which ones and to add them yourself. Arguments with an asterisk |
| 640 | do not need quotes. |
| 641 | |
| 642 | Options: |
| 643 | ipVersion - Either 4 (default) or 6, indicates what Internet Protocol |
| 644 | frame to use to encapsulate into |
| 645 | Default frame: |
| 646 | ###[ UDP ]### |
| 647 | sport= domain * |
| 648 | dport= domain * |
| 649 | len= None |
| 650 | chksum= None |
| 651 | |
| 652 | Returns main.TRUE or main.FALSE on error |
| 653 | """ |
| 654 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 655 | main.log.debug( self.name + ": Building UDP Frame" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 656 | # Set the UDP frame |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 657 | if overGtp: |
| 658 | cmd = 'inner_udp = UDP( ' |
| 659 | else: |
| 660 | cmd = 'udp = UDP( ' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 661 | options = [] |
| 662 | for key, value in kwargs.iteritems(): |
| 663 | options.append( str( key ) + "=" + str( value ) ) |
| 664 | cmd += ", ".join( options ) |
| 665 | cmd += ' )' |
| 666 | self.handle.sendline( cmd ) |
| 667 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 668 | response = self.cleanOutput( self.handle.before ) |
| 669 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 670 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 671 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 672 | return main.FALSE |
| 673 | if str( ipVersion ) is '4': |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 674 | if overGtp: |
| 675 | self.handle.sendline( "packet = ether/ip/udp/gtp/inner_ip/inner_udp" ) |
| 676 | else: |
| 677 | self.handle.sendline( "packet = ether/ip/udp" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 678 | elif str( ipVersion ) is '6': |
Daniele Moro | e0609fb | 2021-08-30 17:50:20 +0200 | [diff] [blame] | 679 | if overGtp: |
| 680 | self.handle.sendline( "packet = ether/ipv6/udp/gtp/inner_ipv6/inner_udp" ) |
| 681 | else: |
| 682 | self.handle.sendline( "packet = ether/ipv6/udp" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 683 | else: |
| 684 | main.log.error( "Unrecognized option for ipVersion, given " + |
| 685 | repr( ipVersion ) ) |
| 686 | return main.FALSE |
| 687 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 688 | response = self.cleanOutput( self.handle.before ) |
| 689 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 690 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 691 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 692 | return main.FALSE |
| 693 | return main.TRUE |
| 694 | except pexpect.TIMEOUT: |
| 695 | main.log.exception( self.name + ": Command timed out" ) |
| 696 | return main.FALSE |
| 697 | except pexpect.EOF: |
| 698 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 699 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 700 | except Exception: |
| 701 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 702 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 703 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 704 | def buildSCTP( self, ipVersion=4, **kwargs ): |
| 705 | """ |
| 706 | Build an SCTP frame |
| 707 | |
| 708 | Will create a frame class with the given options. If a field is |
| 709 | left blank it will default to the below value unless it is |
| 710 | overwritten by the next frame. |
| 711 | |
| 712 | NOTE: Some arguments require quotes around them. It's up to you to |
| 713 | know which ones and to add them yourself. Arguments with an asterisk |
| 714 | do not need quotes. |
| 715 | |
| 716 | Options: |
| 717 | ipVersion - Either 4 (default) or 6, indicates what Internet Protocol |
| 718 | frame to use to encapsulate into |
| 719 | Default frame: |
| 720 | ###[ SCTP ]### |
| 721 | sport= domain * |
| 722 | dport= domain * |
| 723 | tag = None |
| 724 | chksum = None |
| 725 | |
| 726 | Returns main.TRUE or main.FALSE on error |
| 727 | """ |
| 728 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 729 | main.log.debug( self.name + ": Building SCTP Frame" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 730 | # Set the SCTP frame |
| 731 | cmd = 'sctp = SCTP( ' |
| 732 | options = [ ] |
| 733 | for key, value in kwargs.iteritems( ): |
| 734 | options.append( str( key ) + "=" + str( value ) ) |
| 735 | cmd += ", ".join( options ) |
| 736 | cmd += ' )' |
| 737 | self.handle.sendline( cmd ) |
| 738 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 739 | response = self.cleanOutput( self.handle.before ) |
| 740 | if "Traceback" in response: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 741 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 742 | main.log.error( "Error in sending command: " + response ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 743 | return main.FALSE |
| 744 | if str( ipVersion ) is '4': |
| 745 | self.handle.sendline( "packet = ether/ip/sctp" ) |
| 746 | elif str( ipVersion ) is '6': |
| 747 | self.handle.sendline( "packet = ether/ipv6/sctp" ) |
| 748 | else: |
| 749 | main.log.error( "Unrecognized option for ipVersion, given " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 750 | repr( ipVersion ) ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 751 | return main.FALSE |
| 752 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 753 | response = self.cleanOutput( self.handle.before ) |
| 754 | if "Traceback" in response: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 755 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 756 | main.log.error( "Error in sending command: " + response ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 757 | return main.FALSE |
| 758 | return main.TRUE |
| 759 | except pexpect.TIMEOUT: |
| 760 | main.log.exception( self.name + ": Command timed out" ) |
| 761 | return main.FALSE |
| 762 | except pexpect.EOF: |
| 763 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 764 | main.cleanAndExit() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 765 | except Exception: |
| 766 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 767 | main.cleanAndExit() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 768 | |
| 769 | def buildARP( self, **kwargs ): |
| 770 | """ |
| 771 | Build an ARP frame |
| 772 | |
| 773 | Will create a frame class with the given options. If a field is |
| 774 | left blank it will default to the below value unless it is |
| 775 | overwritten by the next frame. |
| 776 | |
| 777 | NOTE: Some arguments require quotes around them. It's up to you to |
| 778 | know which ones and to add them yourself. Arguments with an asterisk |
| 779 | do not need quotes. |
| 780 | |
| 781 | Default frame: |
| 782 | ###[ ARP ]### |
| 783 | hwtype : XShortField = (1) |
| 784 | ptype : XShortEnumField = (2048) |
| 785 | hwlen : ByteField = (6) |
| 786 | plen : ByteField = (4) |
| 787 | op : ShortEnumField = (1) |
| 788 | hwsrc : ARPSourceMACField = (None) |
| 789 | psrc : SourceIPField = (None) |
| 790 | hwdst : MACField = ('00:00:00:00:00:00') |
| 791 | pdst : IPField = ('0.0.0.0') |
| 792 | |
| 793 | Returns main.TRUE or main.FALSE on error |
| 794 | """ |
| 795 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 796 | main.log.debug( self.name + ": Building ARP Frame" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 797 | # Set the ARP frame |
| 798 | cmd = 'arp = ARP( ' |
| 799 | options = [] |
| 800 | for key, value in kwargs.iteritems( ): |
| 801 | if isinstance( value, str ): |
| 802 | value = '"' + value + '"' |
| 803 | options.append( str( key ) + "=" + str( value ) ) |
| 804 | cmd += ", ".join( options ) |
| 805 | cmd += ' )' |
| 806 | self.handle.sendline( cmd ) |
| 807 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 808 | response = self.cleanOutput( self.handle.before ) |
| 809 | if "Traceback" in response: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 810 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 811 | main.log.error( "Error in sending command: " + response ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 812 | return main.FALSE |
| 813 | self.handle.sendline( "packet = ether/arp" ) |
| 814 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 815 | response = self.cleanOutput( self.handle.before ) |
| 816 | if "Traceback" in response: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 817 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 818 | main.log.error( "Error in sending command: " + response ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 819 | return main.FALSE |
| 820 | return main.TRUE |
| 821 | except pexpect.TIMEOUT: |
| 822 | main.log.exception( self.name + ": Command timed out" ) |
| 823 | return main.FALSE |
| 824 | except pexpect.EOF: |
| 825 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 826 | main.cleanAndExit() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 827 | except Exception: |
| 828 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 829 | main.cleanAndExit() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 830 | |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 831 | def buildICMP( self, ipVersion=4, vlan=False, **kwargs ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 832 | """ |
| 833 | Build an ICMP frame |
| 834 | |
| 835 | Will create a frame class with the given options. If a field is |
| 836 | left blank it will default to the below value unless it is |
| 837 | overwritten by the next frame. |
| 838 | Default frame: |
| 839 | ###[ ICMP ]### |
| 840 | type= echo-request |
| 841 | code= 0 |
| 842 | chksum= None |
| 843 | id= 0x0 |
| 844 | seq= 0x0 |
| 845 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 846 | Options: |
| 847 | ipVersion - Either 4 (default) or 6, indicates what Internet Protocol |
| 848 | frame to use to encapsulate into |
| 849 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 850 | Returns main.TRUE or main.FALSE on error |
| 851 | """ |
| 852 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 853 | main.log.debug( self.name + ": Building ICMP Frame" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 854 | # Set the ICMP frame |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 855 | if str( ipVersion ) is '4': |
| 856 | cmd = 'icmp = ICMP( ' |
| 857 | elif str( ipVersion ) is '6': |
| 858 | cmd = 'icmp6 = ICMPv6EchoReply( ' |
| 859 | else: |
| 860 | main.log.error( "Unrecognized option for ipVersion, given " + |
| 861 | repr( ipVersion ) ) |
| 862 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 863 | options = [] |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 864 | for key, value in kwargs.iteritems( ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 865 | if isinstance( value, str ): |
| 866 | value = '"' + value + '"' |
| 867 | options.append( str( key ) + "=" + str( value ) ) |
| 868 | cmd += ", ".join( options ) |
| 869 | cmd += ' )' |
| 870 | self.handle.sendline( cmd ) |
| 871 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 872 | response = self.cleanOutput( self.handle.before ) |
| 873 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 874 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 875 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 876 | return main.FALSE |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 877 | if vlan: |
| 878 | if str( ipVersion ) is '4': |
| 879 | self.handle.sendline( "packet = ether/vlan/ip/icmp" ) |
| 880 | elif str( ipVersion ) is '6': |
| 881 | self.handle.sendline( "packet = ether/vlan/ipv6/icmp6" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 882 | else: |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 883 | if str( ipVersion ) is '4': |
| 884 | self.handle.sendline( "packet = ether/ip/icmp" ) |
| 885 | elif str( ipVersion ) is '6': |
| 886 | self.handle.sendline( "packet = ether/ipv6/icmp6" ) |
| 887 | else: |
| 888 | main.log.error( "Unrecognized option for ipVersion, given " + |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 889 | repr( ipVersion ) ) |
Siddesh | d984084 | 2021-08-06 19:26:05 +0000 | [diff] [blame] | 890 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 891 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 892 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 893 | response = self.cleanOutput( self.handle.before ) |
| 894 | if "Traceback" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 895 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 896 | main.log.error( "Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 897 | return main.FALSE |
| 898 | return main.TRUE |
| 899 | except pexpect.TIMEOUT: |
| 900 | main.log.exception( self.name + ": Command timed out" ) |
| 901 | return main.FALSE |
| 902 | except pexpect.EOF: |
| 903 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 904 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 905 | except Exception: |
| 906 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 907 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 908 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 909 | def clearBuffer( self, debug=False ): |
| 910 | """ |
| 911 | Keep reading from buffer until its empty |
| 912 | Everything seems to be printed twice in newer versions of |
| 913 | scapy, even when turning off fancy output |
| 914 | """ |
| 915 | i = 0 |
| 916 | response = '' |
| 917 | while True: |
| 918 | try: |
| 919 | i += 1 |
| 920 | # clear buffer |
| 921 | if debug: |
| 922 | main.log.warn( "%s expect loop iteration" % i ) |
Jon Hall | 627b157 | 2020-12-01 12:01:15 -0800 | [diff] [blame] | 923 | self.handle.expect( self.scapyPrompt, timeout=5 ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 924 | response += self.cleanOutput( self.handle.before, debug ) |
| 925 | except pexpect.TIMEOUT: |
| 926 | return response |
| 927 | |
| 928 | def sendPacket( self, iface=None, packet=None, timeout=1, debug=True ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 929 | """ |
| 930 | Send a packet with either the given scapy packet command, or use the |
| 931 | packet saved in the variable 'packet'. |
| 932 | |
| 933 | Examples of a valid string for packet: |
| 934 | |
| 935 | Simple IP packet |
| 936 | packet='Ether(dst="a6:d9:26:df:1d:4b")/IP(dst="10.0.0.2")' |
| 937 | |
| 938 | A Ping with two vlan tags |
| 939 | packet='Ether(dst='ff:ff:ff:ff:ff:ff')/Dot1Q(vlan=1)/Dot1Q(vlan=10)/ |
| 940 | IP(dst='255.255.255.255', src='192.168.0.1')/ICMP()' |
| 941 | |
| 942 | Returns main.TRUE or main.FALSE on error |
| 943 | """ |
| 944 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 945 | main.log.debug( self.name + ": Sending Packet" ) |
| 946 | if debug: |
| 947 | self.handle.sendline( "packet.summary()" ) |
| 948 | self.handle.expect( self.scapyPrompt ) |
| 949 | self.clearBuffer() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 950 | # TODO: add all params, or use kwargs |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 951 | sendCmd = 'sendp( ' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 952 | if packet: |
| 953 | sendCmd += packet |
| 954 | else: |
| 955 | sendCmd += "packet" |
| 956 | if iface: |
| 957 | sendCmd += ", iface='{}'".format( iface ) |
| 958 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 959 | if debug: |
| 960 | sendCmd += ', return_packets=True).summary()' # show packet(s) sent |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 961 | self.handle.sendline( sendCmd ) |
| 962 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 963 | response = self.cleanOutput( self.handle.before ) |
| 964 | main.log.debug( self.name + ": Send packet response: {}".format( response ) ) |
Jon Hall | 50a0001 | 2021-03-08 11:06:11 -0800 | [diff] [blame] | 965 | if "Traceback" in response or "Errno" in response or "Error" in response: |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 966 | # KeyError, SyntaxError, ... |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 967 | main.log.error( self.name + ": Error in sending command: " + response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 968 | return main.FALSE |
| 969 | # TODO: Check # of packets sent? |
| 970 | return main.TRUE |
| 971 | except pexpect.TIMEOUT: |
| 972 | main.log.exception( self.name + ": Command timed out" ) |
| 973 | return main.FALSE |
| 974 | except pexpect.EOF: |
| 975 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 976 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 977 | except Exception: |
| 978 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 979 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 980 | |
| 981 | def startFilter( self, ifaceName=None, sniffCount=1, pktFilter="ip" ): |
| 982 | """ |
| 983 | Listen for packets using the given filters |
| 984 | |
| 985 | Options: |
| 986 | ifaceName - the name of the interface to listen on. If none is given, |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 987 | defaults to self.ifaceName which is <host name>-eth0 |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 988 | pktFilter - A string in Berkeley Packet Filter (BPF) format which |
| 989 | specifies which packets to sniff |
| 990 | sniffCount - The number of matching packets to capture before returning |
| 991 | |
| 992 | Returns main.TRUE or main.FALSE on error |
| 993 | """ |
| 994 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 995 | main.log.info( self.name + ": Starting filter on interface %s" % ifaceName ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 996 | # TODO: add all params, or use kwargs |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 997 | ifaceName = str( ifaceName ) if ifaceName else self.ifaceName |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 998 | # Set interface |
You Wang | bd848ed | 2018-03-23 13:57:42 -0700 | [diff] [blame] | 999 | self.handle.sendline( 'conf.iface = "' + ifaceName + '"' ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1000 | self.handle.expect( ifaceName ) |
| 1001 | self.cleanOutput( self.handle.before + self.handle.after ) |
| 1002 | self.cleanOutput( self.handle.before ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1003 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1004 | response = self.handle.before + self.handle.after |
| 1005 | self.cleanOutput( response ) |
Daniele Moro | a9c0d0b | 2021-09-01 16:56:34 +0200 | [diff] [blame] | 1006 | cmd = 'pkts = sniff(count = %s, iface="%s", filter = "%s", prn=lambda p: p.summary() )' % ( sniffCount, ifaceName, pktFilter ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1007 | main.log.info( self.name + ": Starting filter on " + self.name + ' > ' + cmd ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1008 | self.handle.sendline( cmd ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1009 | response = self.clearBuffer() |
| 1010 | |
You Wang | 3a5f74c | 2018-08-03 14:58:15 -0700 | [diff] [blame] | 1011 | # Make sure the sniff function didn't exit due to failures |
| 1012 | i = self.handle.expect( [ self.scapyPrompt, pexpect.TIMEOUT ], timeout=3 ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1013 | response = self.cleanOutput( self.handle.before + str( self.handle.after ) ) |
You Wang | 3a5f74c | 2018-08-03 14:58:15 -0700 | [diff] [blame] | 1014 | if i == 0: |
| 1015 | # sniff exited |
| 1016 | main.log.error( self.name + ": sniff function exited" ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1017 | main.log.error( self.name + ": " + response ) |
You Wang | 3a5f74c | 2018-08-03 14:58:15 -0700 | [diff] [blame] | 1018 | return main.FALSE |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1019 | return main.TRUE |
| 1020 | except pexpect.TIMEOUT: |
| 1021 | main.log.exception( self.name + ": Command timed out" ) |
| 1022 | return main.FALSE |
| 1023 | except pexpect.EOF: |
| 1024 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1025 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1026 | except Exception: |
| 1027 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1028 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1029 | |
| 1030 | def checkFilter( self, timeout=10 ): |
| 1031 | """ |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1032 | Check if a filter is still running. |
| 1033 | Returns: |
| 1034 | main.TRUE if the filter stopped |
| 1035 | main.FALSE if the filter is still running |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1036 | """ |
| 1037 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1038 | main.log.debug( self.name + ": Checking Filter" ) |
| 1039 | self.handle.sendline( "" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1040 | i = self.handle.expect( [ self.scapyPrompt, pexpect.TIMEOUT ], timeout=timeout ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1041 | response = self.cleanOutput( self.handle.before + str( self.handle.after ), debug=True ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1042 | if i == 0: |
| 1043 | return main.TRUE |
| 1044 | else: |
| 1045 | return main.FALSE |
| 1046 | except pexpect.EOF: |
| 1047 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1048 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1049 | except Exception: |
| 1050 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1051 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1052 | |
| 1053 | def killFilter( self ): |
| 1054 | """ |
| 1055 | Kill a scapy filter |
| 1056 | """ |
| 1057 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1058 | main.log.debug( self.name + ": Killing scapy filter" ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1059 | self.handle.send( "\x03" ) # Send a ctrl-c to kill the filter |
| 1060 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1061 | output = self.cleanOutput( self.handle.before, debug=True ) |
| 1062 | return output |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1063 | except pexpect.TIMEOUT: |
| 1064 | main.log.exception( self.name + ": Command timed out" ) |
| 1065 | return None |
| 1066 | except pexpect.EOF: |
| 1067 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1068 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1069 | except Exception: |
| 1070 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1071 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1072 | |
You Wang | 548db38 | 2020-08-12 09:17:13 -0700 | [diff] [blame] | 1073 | def readPackets( self, detailed=False ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1074 | """ |
| 1075 | Read all the packets captured by the previous filter |
| 1076 | """ |
| 1077 | try: |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1078 | main.log.debug( self.name + ": Reading Packets" ) |
| 1079 | main.log.debug( self.name + ": Begin clear buffer" ) |
| 1080 | self.clearBuffer() |
| 1081 | main.log.debug( self.name + ": end clear buffer" ) |
| 1082 | |
You Wang | 548db38 | 2020-08-12 09:17:13 -0700 | [diff] [blame] | 1083 | if detailed: |
| 1084 | self.handle.sendline( "[p for p in pkts]") |
| 1085 | else: |
| 1086 | self.handle.sendline( "pkts.summary()") |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1087 | output = self.clearBuffer() |
Jon Hall | 50a0001 | 2021-03-08 11:06:11 -0800 | [diff] [blame] | 1088 | if "Traceback" in output or "Errno" in output or "Error" in output: |
| 1089 | # KeyError, SyntaxError, IOError, NameError, ... |
| 1090 | main.log.error( self.name + ": Error in sending command: " + output ) |
| 1091 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1092 | except pexpect.TIMEOUT: |
| 1093 | main.log.exception( self.name + ": Command timed out" ) |
| 1094 | return None |
| 1095 | except pexpect.EOF: |
| 1096 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1097 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1098 | except Exception: |
| 1099 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1100 | main.cleanAndExit() |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1101 | return output |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1102 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1103 | def updateSelf( self, IPv6=False ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1104 | """ |
| 1105 | Updates local MAC and IP fields |
| 1106 | """ |
| 1107 | self.hostMac = self.getMac() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1108 | if IPv6: |
| 1109 | self.hostIp = self.getIp( IPv6=True ) |
| 1110 | else: |
| 1111 | self.hostIp = self.getIp() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1112 | |
| 1113 | def getMac( self, ifaceName=None ): |
| 1114 | """ |
| 1115 | Save host's MAC address |
| 1116 | """ |
| 1117 | try: |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 1118 | ifaceName = str( ifaceName ) if ifaceName else self.ifaceName |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1119 | cmd = 'get_if_hwaddr("' + str( ifaceName ) + '")' |
| 1120 | self.handle.sendline( cmd ) |
| 1121 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1122 | response = self.cleanOutput( self.handle.before ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1123 | pattern = r'(([0-9a-f]{2}[:-]){5}([0-9a-f]{2}))' |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1124 | match = re.search( pattern, response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1125 | if match: |
| 1126 | return match.group() |
| 1127 | else: |
| 1128 | # the command will have an exception if iface doesn't exist |
| 1129 | return None |
| 1130 | except pexpect.TIMEOUT: |
| 1131 | main.log.exception( self.name + ": Command timed out" ) |
| 1132 | return None |
| 1133 | except pexpect.EOF: |
| 1134 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1135 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1136 | except Exception: |
| 1137 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1138 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1139 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1140 | def getIp( self, ifaceName=None, IPv6=False ): |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1141 | """ |
| 1142 | Save host's IP address |
| 1143 | |
| 1144 | Returns the IP of the first interface that is not a loopback device. |
| 1145 | If no IP could be found then it will return 0.0.0.0. |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1146 | |
| 1147 | If IPv6 is equal to True, returns IPv6 of the first interface that is not a loopback device. |
| 1148 | If no IPv6 could be found then it will return :: . |
| 1149 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1150 | """ |
| 1151 | def getIPofInterface( ifaceName ): |
| 1152 | cmd = 'get_if_addr("' + str( ifaceName ) + '")' |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1153 | if IPv6: |
| 1154 | cmd = 'get_if_raw_addr6("' + str( ifaceName ) + '")' |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1155 | self.handle.sendline( cmd ) |
| 1156 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1157 | response = self.cleanOutput( self.handle.before ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1158 | |
| 1159 | pattern = r'(((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))' |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1160 | if IPv6: |
| 1161 | pattern = r'(\\x([0-9]|[a-f]|[A-F])([0-9]|[a-f]|[A-F])){16}' |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1162 | match = re.search( pattern, response ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1163 | if match: |
| 1164 | # NOTE: The command will return 0.0.0.0 if the iface doesn't exist |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1165 | if IPv6 is not True: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1166 | if match.group() == '0.0.0.0': |
| 1167 | main.log.warn( 'iface {0} has no IPv4 address'.format( ifaceName ) ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1168 | return match.group() |
| 1169 | else: |
| 1170 | return None |
| 1171 | try: |
| 1172 | if not ifaceName: |
| 1173 | # Get list of interfaces |
| 1174 | ifList = self.getIfList() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1175 | if IPv6: |
| 1176 | for ifaceName in ifList: |
| 1177 | if ifaceName == "lo": |
| 1178 | continue |
| 1179 | ip = getIPofInterface( ifaceName ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1180 | if ip is not None: |
| 1181 | newip = ip |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1182 | tmp = newip.split( "\\x" ) |
| 1183 | ip = "" |
| 1184 | counter = 0 |
| 1185 | for i in tmp: |
| 1186 | if i != "": |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1187 | counter = counter + 1 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1188 | if counter % 2 == 0 and counter < 16: |
| 1189 | ip = ip + i + ":" |
| 1190 | else: |
| 1191 | ip = ip + i |
| 1192 | return ip |
| 1193 | return "::" |
| 1194 | else: |
| 1195 | for ifaceName in ifList: |
| 1196 | if ifaceName == "lo": |
| 1197 | continue |
| 1198 | ip = getIPofInterface( ifaceName ) |
| 1199 | if ip != "0.0.0.0": |
| 1200 | return ip |
| 1201 | return "0.0.0.0" |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1202 | else: |
| 1203 | return getIPofInterface( ifaceName ) |
| 1204 | |
| 1205 | except pexpect.TIMEOUT: |
| 1206 | main.log.exception( self.name + ": Command timed out" ) |
| 1207 | return None |
| 1208 | except pexpect.EOF: |
| 1209 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1210 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1211 | except Exception: |
| 1212 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1213 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1214 | |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1215 | def addRoute( self, network, gateway, interface=None ): |
| 1216 | """ |
| 1217 | Add a route to the current scapy session |
| 1218 | """ |
| 1219 | main.log.info( self.name + ": Adding route to scapy session; %s via %s out of interface %s" % ( network, gateway, interface ) ) |
| 1220 | if gateway is None: |
| 1221 | main.log.error( self.name + ": Gateway is None, cannot set route" ) |
| 1222 | return main.FALSE |
Jon Hall | 06fd0df | 2021-01-25 15:50:06 -0800 | [diff] [blame] | 1223 | if network is None or "None" in network: |
| 1224 | main.log.error( self.name + ": Network is None, cannot set route" ) |
| 1225 | return main.FALSE |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1226 | try: |
| 1227 | cmdStr = 'conf.route.add( net="%s", gw="%s"' % ( network, gateway ) |
| 1228 | if interface: |
| 1229 | cmdStr += ', dev="%s"' % interface |
| 1230 | cmdStr += ')' |
| 1231 | self.handle.sendline( cmdStr ) |
| 1232 | self.handle.expect( self.scapyPrompt ) |
| 1233 | response = self.cleanOutput( self.handle.before ) |
| 1234 | if "Traceback" in response: |
| 1235 | main.log.error( self.name + ": Error in adding route to scappy session" ) |
| 1236 | main.log.debug( response ) |
| 1237 | return main.FALSE |
| 1238 | return main.TRUE |
| 1239 | except pexpect.TIMEOUT: |
| 1240 | main.log.exception( self.name + ": Command timed out" ) |
| 1241 | return None |
| 1242 | except pexpect.EOF: |
| 1243 | main.log.exception( self.name + ": connection closed." ) |
| 1244 | main.cleanAndExit() |
| 1245 | except Exception: |
| 1246 | main.log.exception( self.name + ": Uncaught exception!" ) |
| 1247 | main.cleanAndExit() |
| 1248 | |
| 1249 | def addRoutes( self ): |
| 1250 | """ |
| 1251 | Add any routes configured for the host |
| 1252 | """ |
| 1253 | returnValues = [] |
| 1254 | for route in self.routes: |
| 1255 | gw = route.get( 'gw' ) |
| 1256 | iface = route.get( 'interface' ) |
| 1257 | returnValues .append( self.addRoute( "%s/%s" % ( route.get( 'network' ), route.get( 'netmask' ) ), |
Jon Hall | 50a0001 | 2021-03-08 11:06:11 -0800 | [diff] [blame] | 1258 | gw if gw else main.Cluster.active(0).address, |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1259 | interface=iface if iface else self.interfaces[ 0 ].get( 'name' ) ) ) |
| 1260 | return returnValues |
| 1261 | |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1262 | def getIfList( self ): |
| 1263 | """ |
| 1264 | Return List of Interfaces |
| 1265 | """ |
| 1266 | try: |
| 1267 | self.handle.sendline( 'get_if_list()' ) |
| 1268 | self.handle.expect( self.scapyPrompt ) |
Jon Hall | 43060f6 | 2020-06-23 13:13:33 -0700 | [diff] [blame] | 1269 | response = self.cleanOutput( self.handle.before ) |
| 1270 | ifList = response.split( '\r\n' ) |
Jeremy Ronquillo | 8270549 | 2017-10-18 14:19:55 -0700 | [diff] [blame] | 1271 | ifList = ifList[ 1 ].replace( "'", "" )[ 1:-1 ].split( ', ' ) |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1272 | return ifList |
| 1273 | |
| 1274 | except pexpect.TIMEOUT: |
| 1275 | main.log.exception( self.name + ": Command timed out" ) |
| 1276 | return None |
| 1277 | except pexpect.EOF: |
| 1278 | main.log.exception( self.name + ": connection closed." ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1279 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1280 | except Exception: |
| 1281 | main.log.exception( self.name + ": Uncaught exception!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1282 | main.cleanAndExit() |
Jeremy Songster | 1f39bf0 | 2016-01-20 17:17:25 -0800 | [diff] [blame] | 1283 | |
| 1284 | if __name__ != "__main__": |
| 1285 | sys.modules[ __name__ ] = ScapyCliDriver() |