Ejemplo n.º 1
0
def main():

    lockf = ".lock.pod"
    if not lockFile(lockf):
        print "You can run only one instance of cscan (%s)" % lockf
        exit(0)

    my_env = os.environ
    env = config.copy()
    env.update(my_env)
    #Parser argument in command line
    parser = argparse.ArgumentParser(description='continues scanning on Faraday')
    parser.add_argument('-p','--plugin', help='Scan only the following plugin ej: ./cscan.py -p nmap.sh', required=False)
    args = parser.parse_args()

    for dirpath, dnames, fnames in os.walk("./scripts/web/"):
        for f in  fnames:
            if args.plugin and args.plugin != f:
                continue
            script = os.path.join(dirpath, f)
            cmd = "%s websites.txt output/" % (script)
            print "Running: %s" % cmd
            proc = subprocess.call(cmd, shell=True, stdin=None, stderr=subprocess.PIPE,  env=dict(env))

    for dirpath, dnames, fnames in os.walk("./scripts/network/"):
        for f in  fnames:
            if args.plugin and args.plugin != f:
                continue
            script = os.path.join(dirpath, f)
            cmd = "%s ips.txt output/" % (script)
            print "Running: %s" % cmd
            proc = subprocess.call(cmd, shell=True, stdin=None, stderr=subprocess.PIPE, env=dict(env))

    #Remove lockfile           
    os.remove(lockf)
Ejemplo n.º 2
0
 def setUpClass(cls): 
     #here use 9090 while not 90900 because if use later 90900 the test of tunnel not working 
     server_list = [(None, 9090), (None, 90901), (None, 90902)] 
     cls.server_list = server_list 
     from config import config
     cfg = config.copy()
     cfg.update(info=1, start=1)
     
     cc = {}
     cc[0] = cfg.copy()
     cc[0].update(port=9090)
     cc[1] = cfg.copy()
     cc[1].update(port=90901)
     cc[2] = cfg.copy()
     cc[2].update(mode='with_return')
     cc[2].update(port=90902)
     
     
     if 1: 
         worker_proc = []
         #for s in server_list: 
         #    host, port = s 
         #    mode = 'ansync' if port != 90902  else 'with_return'
         #    proc = Process(target=Worker, args=(), 
         #            kwargs={'port': port, 
         #                'start': 1, 'info': 1, 'mode': mode}) 
         #    worker_proc.append(proc)
         #    proc.start() 
         for  i in range(3): 
             proc = Process(target=Worker, args=(), 
                     kwargs=cc[i]) 
             worker_proc.append(proc)
             proc.start() 
         
         cls.worker_proc = worker_proc 
Ejemplo n.º 3
0
def main():

    lockf = ".lock.pod"
    if not lockFile(lockf):
        print "You can run only one instance of cscan (%s)" % lockf
        exit(0)

    my_env = os.environ
    env = config.copy()
    env.update(my_env)
    #Parser argument in command line
    parser = argparse.ArgumentParser(description='continues scanning on Faraday')
    parser.add_argument('-p','--plugin', help='Scan only the following plugin ej: ./cscan.py -p nmap.sh', required=False)
    args = parser.parse_args()

    for dirpath, dnames, fnames in os.walk("./scripts/web/"):
        for f in  fnames:
            if args.plugin and args.plugin != f:
                continue
            script = os.path.join(dirpath, f)
            cmd = "%s websites.txt output/" % (script)
            print "Running: %s" % cmd
            proc = subprocess.call(cmd, shell=True, stdin=None, stderr=subprocess.PIPE,  env=dict(env))

    for dirpath, dnames, fnames in os.walk("./scripts/network/"):
        for f in  fnames:
            if args.plugin and args.plugin != f:
                continue
            script = os.path.join(dirpath, f)
            cmd = "%s ips.txt output/" % (script)
            print "Running: %s" % cmd
            proc = subprocess.call(cmd, shell=True, stdin=None, stderr=subprocess.PIPE, env=dict(env))

    #Remove lockfile           
    os.remove(lockf)
Ejemplo n.º 4
0
def main():
    lockf = ".lock.pod"
    if not lockFile(lockf):
        print "You can run only one instance of cscan (%s)" % lockf
        exit(0)

    my_env = os.environ
    env = config.copy()
    env.update(my_env)

    parser = argparse.ArgumentParser(description='continues scanning on Faraday')
    parser.add_argument('-s','--script', help='Scan only the following script ej: ./cscan.py -p nmap.sh', required=False)
    parser.add_argument('-S','--scripts', help='Scan the following scripts list ej: ./cscan.py -p nmap.sh,nikto.sh', required=False)
    parser.add_argument('-c','--category', help='Scan only for given category ej: ./cscan.py -c network', required=False)
    parser.add_argument('-t','--targets', help='Choose a custom target list ej: ./cscan.py -t custom-list.txt', required=False)
    parser.add_argument('-o','--output', help='Choose a custom output directory', required=False)
    parser.add_argument('-l','--log', help='Choose a custom log directory', required=False)
    args = parser.parse_args()

    output = 'output/'
    if args.output:
        output = args.output

    logdir = 'log/'
    if args.log:
        logdir = args.log

    for d in [logdir, output]:
        if not os.path.isdir(d):
            os.makedirs(d)

    if args.script:
        scripts = [args.script]
    elif args.scripts:
        scripts = args.scripts.split(",")
    else:
        scripts = env["CS_SCRIPTS"].split(",")

    categories = env["CS_CATEGORIES"].split(",")
    for category in categories:
        env["PATH"] += ":%s" % os.path.abspath("./scripts/" + category)

    for script in scripts:
        if args.targets:
            targets = args.targets
        else:
            targets = target_list(script, categories)

        cmd = "%s %s %s %s" % (script, targets, output, logdir)
        print "\n\nRunning: %s" % cmd
        proc = subprocess.call(cmd, shell=True, stdin=None, env=dict(env))

    #Remove lockfile
    os.remove(lockf)
Ejemplo n.º 5
0
    def get_config(self) -> dict:
        from config import config
        import json

        self.config = config.copy()
        peripherals = self.config["peripherals"]
        with open(self.config_path + "/config.json") as fp:
            conf = json.load(fp)
        for k in self.config.keys():
            if k in conf:
                self.config[k] = conf[k]

        for k, v in self.config["peripherals"].items():
            self.config["peripherals"][k]["id"] = peripherals[v["name"]]["id"]

        return self.config
Ejemplo n.º 6
0
    def test_supervise(self): 
        def test_func(i): 
            print '#%s, pid=%d'%(i, os.getpid())
            time.sleep(1)
            return 3

        from config import config
        cfg = config.copy()
        cfg.update(info=1, start=1, long_idle_shut_down=1, 
                idle_time_limit=2, check_idle_period=0.2)
        cc = cfg.copy()
        cc.update(port=9070)
        
        proc = Process(target=Worker, args=(), 
                kwargs=cc) 
        proc.start() 
        time.sleep(1)
        queue(test_func, args=(1, ), host=cfg['host'], port=9070, 
                tunnel=0,   querry=0)
Ejemplo n.º 7
0
        

if __name__ == '__main__':
    
    
    if len(sys.argv)>1: 
        parser = argparse.ArgumentParser(description='dont know')
        parser.add_argument('-s', '--start', action='store_true', default=False) 
        parser.add_argument('-m', '--mode', default='ansync') 
        parser.add_argument('-p', '--port', type=int, default=None)
        args = parser.parse_args()
        args = vars(args)
        port = args['port']
        mode = args['mode']
        from config import config 
        cfg = config.copy()
        if port is not None: 
            cfg.update(port=port)
        cfg.update(mode=mode, start=1)
        if args['start']: 
            #w = Worker(port=port, mode=mode, start=1)
            w = Worker(**cfg)
            #w.start()
            #w.start_new()
            #w.start_async()
                
    else: 
        #sr = ThreadedServer(TestRpyc, port=9999, auto_register=False)
        
        if 1:
            TestIt.test_temp=unittest.skip("skip test_temp")(TestIt.test_temp) 
Ejemplo n.º 8
0
Archivo: proxy.py Proyecto: clones/kaa
 def config(self):
     if self._config is config:
         # Right now we're just using the global config.  Make a copy-on-write
         # clone to pass back to the user.
         self._config = config.copy(copy_on_write=True)
     return self._config
Ejemplo n.º 9
0
Archivo: cscan.py Proyecto: Sliim/cscan
def main():
    lockf = ".lock.pod"
    if not lockFile(lockf):
        print "You can run only one instance of cscan (%s)" % lockf
        exit(0)

    my_env = os.environ
    env = config.copy()
    env.update(my_env)

    parser = argparse.ArgumentParser(description='continues scanning on Faraday')
    parser.add_argument('-s','--script', help='Scan only the following script ej: ./cscan.py -p nmap.sh', required=False)
    parser.add_argument('-S','--scripts', help='Scan the following scripts list ej: ./cscan.py -p nmap.sh,nikto.sh', required=False)
    parser.add_argument('-c','--category', help='Scan only for given category ej: ./cscan.py -c network', required=False)
    parser.add_argument('-t','--targets', help='Choose a custom target list ej: ./cscan.py -t custom-list.txt', required=False)
    parser.add_argument('-o','--output', help='Choose a custom output directory', required=False)
    parser.add_argument('-l','--log', help='Choose a custom log directory', required=False)
    args = parser.parse_args()

    mm_url = False
    if env["CS_MATTERMOST"]:
        mm_url = env["CS_MATTERMOST"]
        mm_username = env["CS_MATTERMOST_USERNAME"] if "CS_MATTERMOST_USERNAME" in env else None
        mm_icon_url = env["CS_MATTERMOST_ICON_URL"] if "CS_MATTERMOST_ICON_URL" in env else None
        mattermost_message(mm_url, "Starting CScan..", mm_username, mm_icon_url)

    output = 'output/'
    if args.output:
        output = args.output

    logdir = 'log/'
    if args.log:
        logdir = args.log

    for d in [logdir, output]:
        if not os.path.isdir(d):
            os.makedirs(d)

    if args.script:
        scripts = [args.script]
    elif args.scripts:
        scripts = args.scripts.split(",")
    else:
        scripts = env["CS_SCRIPTS"].split(",")

    categories = env["CS_CATEGORIES"].split(",")
    for category in categories:
        env["PATH"] += ":%s" % os.path.abspath("./scripts/" + category)

    for script in scripts:
        if args.targets:
            targets = args.targets
        else:
            targets = target_list(script, categories)

        cmd = "%s %s %s %s" % (script, targets, output, logdir)
        print "Running: %s" % cmd
        if mm_url:
            mattermost_message(mm_url, "Run script: %s\nTargets:\n```\n%s\n```\n" % (script, open(targets).read()), mm_username, mm_icon_url)
        proc = subprocess.call(cmd, shell=True, stdin=None, env=dict(env))

    if mm_url:
        mattermost_message(mm_url, "CScan finished.", mm_username, mm_icon_url)

    #Remove lockfile
    os.remove(lockf)
Ejemplo n.º 10
0
 def config(self):
     if self._config is config:
         # Right now we're just using the global config.  Make a copy-on-write
         # clone to pass back to the user.
         self._config = config.copy(copy_on_write=True)
     return self._config
Ejemplo n.º 11
0
def main():
    lockf = ".lock.pod"
    if not lockFile(lockf):
        print "You can run only one instance of cscan (%s)" % lockf
        exit(0)

    my_env = os.environ
    env = config.copy()
    env.update(my_env)

    parser = argparse.ArgumentParser(
        description='continues scanning on Faraday')
    parser.add_argument(
        '-s',
        '--script',
        help='Scan only the following script ej: ./cscan.py -p nmap.sh',
        required=False)
    parser.add_argument(
        '-S',
        '--scripts',
        help=
        'Scan the following scripts list ej: ./cscan.py -p nmap.sh,nikto.sh',
        required=False)
    parser.add_argument(
        '-c',
        '--category',
        help='Scan only for given category ej: ./cscan.py -c network',
        required=False)
    parser.add_argument(
        '-t',
        '--targets',
        help='Choose a custom target list ej: ./cscan.py -t custom-list.txt',
        required=False)
    parser.add_argument('-o',
                        '--output',
                        help='Choose a custom output directory',
                        required=False)
    parser.add_argument('-l',
                        '--log',
                        help='Choose a custom log directory',
                        required=False)
    args = parser.parse_args()

    output = 'output/'
    if args.output:
        output = args.output

    logdir = 'log/'
    if args.log:
        logdir = args.log

    for d in [logdir, output]:
        if not os.path.isdir(d):
            os.makedirs(d)

    if args.script:
        scripts = [args.script]
    elif args.scripts:
        scripts = args.scripts.split(",")
    else:
        scripts = env["CS_SCRIPTS"].split(",")

    categories = env["CS_CATEGORIES"].split(",")
    for category in categories:
        env["PATH"] += ":%s" % os.path.abspath("./scripts/" + category)

    for script in scripts:
        if args.targets:
            targets = args.targets
        else:
            targets = target_list(script, categories)

        cmd = "%s %s %s %s" % (script, targets, output, logdir)
        print "\n\nRunning: %s" % cmd
        proc = subprocess.call(cmd, shell=True, stdin=None, env=dict(env))

    #Remove lockfile
    os.remove(lockf)
Ejemplo n.º 12
0
    models_fit = [0]
    z_fit = range(z_len)
    print 'Running for %i templates' % len(templates_data_interpolated)
    models_fit = range(len(templates_data_interpolated))
else:
    ndim, nwalkers = 7, config['n_walkers']
    n_samples = config['n_samples']
    n_steps = config['n_steps']
    n_burnin = int(n_steps * .3)
    out_fname = '%s/%s' % (save_dir, config['fit_bpz_outfile'])
    models_fit = range(len(templates_data_interpolated))
    z_fit = range(z_len)

f_fit = h5py.File(out_fname, 'w')
# Store config used on the run as attributes
aux_config = config.copy()
aux_config['filters'] = ','.join(sorted(aux_config['filters'].keys()))
f_fit.attrs.update(aux_config)

model_lnprob = f_fit.create_dataset('/model_lnprob',
                                    shape=(z_len, templates_len, n_samples),
                                    compression='gzip')
model_parameters = f_fit.create_dataset('/model_parameters',
                                        shape=(z_len, templates_len, n_samples,
                                               ndim),
                                        compression='gzip')
acceptance_fraction = f_fit.create_dataset('/acceptance_fraction',
                                           shape=(z_len, templates_len,
                                                  nwalkers),
                                           compression='gzip')
full_chain = f_fit.create_dataset('/full_chain',