def test_host(host,user,passwd): """Test the basic auth in host given using usr and pass given. """ try: Log.info("["+host+"] Checking %s/%s" %(user,passwd)) passman = urllib2.HTTPPasswordMgrWithDefaultRealm() passman.add_password(None, host, user, passwd) authhandler = urllib2.HTTPBasicAuthHandler(passman) opener = urllib2.build_opener(authhandler) urllib2.install_opener(opener) source = urllib2.urlopen(host, timeout=5) if len(str(source)) > 0: # Some devices show an html page after a number of tries to avoid bruteforce. We discard those. html = str(source.read()) if html.find('HTTP 401') > 0: Log.warn("["+host+"] HTTP 401 found in html. Possibly false positive. Omitting from output") return -1 # Access granted using admin/admin Log.success("Access granted with "+user+"/"+passwd+" to "+host) outputLock.acquire() output.writelines("<tr><td><a href="+host+" target=\"_blank\">"+host+"</a></td><td>"+user+"</td><td>"+passwd+"</td></tr>") outputLock.release() return -1 # return -1 to stop looking in a host when we have access to. return 0 except Exception, e: Log.err("["+host+"] Error: %s" % e) return 0
def process_ips(threadID, q): while not exitFlag: queueLock.acquire() if not workQueue.empty(): ip = q.get() queueLock.release() host = "http://"+ip Log.info("Thread %s Checking %s" % (threadID, host)) try: source = urllib2.urlopen(host, timeout=1).read() except Exception, e: if str(e).find('401') > 0: check_basic_auth(host) except KeyboardInterrupt: sys.exit()
def setUp(self): # setup logger self.LOG = Log.Logger("tsi.testing") self.config = {'tsi.testing': True, 'tsi.switch_uid': False} TSI.setup_defaults(self.config) self.bss = BSS.BSS() self.bss.init(self.config, self.LOG)
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.bss = lsf.BSS.BSS() self.config = {'tsi.testing': True, # mock submit cmd 'tsi.submit_cmd': "echo 1234.server" } TSI.setup_defaults(self.config) self.bss.init(self.config, self.LOG)
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.config = { 'tsi.my_addr': 'localhost', 'tsi.my_port': 14433, 'tsi.njs_machine': 'localhost', 'tsi.njs_port': None }
def main(argv): try: opts, args = getopt.getopt(argv, "hu:p:s:U:P:I:t:d:v", ["help", "user="******"passwd=", "shodan=", "userfile=", "passfile=", "iplist=", "threads=", "port=", "verbose"]) except getopt.GetoptError: usage() sys.exit(2) global _user global _passwd global _dork global _port global userfile global passfile global ipsfile global th_num _user = '******' # Default user _passwd = 'admin' # Default password _dork = "" _port = 0 th_num = 10 # by default we use 10 threads userfile = "" passfile = "" ipsfile = "" for opt, arg in opts: if opt in ("-h", "--help"): usage() sys.exit() elif opt in ("-u", "--user"): _user = arg elif opt in ("-p", "--passwd"): _passwd = arg elif opt in ("-U", "--userfile"): userfile = arg elif opt in ("-P", "--passfile"): passfile = arg elif opt in ("-s", "--shodan"): _dork = arg elif opt in ("-I", "--iplist"): ipsfile = arg elif opt in ("-t", "--threads"): th_num = int(arg) elif opt in ("-d", "--port"): _port = int(arg) elif opt in ("-v", "--verbose"): Log.debug(1)
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.bss = slurm.BSS.BSS() self.config = { 'tsi.testing': True, # mock submit/alloc cmds 'tsi.submit_cmd': "echo 'Submitted batch job 1234'", 'tsi.alloc_cmd': "echo 'salloc: Granted job allocation 115463'" } TSI.setup_defaults(self.config) self.bss.init(self.config, self.LOG)
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.config = {} self.config = {'tsi.testing': True} self.config['tsi.switch_uid'] = False self.config['tsi.acl'] = {} self.config['tsi.getfacl'] = "getfacl" self.config['tsi.setfacl'] = "setfacl" try: os.mkdir("/tmp/test_TSI_ACL") except: pass
def setUp(self): # setup logger self.LOG = Log.Logger("tsi.testing") self.config = {} self.config['tsi.my_addr'] = 'localhost' self.config['tsi.my_port'] = 14433 self.config['tsi.njs_machine'] = 'localhost' self.config['tsi.njs_port'] = 24433 self.config['tsi.keystore'] = 'tests/certs/tsi-key-plain.pem' self.config['tsi.keypass'] = '******' self.config['tsi.certificate'] = 'tests/certs/tsi-cert.pem' self.config['tsi.truststore'] = 'tests/certs/tsi-truststore.pem' self.config['tsi.allowed_dn.1'] = 'CN=Foo,C=DE' self.config['tsi.allowed_dn.2'] = 'CN=Bar,C=EU'
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.config = {} self.config['tsi.my_addr'] = 'localhost' self.config['tsi.my_port'] = 14433 self.config['tsi.njs_machine'] = 'localhost' self.config['tsi.njs_port'] = 24433 self.config['tsi.keystore'] = 'tests/certs/tsi-key-plain.pem' self.config['tsi.keypass'] = '******' self.config['tsi.certificate'] = 'tests/certs/tsi-cert.pem' self.config['tsi.truststore'] = 'tests/certs/tsi-truststore.pem' self.config['tsi.allowed_dns'] = [ SSL.convert_dn('CN=TSI,O=UNICORE,C=EU') ]
def __init__(self): """ pass """ global scheme, host, port, timeout scheme = loacalReadConfig.get_http('scheme') host = loacalReadConfig.get_http('baseurl') port = loacalReadConfig.get_http('port') timeout = loacalReadConfig.get_http('timeout') self.log = Log.MyLog().get_log() self.logger = self.log.get_logger() self.headers = {} self.params = {} self.data = {} self.url = None self.files = {} self.state = 0 self.session = requests.Session()
def test_RunMain(self): config = "tests/conf/tsi.properties" pid = os.fork() if pid == 0: # child, this is the TSI shepherd process TSI.main(["TSI", config]) else: # parent, this is the fake XNJS LOG = Log.Logger("fake-xnjs") time.sleep(2) client_config = TSI.read_config_file(config, LOG) # connect to the server host = client_config['tsi.my_addr'] port = int(client_config['tsi.my_port']) tsi = socket.create_connection((host, port)) LOG.info("CLIENT: Connected to %s:%s" % (host, port)) host = client_config['tsi.njs_machine'] port = int(client_config['tsi.njs_port']) tsi.sendall(b'newtsiprocess 24433') LOG.info("CLIENT: waiting for callback on %s:%s" % (host, port)) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind((host, port)) server.listen(2) (command, (_, _)) = server.accept() (data, (_, _)) = server.accept() test_msg = b'#TSI_PING\nENDOFMESSAGE\n' LOG.info("CLIENT: connected, sending test message: %s" % test_msg) command.sendall(test_msg) reply = command.recv(1024) print(reply) # send shutdown and cleanup LOG.info("CLIENT: shutdown") tsi.sendall(b'shutdown') command.close() data.close() tsi.close() server.close() os.kill(pid, signal.SIGKILL)
for o, v in opts: if o == '-h': usage() sys.exit(0) if o == '-l': level = int(v) if o == '-p': pop = v if o == '-D': debug = debug + 1 options = ["details"] Attributes.pop = pop Attributes.options = options log = Log.Log(level) import conf conffile = "/import/bta4/v2/etc/bta4.conf" conf.loadconf(conffile) mf = ParseMakefile.ParseMakefile(conf=conf) for rtr in mf.rtrdict.keys(): mtr = mf.getRouterMeter(rtr=rtr) #print "%s = %s" % (rtr, mtr) cfg = RtrConfigParser(dir=RTRCFGDIR, attrs=Attributes) # Routers in the flowrules makefile for r in mf.rtrdict.keys(): found = 0
def init_config(env=None): init_constants(env) Log.init(Ivysaur.LogConfig)
def setUp(self): self.LOG = Log.Logger("tsi.testing", verbose=True, use_syslog=False)
def init_config(env=None): Ripple.init_config(env) Log.init(Ripple.LogConfig)
def setUp(self): self.LOG = Log.Logger("tsi.testing")
elif a.dbcustomer == b.dbcustomer: if a.dblink_id > b.dblink_id: return 1 elif a.dblink_id < b.dblink_id: return -1 return 0 if __name__ == "__main__": options = [] options.append("routes") options.append("interfaces") log = Log.Log(3) Attributes.log = log Attributes.options = options Attributes.debug = 4 targets = RtrCfg.RtrCfg("conf/") custs = NetCustomers(routers=targets.routers, attrs=Attributes) clist = custs.dbinterfaces clist.sort(custs.mycmpfunc) for iface in clist: print iface for route in custs.dbroutes: print route
def run(self): Log.info("Starting Thread %d" % self.threadID) process_ips(self.threadID, self.q) Log.info("Exiting Thread %d" % self.threadID)
def app_log(): filename = Settings.get('logging')['app']['filename'] return Log(filename=filename)
# Wait for all trheads to complete for t in threads: t.join() # End html log and close the file aux = open(RFOOTER,"r") outputLock.acquire() output.writelines("</table>") output.writelines("<br><br><div>Report generated by HttpAuthCrack v"+version+" on "+datetime.datetime.now().strftime("%Y/%m/%d %H:%M")+"</div>") output.writelines(aux.read()) outputLock.release() aux.close() output.close() except KeyboardInterrupt, e: Log.warn("Terminating all Threads due to Keyboard Interrupt...") outputLock.acquire() output.writelines("<h2>Execution stoped by user!!!</h2>") outputLock.release() exitFlag = 1 # End html log and close the file aux = open(RFOOTER,"r") outputLock.acquire() output.writelines(aux.read()) outputLock.release() aux.close() output.close() print "Exiting Main Thread"
def setUp(self): self.LOG = Log.Logger("tsi.testing", use_syslog=False) self.file_name = "tests/conf/tsi.properties"
def setUp(self): self.LOG = Log.Logger("tsi.testing", use_syslog=False) self.config = {'tsi.testing': True, "tsi.switch_uid": False} TSI.setup_defaults(self.config) BecomeUser.initialize(self.config, self.LOG)
conn.close() all_set = np.delete(all_set, 0, 0) train_set = np.delete(train_set, 0, 0) point_set = np.delete(point_set, 0, 0) print time.strftime("%Y-%m-%d %X",time.localtime()) print '\n get all data' #print return_set return all_set,train_set,point_set if __name__=='__main__': begin=time.time() date=str(datetime.datetime.now()-datetime.timedelta(days=1))[:10] cluster_num = 4 tableName_input = 'temp_chengf_test_cluster' # temp_chengf_test_cluster dm_rfm_module_20130327 tableName_output = 'temp_chengf_test_cluster_type' # dm_rmf_cluster_result log = Log.getLog2('/home/dm/dm_job/cluster.log') if len(sys.argv)==4: cluster_num=sys.argv[1] tableName_input=sys.argv[2] tableName_output =sys.argv[3] if len(sys.argv)==2: cluster_num=sys.argv[1] print 'excute python pycluster.py ' + str(cluster_num) + ' ' + tableName_input + ' ' + tableName_output log.info('%s begin '%__file__) print __file__ try: print time.strftime("%Y-%m-%d %X",time.localtime()) print 'begin extract data !' log.info('%s begin extract data,Using %d s\n' % (__file__,(time.time()-begin))) all_set,train_set,point_set = get_data(tableName_input) print time.strftime("%Y-%m-%d %X",time.localtime())
#!/usr/bin/env python3 #-*- coding: utf-8 -*- from lib import Log from lib import A from lib import B if __name__ == "__main__": logger = Log(file=__file__, cla=__name__).logger logger.info("from main function") a = A() b = B()
import requests from config import readConfig as readConfig import os from xlrd import open_workbook from xml.etree import ElementTree as ElementTree from lib import configHttp from lib import Log import json localReadConfig = readConfig.ReadConfig() proDir = readConfig.proDir[0:-6] localConfigHttp = configHttp.ConfigHttp() log = Log.MyLog().get_log() logger = log.get_logger() caseNo = 0 def show_return_msg(response): """ 显示返回的数据 """ url = response.url msg = response.text print("\n请求地址:" + url) print("\n请求返回值:" + '\n' + json.dumps( json.loads(msg), ensure_ascii=False, sort_key=True, indent=4)) #***************************************读取用例excel**************************************** def get_xls(xls_name, api_id, sheet_name='sheet'): """ 读取testcase excel """ cls = []
def setUp(self): self.LOG = Log.Logger("tsi.testing") self.file_name = "tests/conf/tsi.properties"