示例#1
0
 def __init__(self, host='localhost', bindingip='', externalip=None, localport=5060,
              method='REGISTER', guessmode=1, guessargs=None, selecttime=0.005,
              sessionpath=None, compact=False, socktimeout=3, initialcheck=True,
              enableack=False, maxlastrecvtime=15, domain=None, printdebug=False,
              ipv6=False, port=5060):
     self.log = logging.getLogger('TakeASip')
     self.maxlastrecvtime = maxlastrecvtime
     self.sessionpath = sessionpath
     self.dbsyncs = False
     self.enableack = enableack
     if self.sessionpath is not None:
         self.resultauth = dbm.open(os.path.join(
             self.sessionpath, 'resultauth'), 'c')
         try:
             self.resultauth.sync()
             self.dbsyncs = True
             self.log.info("Db does sync")
         except AttributeError:
             self.log.info("Db does not sync")
             pass
     else:
         self.resultauth = dict()
     family = socket.AF_INET
     if ipv6:
         family = socket.AF_INET6
     self.sock = socket.socket(family, socket.SOCK_DGRAM)
     self.sock.settimeout(socktimeout)
     self.bindingip = bindingip
     self.localport = localport
     self.ipv6 = ipv6
     self.originallocalport = localport
     self.rlist = [self.sock]
     self.wlist = list()
     self.xlist = list()
     self.challenges = list()
     self.realm = None
     try:
         if int(port) > 1 and int(port) <= 65535:
             self.dsthost, self.dstport = host, int(port)
     except (ValueError, TypeError):
         self.log.error('port should strictly be an integer between 1 and 65535')
         exit(1)
     self.domain = self.dsthost
     if domain:
         self.domain = domain
     self.guessmode = guessmode
     self.guessargs = guessargs
     if self.guessmode == 1:
         self.usernamegen = numericbrute(*self.guessargs)
     elif guessmode == 2:
         self.usernamegen = dictionaryattack(self.guessargs)
     self.selecttime = selecttime
     self.compact = compact
     self.nomore = False
     self.BADUSER = None
     self.method = method.upper()
     if self.method == 'INVITE':
         self.log.warning(
             'using an INVITE scan on an endpoint (i.e. SIP phone) may cause it to ring and wake up people in the middle of the night')
     if self.sessionpath is not None:
         self.packetcount = packetcounter(50)
     self.initialcheck = initialcheck
     self.lastrecvtime = time.time()
     if externalip is None:
         self.log.debug("external ip was not set")
         if (self.bindingip != '0.0.0.0') and (len(self.bindingip) > 0):
             self.log.debug(
                 "but bindingip was set! we'll set it to the binding ip")
             self.externalip = self.bindingip
         else:
             try:
                 self.log.info(
                     "trying to get self ip .. might take a while")
                 self.externalip = socket.gethostbyname(
                     socket.gethostname())
             except socket.error:
                 self.externalip = '127.0.0.1'
     else:
         self.log.debug("external ip was set")
         self.externalip = externalip
     self.printdebug = printdebug
示例#2
0
 def __init__(self, host='localhost', bindingip='', localport=5060, port=5060,
              externalip=None,
              username=None, crackmode=1, crackargs=None, realm=None, sessionpath=None,
              selecttime=0.005, compact=False, reusenonce=False, extension=None,
              maxlastrecvtime=10, domain=None, requesturi=None, method='REGISTER', ipv6=False):
     self.log = logging.getLogger('ASipOfRedWine')
     family = socket.AF_INET
     if ipv6:
         family = socket.AF_INET6
     self.ipv6 = ipv6
     self.sock = socket.socket(family, socket.SOCK_DGRAM)
     self.sock.settimeout(10)
     self.sessionpath = sessionpath
     self.maxlastrecvtime = maxlastrecvtime
     self.lastrecvtime = time.time()
     self.dbsyncs = False
     self.method = method
     if self.sessionpath is not None:
         self.resultpasswd = dbm.open(
             os.path.join(self.sessionpath, 'resultpasswd'), 'c')
         try:
             self.resultpasswd.sync()
             self.dbsyncs = True
             self.log.info("Db does sync")
         except AttributeError:
             self.log.info("Db does not sync")
             pass
     else:
         self.resultpasswd = dict()
     self.nomore = False
     self.passwordcracked = False
     self.rlist = [self.sock]
     self.wlist = list()
     self.xlist = list()
     self.challenges = list()
     self.crackmode = crackmode
     self.crackargs = crackargs
     try:
         if int(port) > 1 and int(port) <= 65535:
             self.dsthost, self.dstport = host, int(port)
     except (ValueError, TypeError):
         self.log.error('port should strictly be an integer between 1 and 65535')
         exit(1)
     self.domain = self.dsthost
     if domain:
         self.domain = domain
     if crackmode == 1:
         self.passwdgen = numericbrute(*crackargs)
     elif crackmode == 2:
         self.passwdgen = dictionaryattack(crackargs)
     self.username = username
     self.realm = realm
     self.selecttime = selecttime
     self.dstisproxy = None
     self.ignorenewnonce = True
     self.noauth = False
     self.auth = dict()
     self.previouspassword = str()
     self.compact = compact
     self.reusenonce = reusenonce
     self.staticnonce = None
     self.staticcid = None
     if extension is not None:
         self.extension = extension
     else:
         self.extension = username
     self.bindingip = bindingip
     self.localport = localport
     self.requesturi = requesturi
     self.noncecount = 1
     self.originallocalport = localport
     if self.sessionpath is not None:
         self.packetcount = packetcounter(50)
     if externalip is None:
         self.log.debug("external ip was not set")
         if (self.bindingip != '0.0.0.0') and (len(self.bindingip) > 0):
             self.log.debug(
                 "but bindingip was set! we'll set it to the binding ip")
             self.externalip = self.bindingip
         else:
             try:
                 self.log.info(
                     "trying to get self ip .. might take a while")
                 self.externalip = socket.gethostbyname(
                     socket.gethostname())
             except socket.error:
                 self.externalip = '127.0.0.1'
     else:
         self.log.debug("external ip was set")
         self.externalip = externalip