Beispiel #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()
Beispiel #2
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()
Beispiel #3
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()
Beispiel #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
    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()
Beispiel #5
0
def validate_env():
    import os, os.path
    from ScoringEngine.core import logger, config
    from ScoringEngine.core.db import Session, tables
    try:
        s = Session()
        logger.debug("Checking if >0 users")
        if s.query(tables.User).count() == 0:
            # We should create the default admin user if there are no users.
            logger.warning("No users found creating default admin account")
            s.add(tables.User.create("Administrator", "admin", u"admin", -1, 5))
            s.commit()

        # refresh scoretype table
        logger.debug("Refreshing scoretypes")
        for d in config.get_item("tests"):
            for f in os.listdir(d):
                if os.path.isfile(os.path.join(d, f)):
                    p = f.split('.')
                    if len(p) > 1 and p[1] == "py":
                        t = s.query(tables.ServiceType).filter(tables.ServiceType.tester == p[0]).first()
                        if not t:
                            logger.debug("Adding type: %s" % p[0])
                            t = tables.ServiceType()
                            t.tester = p[0]
                            t.name = p[0].capitalize()
                            s.add(t)
        s.commit()
        s.close()
    except Exception as e:
        import sys
        print(e)
        print(e.message)
        sys.exit(1)
Beispiel #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()
Beispiel #7
0
def login():
    if request.method == 'POST':
        users = getSession().query(tables.User).filter(
            tables.User.username == request.form['username'])
        for user in users:
            if user.verify_password(request.form['password']):
                logger.debug("Login for " + user.username)
                return do_login(user)
            else:
                logger.warning("Incorrect password for " + user.username)
        return render_template('user/login.html',
                               title='Home Page',
                               year=datetime.now().year,
                               error="User/Password Incorrect")
    return render_template(
        'user/login.html',
        title='Home Page',
        year=datetime.now().year,
    )
Beispiel #8
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()