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()
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()
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()
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()
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()
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()
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()
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()
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()
def score(): session = Session() event = None events = session.query(tables.Event).filter(tables.Event.current == True) if events.count() > 0: event = events[0].id logger.info("Score Event: %s" % events[0].name) for server in session.query(tables.TeamServer).all(): if server.server.enabled and server.team.enabled: for service in session.query(tables.Service).filter( tables.and_(tables.Service.serverid == server.server.id, tables.Service.enabled == True)): m = __import__(service.type.tester) func = getattr(m, "test") logger.debug("Score: %s(<%s>, <%s>, <%s>, <%s>)" % (service.type.tester, server.team.name, server.server.name, service.name, event)) threading.Thread(target=func, args=[server, service, event]).start() session.close()
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)
def api_test(): session = Session() events = session.query(tables.Event).all() return dumps([event.seralize() for event in events])