Esempio n. 1
0
def test(server, service, event):
    session=Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id;
    se.teamserverid = server.id;
    se.scoretime = datetime.now()
    se.eventid = event
    try:
        imap = imaplib.IMAP4_SSL(server.getIP())
        conf = utils.getServiceConfig(session, service, server)
        if 'passdb' not in conf:
            logger.warning("Service %i is not configured" % service.id)
            session.close()
            return
        user = utils.getRandomUser(session, conf['passdb'])
        r = imap.login(user['email'], user['pass'])
        if r[0] == 'OK':
            se.up = True
        else:
            se.up = False
        try:
            imap.close()
        except Exception as ep2:
            pass
    except Exception as ep:
        se.info = ep.message
        se.up = False
    session.add(se)
    session.commit()
    session.close()
Esempio n. 2
0
def test(server, service, event):
    #raise NotImplementedError();
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event
    ssh = paramiko.SSHClient()
    try:
        conf = utils.getServiceConfig(session, service, server)
        if 'passdb' not in conf:
            logger.warning("Service %i is not configured" % service.id)
            ssh.close()
            session.close()
            return
        user = utils.getRandomUser(session, conf['passdb'])
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(server.getIP(),
                    username=user['user'],
                    password=user['pass'])
        ssh.exec_command("ping -c 4 8.8.8.8")
        se.up = True
    except Exception as e:
        se.info = e.message
        se.up = False
    finally:
        ssh.close()
    session.add(se)
    session.commit()
    session.close()
Esempio n. 3
0
def test(server, service, event):
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event
    smtp = smtplib.SMTP()
    try:
        #smtp = smtplib.SMTP(server.getIP(), service.port)
        smtp.connect(server.getIP(), service.port)
        smtp.starttls()
        conf = utils.getServiceConfig(session, service, server)
        if 'passdb' not in conf:
            logger.warning("Service %i is not configured" % service.id)
            session.close()
            return
        user = utils.getRandomUser(session, conf['passdb'])
        r = smtp.login(user['email'], user['pass'])
        to_email = utils.getRandomEmail(session, conf['passdb'])
        smtp.sendmail(user['email'], to_email, "This is the test ")
        se.up = True

        #se.info = smtp.ehlo_msg
    except Exception as ep:
        se.info = ep.message
        se.up = False
    finally:
        try:
            smtp.close()
        except Exception as ep:
            pass
    session.add(se)
    session.commit()
    session.close()
Esempio n. 4
0
def test(server, service, event):
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event
    br = mechanize.Browser()
    try:
        url = "http://" + server.getIP()
        conf = ScoringEngine.utils.getServiceConfig(session, service, server)
        if 'url' in conf:
            url += conf['url']
        br.set_handle_robots(False)
        res = br.open(url)
        contents = res.read()
        if "regex" in conf and conf['regex'].strip() != "":
            import re
            if re.search(conf['regex'], contents) is None:
                se.up = False
            else:
                se.up = True
        else:
            se.up = True

    except Exception as e:
        se.info = e.message
        se.up = False
    finally:
        br.close()
    session.add(se)
    session.commit()
    session.close()
Esempio n. 5
0
def test(server, service, event):
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event
    ftp = ftplib.FTP()
    try:
        #ftp = ftplib.FTP(server.getIP())
        ftp.connect(server.getIP())
        conf = ScoringEngine.utils.getServiceConfig(session, service, server)
        if 'passdb' not in conf:
            logger.warning("Service %i is not configured" % service.id)
            session.close()
            return
        user = utils.getRandomUser(session, conf['passdb'])
        ftp.login(user['user'], user['pass'])

        if 'mode' in conf and conf['mode'] != 'connect':
            path = conf['path']
            if conf['mode'] == 'chkfileexist':
                pass
        else:
            se.up = True
            se.info = ftp.nlst()
    except ftplib.error_perm as ep:
        se.info = ep.message
        se.up = False
    finally:
        ftp.close()
    session.add(se)
    session.commit()
    session.close()
Esempio n. 6
0
def test(server, service, event):
    #raise NotImplementedError();
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event

    try:
        conf = ScoringEngine.utils.getServiceConfig(session, service, server)
        if 'passdb' not in conf or 'share' not in conf or 'path' not in conf or 'file' not in conf or 'remote_name' not in conf:
            logger.warning("No configuration for service %i", service.id)
            session.close()
            return
        user = ScoringEngine.utils.getRandomUser(session, conf['passdb'])
        conn = SMBConnection(user['user'].encode('ascii', 'ignore'),
                             user['pass'].encode('ascii', 'ignore'),
                             'LepusISE'.encode('ascii', 'ignore'),
                             conf['remote_name'].encode('ascii', 'ignore'),
                             user['domain'].encode('ascii', 'ignore'),
                             is_direct_tcp=service.port == 445)
        if conn.connect(server.getIP().encode('ascii', 'ignore'),
                        service.port):
            if 'regex' not in conf or conf['regex'].strip() == "":
                files = conn.listPath(conf['share'], conf['path'])
                for file in files:
                    if file.filename == conf['file']:
                        se.up = True
                        se.info = json.dumps([file.filename for file in files])
                        break
            else:
                import re
                import tempfile
                file_obj = tempfile.NamedTemporaryFile()
                file_attr, filesize = conn.retrieveFile(
                    conf['share'], conf['path'] + "/" + conf['file'], file_obj)
                file_obj.seek(0)
                content = file_obj.read()
                file_obj.close()
                if re.search(conf['regex'], content) is None:
                    se.up = False
                else:
                    se.up = True
        else:
            se.up = False
        conn.close()
    except Exception as e:
        se.up = False
        se.info = e.message
    session.add(se)
    session.commit()
    session.close()
Esempio n. 7
0
def test(server, service, event):
    session=Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id;
    se.teamserverid = server.id;
    se.scoretime = datetime.now()
    se.eventid = event
    try:
        r = utils.Ping(server.getIP(), 5)
        if r:
            se.up = True
            se.info = json.dumps({'trip': r})
        else:
            se.up = False
    except Exception as e:
        se.info = e.message
        se.up = False
    session.add(se)
    session.commit()
    session.close()
Esempio n. 8
0
def test(server, service, event):
    #raise NotImplementedError();
    session=Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id;
    se.teamserverid = server.id;
    se.scoretime = datetime.now()
    se.eventid = event
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect((server.getIP(), service.port))
        se.up = True
        #se.info = s.recv(1024)
    except Exception as e:
        se.info = e.message
        se.up = False
    finally:
        s.close()
    session.add(se)
    session.commit()
    session.close()
Esempio n. 9
0
def test(server, service, event):
    session = Session()
    se = tables.ScoreEvent()
    se.serviceid = service.id
    se.teamserverid = server.id
    se.scoretime = datetime.now()
    se.eventid = event
    try:
        conf = ScoringEngine.utils.getServiceConfig(session, service, server)
        if 'servers' not in conf:
            logger.warning("No servers configured for service %i" % service.id)
            session.close()
            return
        servers = conf['servers']
        ser = random.choice(servers)
        dnsentry = ser['dns']
        ip = ser['ip']
        sp = subprocess.Popen(
            ["nslookup", dnsentry, server.getIP()], stdout=subprocess.PIPE)
        lines = sp.stdout
        sp.wait()
        l = lines.readlines()

        for line in l[2:]:
            if ip in line:
                print line
                se.up = True
                break
            else:
                se.up = False
        se.info = json.dumps(l)
    except Exception as e:
        se.info = e.message
        se.up = False
    finally:
        if not se.up:
            se.up = False
    session.add(se)
    session.commit()
    session.close()