Beispiel #1
0
def level13():
    print('Setting up level 13')
    gid = grp.getgrnam("ctf13").gr_gid
    uid = pwd.getpwnam("ctf13").pw_uid

    shutil.copy('../level_13/john.tar.gz', '/home/ctf13/john.tar.gz')
    shutil.copy('../level_13/pw.zip', '/home/ctf13/pw.zip')

    os.chown('/home/ctf13/pw.zip', uid, gid)
    os.chmod('/home/ctf13/pw.zip', 0o700)

    tar = tarfile.open('/home/ctf13/john.tar.gz', "r:gz")
    tar.extractall(path='/home/ctf13/')
    tar.close()

    os.rename('/home/ctf13/run', '/home/ctf13/john')

    tar = tarfile.open('../Info/data/PWLists.tar.gz', "r:gz")
    tar.extractall(path='/home/ctf13/wordlists')
    tar.close()

    os.chown('/home/ctf13/john', uid, gid)
    os.chmod('/home/ctf13/john', 0o700)

    owner_edit = 'sudo chown -R ctf13 /home/ctf13/john'
    ps = Popen([owner_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    owner_edit = 'sudo chown -R ctf13 /home/ctf13/wordlists'
    ps = Popen([owner_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    os.remove('/home/ctf13/john.tar.gz')

    os.chmod('/home/ctf13', 0o700)
Beispiel #2
0
def data_fit_staterrors(fit, prefix, verbose=0):
    outfilename  = 'bf_stat'
    
    outfile  = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                              comname=outfilename)
    fdir = outfile.replace(outfilename, '')
    com1_name = 'newfit-cat_files_data_statonly.sh'

    #bashbase = os.path.join(attr.base, 'src', attr.src, 'brf')
    com1 = tools.set_file(extbase=attr.brfpath, prefix=prefix, comname=com1_name)
    sdir = com1.replace(com1_name, '')
    com2 = create_bash_statonly(fdir, sdir, com1)

    if fit or not os.access(outfile, os.F_OK) :
        print 'Running fitter for staterrors ...'
        run_bf_fitter(com2, outfile, verbose)
    
    start_line_str   = 'Fitted parameters'
    start_column_str = '+-'
    end_column_str   = '('
    end_line_str     = 'Difference from seeds'

    data = tools.get_column_from_file(outfile,
                                      start_line_str, start_column_str,
                                      end_column_str, end_line_str,
                                      verbose = verbose)
    datafilename =  'data_fit_staterrors'

    outfile  = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                              comname=datafilename)

    fo, bakfile = tools.backup_output(outfile)
    for line in data: fo.write('%s\n' %line)
    tools.check_output(fo, outfile, bakfile)
Beispiel #3
0
def run_bf_fitter(com, outfile, verbose=0):
    fo, bakfile = tools.backup_output(outfile)
    output = commands.getoutput(com)
    if verbose > 0:
        print output
    fo.write(output)
    tools.check_output(fo, outfile, bakfile)
Beispiel #4
0
def run_bf_fitter(com, outfile, verbose=0):
    fo, bakfile = tools.backup_output(outfile)
    output = commands.getoutput(com)
    if verbose > 0:
        print output
    fo.write(output)
    tools.check_output(fo, outfile, bakfile)
Beispiel #5
0
def create_bash_generic_20060927(fdir, sdir, outfile):
    EXE = attr.fitter.replace('20070611', '20060927')

    sys.stdout.write('Using fitter: %s \n' %EXE)

    bash_content = '''#!/usr/bin/env bash

EXE=%s
FDIR=%s
SDIR=%s

YLDFILE=$FDIR/generic_yields_for_werner
BKGBRS=$FDIR/generic_external_bkg_bfs_for_werner
BKGEFFS=$FDIR/generic_bkg_effs_for_werner
BKGERRS=$FDIR/generic_bkg_effs_errs_for_werner
SIGSINGEFFS=$FDIR/signal_single_efficiencies_for_werner
SIGSINGERRS=$FDIR/signal_single_efficiencies_errors_for_werner
SIGDOUBEFFS=$FDIR/signal_double_efficiencies_for_werner
SIGDOUBERRS=$FDIR/signal_double_efficiencies_errors_for_werner
SYSTERRORS=$FDIR/newfit-generic_systerrors
SEEDS=$FDIR/generic_seeds

echo "#!/usr/bin/env bash" > $SDIR/newfit-generic.sh
echo "$EXE <<EOF" >> $SDIR/newfit-generic.sh
echo -e "n\\nn" >> $SDIR/newfit-generic.sh
cat $FDIR/newfit-modedef >> $SDIR/newfit-generic.sh
cat $YLDFILE >> $SDIR/newfit-generic.sh
cat $BKGBRS >> $SDIR/newfit-generic.sh
cat $SIGSINGEFFS >> $SDIR/newfit-generic.sh
cat $SIGDOUBEFFS >> $SDIR/newfit-generic.sh
cat $BKGEFFS >> $SDIR/newfit-generic.sh
cat $SIGSINGERRS >> $SDIR/newfit-generic.sh
cat $SIGDOUBERRS >> $SDIR/newfit-generic.sh
cat $BKGERRS >> $SDIR/newfit-generic.sh
#echo -e "0\\n0\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n1" >> \
$SDIR/newfit-generic.sh
cat $SYSTERRORS >> $SDIR/newfit-generic.sh
cat $SEEDS >> $SDIR/newfit-generic.sh
echo -e "n\\nn\\nn\\ny" >> $SDIR/newfit-generic.sh
cat $FDIR/generic_statonly_brratiodef >> $SDIR/newfit-generic.sh
echo -e "n" >> $SDIR/newfit-generic.sh
echo "EOF" >> $SDIR/newfit-generic.sh
chmod +x $SDIR/newfit-generic.sh
''' % (EXE, fdir, sdir)


    fo, bakfile = tools.backup_output(outfile)
    fo.write(bash_content)
    tools.check_output(fo, outfile, bakfile)
    bashfile = outfile
    os.chmod(bashfile, 0755)
    output = commands.getoutput(bashfile)
    if output:
        raise ValueError(output)

    new_bashfile = os.path.join(sdir, 'newfit-generic.sh')

    return new_bashfile
Beispiel #6
0
def output_matrix(matrix, outfile):

    fo, bakfile = tools.backup_output(outfile)

    for i in xrange(len(matrix[0])):
        for j in xrange(len(matrix)):
            fo.write('%s\n' % matrix[j][i])

    tools.check_output(fo, outfile, bakfile)
Beispiel #7
0
def create_bash_generic_20060927(fdir, sdir, outfile):
    EXE = attr.fitter.replace('20070611', '20060927')

    sys.stdout.write('Using fitter: %s \n' % EXE)

    bash_content = '''#!/usr/bin/env bash

EXE=%s
FDIR=%s
SDIR=%s

YLDFILE=$FDIR/generic_yields_for_werner
BKGBRS=$FDIR/generic_external_bkg_bfs_for_werner
BKGEFFS=$FDIR/generic_bkg_effs_for_werner
BKGERRS=$FDIR/generic_bkg_effs_errs_for_werner
SIGSINGEFFS=$FDIR/signal_single_efficiencies_for_werner
SIGSINGERRS=$FDIR/signal_single_efficiencies_errors_for_werner
SIGDOUBEFFS=$FDIR/signal_double_efficiencies_for_werner
SIGDOUBERRS=$FDIR/signal_double_efficiencies_errors_for_werner
SYSTERRORS=$FDIR/newfit-generic_systerrors
SEEDS=$FDIR/generic_seeds

echo "#!/usr/bin/env bash" > $SDIR/newfit-generic.sh
echo "$EXE <<EOF" >> $SDIR/newfit-generic.sh
echo -e "n\\nn" >> $SDIR/newfit-generic.sh
cat $FDIR/newfit-modedef >> $SDIR/newfit-generic.sh
cat $YLDFILE >> $SDIR/newfit-generic.sh
cat $BKGBRS >> $SDIR/newfit-generic.sh
cat $SIGSINGEFFS >> $SDIR/newfit-generic.sh
cat $SIGDOUBEFFS >> $SDIR/newfit-generic.sh
cat $BKGEFFS >> $SDIR/newfit-generic.sh
cat $SIGSINGERRS >> $SDIR/newfit-generic.sh
cat $SIGDOUBERRS >> $SDIR/newfit-generic.sh
cat $BKGERRS >> $SDIR/newfit-generic.sh
#echo -e "0\\n0\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n1" >> \
$SDIR/newfit-generic.sh
cat $SYSTERRORS >> $SDIR/newfit-generic.sh
cat $SEEDS >> $SDIR/newfit-generic.sh
echo -e "n\\nn\\nn\\ny" >> $SDIR/newfit-generic.sh
cat $FDIR/generic_statonly_brratiodef >> $SDIR/newfit-generic.sh
echo -e "n" >> $SDIR/newfit-generic.sh
echo "EOF" >> $SDIR/newfit-generic.sh
chmod +x $SDIR/newfit-generic.sh
''' % (EXE, fdir, sdir)

    fo, bakfile = tools.backup_output(outfile)
    fo.write(bash_content)
    tools.check_output(fo, outfile, bakfile)
    bashfile = outfile
    os.chmod(bashfile, 0755)
    output = commands.getoutput(bashfile)
    if output:
        raise ValueError(output)

    new_bashfile = os.path.join(sdir, 'newfit-generic.sh')

    return new_bashfile
Beispiel #8
0
def output_matrix(matrix, outfile):

    fo, bakfile = tools.backup_output(outfile)

    for i in xrange(len(matrix[0])):
        for j in xrange(len(matrix)):
            fo.write('%s\n' % matrix[j][i])

    tools.check_output(fo, outfile, bakfile)
Beispiel #9
0
def delet_user():
    for x, y in credentials.items():
        userdel = 'sudo userdel ' + x
        rmuserdir = 'sudo rm /home/' + x + ' -rf'
        ps = Popen([userdel], stdout=PIPE, stderr=PIPE, shell=True)
        tools.check_output(ps)
        ps = Popen([rmuserdir], stdout=PIPE, stderr=PIPE, shell=True)
        tools.check_output(ps)
    return (True)
Beispiel #10
0
def get_statonly_sys_err_generic(prefix='', verbose = 0):
    filename = 'newfit-generic_systerrors'
    outfile  = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                              comname=filename)
    statonly_sys_err = get_statonly_sys_err_for_fit_generic(prefix)
    statonly_sys_list = map(str, statonly_sys_err)
    content = '\n'.join(statonly_sys_list)+ '\n'
    fo, bakfile = tools.backup_output(outfile)
    fo.write(content)
    tools.check_output(fo, outfile, bakfile)
Beispiel #11
0
def statonly_data_yields(prefix, prefix_data, verbose=0):
    outfilename = 'statonly_data_yields_for_werner'

    label = prefix.replace('dir_', '')
    outfile = tools.set_file(extbase=attr.brfpath, prefix=prefix, 
                             comname=outfilename)

    fo, bakfile = tools.backup_output(outfile)

    data_yields_single(fo, prefix_data, opt='statonly', label=label, verbose=verbose)
    data_yields_double(fo, prefix_data, opt='statonly', label=label, verbose=verbose)

    tools.check_output(fo, outfile, bakfile)
Beispiel #12
0
def data_yields(prefix, prefix_data, opt_sys_err='', verbose=0):
    outfilename = 'data_yields_for_werner'
    outfile  = tools.set_file(
        extbase = attr.brfpath, prefix = prefix, 
        comname = outfilename)

    label = prefix.replace('dir_', '')
    fo, bakfile = tools.backup_output(outfile)

    data_yields_single(fo, prefix_data, label=label, verbose=verbose)
    data_yields_double(fo, prefix_data, opt=opt_sys_err, label=label,
                       verbose=verbose)

    tools.check_output(fo, outfile, bakfile)
Beispiel #13
0
def level5():
    print('Setting up level 5')
    path = '/home/ctf5/ReadMe'
    gid = grp.getgrnam("ctf5").gr_gid
    uid = pwd.getpwnam("ctf5").pw_uid

    shutil.copy('../level_05/ReadMe', path)
    os.chown(path, uid, gid)
    os.chmod('/home/ctf5', 0o700)
    os.chmod(path, stat.S_IRUSR)

    edit_bashrc = 'echo "exit" | tee -a /home/ctf5/.bashrc'
    ps = Popen([edit_bashrc], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #14
0
def get_sys_err(prefix= '' , opt_sys_err='', verbose=0):
    label = prefix.replace('dir_', '')

    filename = 'newfit-data_systerrors'
    outfile  = tools.set_file(
        extbase   = attr.brfpath, prefix  = prefix, 
        comname   = filename)

    sys_err_ = get_sys_err_for_fit(label)
    
    sys_list = map(str, sys_err_)
    content = '\n'.join(sys_list)+ '\n'
    fo, bakfile = tools.backup_output(outfile)

    fo.write(content)
    tools.check_output(fo, outfile, bakfile)
Beispiel #15
0
def data_yields(prefix, prefix_data, opt_sys_err='', verbose=0):
    outfilename = 'data_yields_for_werner'
    outfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname=outfilename)

    label = prefix.replace('dir_', '')
    fo, bakfile = tools.backup_output(outfile)

    data_yields_single(fo, prefix_data, label=label, verbose=verbose)
    data_yields_double(fo,
                       prefix_data,
                       opt=opt_sys_err,
                       label=label,
                       verbose=verbose)

    tools.check_output(fo, outfile, bakfile)
Beispiel #16
0
def securInstall():
    print('Securing the install')
    gid = os.getegid()
    uid = os.geteuid()

    os.chmod(os.environ['HOME'], 0o700)

    pash = os.environ['HOME']

    per_edit = 'sudo chmod -R 700 ' + pash
    ps = Popen([per_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    dir_path = os.path.dirname(os.path.realpath(__file__))

    per_edit = 'sudo chmod -R 700 ' + dir_path
    ps = Popen([per_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #17
0
 def do_stop():
     if self.__getOutput() == "":
         LOGGER.info('Daemon is not started')
         return
     try:
         msg = check_output(
             [self.__YDC, '-c', self.config.fileName, 'stop'],
             universal_newlines=True)
         LOGGER.info('Daemon stopped, message: %s', msg)
     except:
         LOGGER.info('Daemon stop failed')
Beispiel #18
0
def level0():
    print('Setting up level 0')
    path = '/home/ctf/-'
    gid = grp.getgrnam("ctf").gr_gid
    uid = pwd.getpwnam("ctf").pw_uid
    shutil.copy('../level_00/-', path)

    os.chown(path, uid, gid)
    os.chmod('/home/ctf', 0o700)
    os.chmod(path, 0o400)

    #Setting welcome and autolunch for firefox
    shutil.copy('../Info/Welcome.ascii', '/home/ctf/welcome')
    os.chmod('/home/ctf/welcome', 0o444)
    edit_bashrc = 'echo "cat welcome" | tee -a /home/ctf/.bashrc'
    ps = Popen([edit_bashrc], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    edit_bashrc = 'echo "firefox localhost:8000 &" | tee -a /home/ctf/.bashrc'
    ps = Popen([edit_bashrc], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #19
0
def data_fit_staterrors(fit, prefix, verbose=0):
    outfilename = 'bf_stat'

    outfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname=outfilename)
    fdir = outfile.replace(outfilename, '')
    com1_name = 'newfit-cat_files_data_statonly.sh'

    #bashbase = os.path.join(attr.base, 'src', attr.src, 'brf')
    com1 = tools.set_file(extbase=attr.brfpath,
                          prefix=prefix,
                          comname=com1_name)
    sdir = com1.replace(com1_name, '')
    com2 = create_bash_statonly(fdir, sdir, com1)

    if fit or not os.access(outfile, os.F_OK):
        print 'Running fitter for staterrors ...'
        run_bf_fitter(com2, outfile, verbose)

    start_line_str = 'Fitted parameters'
    start_column_str = '+-'
    end_column_str = '('
    end_line_str = 'Difference from seeds'

    data = tools.get_column_from_file(outfile,
                                      start_line_str,
                                      start_column_str,
                                      end_column_str,
                                      end_line_str,
                                      verbose=verbose)
    datafilename = 'data_fit_staterrors'

    outfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname=datafilename)

    fo, bakfile = tools.backup_output(outfile)
    for line in data:
        fo.write('%s\n' % line)
    tools.check_output(fo, outfile, bakfile)
Beispiel #20
0
def level15():
    print('Setting up level 15')

    #For last level
    gid = grp.getgrnam("ctf15").gr_gid
    uid = pwd.getpwnam("ctf15").pw_uid

    shutil.copy('../level_15/ctf15.pw', '/home/ctf15/ctf15.pw')
    shutil.copy('../level_15/ReadMe.md', '/home/ctf15/ReadMe.md')
    shutil.copy('../level_15/Server', '/home/ctf15/Server')

    os.chown('/home/ctf15/ctf15.pw', uid, gid)
    os.chmod('/home/ctf15/ctf15.pw', 0o400)

    os.chown('/home/ctf15/ReadMe.md', uid, gid)
    os.chmod('/home/ctf15/ReadMe.md', 0o400)

    os.chown('/home/ctf15/Server', uid, gid)
    os.chmod('/home/ctf15/Server', 0o400)

    #For current level
    dir_path = os.path.dirname(os.path.realpath(__file__))
    servercommand = '' + dir_path[:-5] + 'Info/data/Server'

    comand_path = '/etc/systemd/system/ctfserver.service'

    service = 'Description=This starts the socket on prot 4242 that the user has to find\n\nWants=network.target\nAfter=syslog.target network-online.target\n\n[Service]\nType=simple\nExecStart=' + servercommand + '\nRestart=on-failure\nRestartSec=10\nKillMode=process\n\n[Install]\nWantedBy=multi-user.target'

    text_file = open(comand_path, 'w')
    text_file.write(service)
    text_file.close()

    comand = 'sudo systemctl daemon-reload'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl enable ctfserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl start ctfserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl status ctfserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    #Aternative: Start programm with ./bashrc
    # add_serverstart = 'echo "\n#Clear history every login\n/SERVER &" | tee -a /home/' + x + '/.bashrc'
    # ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    # tools.check_output(ps)

    os.chmod('/home/ctf15', 0o700)
Beispiel #21
0
 def __getOutput(self,
                 userLang=False):  # Get result of 'yandex-disk status'
     cmd = [self.__YDC, '-c', self.config.fileName, 'status']
     if not userLang:  # Change locale settings when it required
         cmd = ['env', '-i', "TMPDIR=%s" % self.tmpDir] + cmd
     # LOGGER.debug('cmd = %s', str(cmd))
     try:
         output = check_output(cmd, universal_newlines=True)
     except:
         output = ''  # daemon is not running or bad
         # LOGGER.debug('Status output = %s', output)
     return output
Beispiel #22
0
def statonly_data_yields(prefix, prefix_data, verbose=0):
    outfilename = 'statonly_data_yields_for_werner'

    label = prefix.replace('dir_', '')
    outfile = tools.set_file(extbase=attr.brfpath,
                             prefix=prefix,
                             comname=outfilename)

    fo, bakfile = tools.backup_output(outfile)

    data_yields_single(fo,
                       prefix_data,
                       opt='statonly',
                       label=label,
                       verbose=verbose)
    data_yields_double(fo,
                       prefix_data,
                       opt='statonly',
                       label=label,
                       verbose=verbose)

    tools.check_output(fo, outfile, bakfile)
Beispiel #23
0
def level14():
    print('Setting up level 14')
    gid = grp.getgrnam("ctf14").gr_gid
    uid = pwd.getpwnam("ctf14").pw_uid

    shutil.copy('../level_14/hack_this.jpg', '/home/ctf14/hack_this.jpg')

    os.chown('/home/ctf14/hack_this.jpg', uid, gid)
    os.chmod('/home/ctf14/hack_this.jpg', 0o700)

    ssh_login = '******'
    ps = Popen([ssh_login], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    set_ssh = 'sudo sshpass -p 6E8Wmjx7DjkVixD4whK9NRNnUsfHY98p ssh-copy-id -i ../level_14/tatu-key-ecdsa ctf15@localhost'
    ps = Popen([set_ssh], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    os.chown('/home/ctf14/hack_this.jpg', uid, gid)
    os.chmod('/home/ctf14/hack_this.jpg', 0o700)

    os.chmod('/home/ctf14', 0o700)
Beispiel #24
0
 def do_start():
     if self.__getOutput() != "":
         LOGGER.info('Daemon is already started')
         self.__watcher.start()  # Activate file watcher
         return
     try:  # Try to start
         msg = check_output(
             [self.__YDC, '-c', self.config.fileName, 'start'],
             universal_newlines=True)
         LOGGER.info('Daemon started, message: %s', msg)
     except CalledProcessError as e:
         LOGGER.error('Daemon start failed: %s', e.output)
         return
     self.__watcher.start()  # Activate file watcher
Beispiel #25
0
def create_user():
    for x, y in credentials.items():
        print('Setting user: '******'sudo useradd -m ' + x
        shell_edit = 'sudo chsh -s /bin/bash ' + x
        set_pw = 'sudo echo ' + x + ':' + y + ' | chpasswd'
        add_group = 'sudo usermod -a -G wireshark ' + x
        edit_bashrc1 = 'echo "\n#Clear history every login\nhistory -c" | tee -a /home/' + x + '/.bashrc'
        edit_bashrc2 = 'echo "\n#Set ssh alias for X11 forwarding\nalias ssh=\'ssh -X\'" | tee -a /home/' + x + '/.bashrc'
        edit_bashrc3 = 'echo "\n#Set postman alias \nalias postman=\'/home/ctf/Postman/Postman\'" | tee -a /home/' + x + '/.bashrc'

        ps = Popen([user_add], stdout=PIPE, stderr=PIPE, shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([shell_edit], stdout=PIPE, stderr=PIPE, shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([set_pw], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([add_group],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE,
                   shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([edit_bashrc1],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE,
                   shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([edit_bashrc2],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE,
                   shell=True)
        if (not tools.check_output(ps)):
            return (False)
        ps = Popen([edit_bashrc3],
                   stdin=PIPE,
                   stdout=PIPE,
                   stderr=PIPE,
                   shell=True)
        if (not tools.check_output(ps)):
            return (False)
    return (True)
Beispiel #26
0
def setupmongo():
    print('Setting up MongoDB')

    myclient = pymongo.MongoClient("mongodb://localhost:27017/")
    mydb = myclient["admin"]
    mydb.command("createUser",
                 "useradmin",
                 pwd="ConSecurMongoDB",
                 roles=["userAdminAnyDatabase"])
    myclient.close()

    time.sleep(1)

    print('Mongo Admin created. Restarting MongoDB with --auth')
    comand = 'sudo systemctl stop mongod'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)

    comand_path = '/etc/systemd/system/multi-user.target.wants/mongodb.service'

    service = '[Unit]\nDescription=An object/document-oriented database\nDocumentation=man:mongod(1)\nAfter=network.target\n\n[Service]\nUser=mongodb\nGroup=mongodb\nRuntimeDirectory=mongodb\nRuntimeDirectoryMode=0755\nEnvironmentFile=-/etc/default/mongodb\nEnvironment=CONF=/etc/mongodb.conf\nEnvironment=SOCKETPATH=/run/mongodb\nExecStart=/usr/bin/mongod --auth --unixSocketPrefix=${SOCKETPATH} --config ${CONF} $DAEMON_OPTS\nLimitFSIZE=infinity\nLimitCPU=infinity\nLimitAS=infinity\nLimitNOFILE=64000\nLimitNPROC=64000\n\n[Install]\nWantedBy=multi-user.target\n'

    time.sleep(1)

    text_file = open(comand_path, 'w')
    text_file.write(service)
    text_file.close()

    print('New daemon written')

    comand = 'sudo systemctl daemon-reload'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    time.sleep(1)
    comand = 'sudo systemctl start mongodb'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    time.sleep(1)
    comand = 'sudo systemctl status mongodb'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    print('Creating ctf user')
    myclient = pymongo.MongoClient('localhost',
                                   username='******',
                                   password='******')
    mydb = myclient["ctf"]
    mydb.command("createUser",
                 "ctf",
                 pwd="ConSecurMongoDB",
                 roles=["readWrite"])
    myclient.close()
Beispiel #27
0
def alterhosts():
    hosts_edit = 'echo "127.0.0.1       BeeblebroxCTF.com" | tee -a /etc/hosts'
    ps = Popen([hosts_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #28
0
def npm_tools():
    print('\nUpdating and installing npm tools ...')

    comand = 'sudo npm install -g npm@latest'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo npm install nodemon -g'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo npm install forever -g'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'npm install --prefix ../NodeJSServer'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)

    print('Try to set demon for NodeServer...')
    dir_path = os.path.dirname(os.path.realpath(__file__))
    nodecommand = 'forever ' + dir_path[:-5] + 'NodeJSServer/app.js'
    comand_path = '/etc/systemd/system/nodeserver.service'

    service = 'Description=This starts the NodeJS Webserver\n\nWants=network.target\nAfter=syslog.target network-online.target\n\n[Service]\nType=simple\nExecStart=' + nodecommand + '\nRestart=on-failure\nRestartSec=10\nKillMode=process\n\n[Install]\nWantedBy=multi-user.target'

    text_file = open(comand_path, 'w')
    text_file.write(service)
    text_file.close()

    comand = 'sudo systemctl daemon-reload'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl enable nodeserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl start nodeserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
    comand = 'sudo systemctl status nodeserver'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #29
0
def setScripts():
    comand = 'sudo cat ../Info/Welcome.ascii | sudo tee /etc/motd'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #30
0
def sshX11():
    ssh_edit = 'echo "    ForwardX11 yes" | tee -a /etc/ssh/ssh_config'
    ps = Popen([ssh_edit], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #31
0
def setupMongoUsers():
    print('\nRestoring database')
    comand = 'sudo mongorestore -d ctf --uri mongodb://ctf:ConSecurMongoDB@localhost:27017/ctf ../Info/ctf'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #32
0
def securMaria():
    print('Securing the MariaDB install...')
    command = 'sudo ./secureMaria.sh'
    ps = Popen([command], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps,True)
    time.sleep(11)
Beispiel #33
0
def installPips():
    comand = 'sudo pip3 install mysql-connector'
    ps = Popen([comand], stdout=PIPE, stderr=PIPE, shell=True)
    tools.check_output(ps)
Beispiel #34
0
def create_bash_stat_syst(fdir, sdir, outfile):
    EXE = attr.fitter
    sys.stdout.write('Using fitter: %s \n' %EXE)
    bash_content = '''#!/usr/bin/env bash
EXE=%s
FDIR=%s
SDIR=%s

YLDFILE=$FDIR/data_yields_for_werner

BKGBRS=$FDIR/data_external_bkg_bfs_for_werner
BKGEFFS=$FDIR/data_bkg_effs_for_werner
BKGERRS=$FDIR/data_bkg_effs_errs_for_werner

SIGSINGEFFS=$FDIR/signal_single_efficiencies_for_werner
SIGSINGERRS=$FDIR/signal_single_efficiencies_errors_for_werner
SIGDOUBEFFS=$FDIR/signal_double_efficiencies_for_werner
SIGDOUBERRS=$FDIR/signal_double_efficiencies_errors_for_werner
SYSTERRORS=$FDIR/newfit-data_systerrors
SEEDS=$FDIR/data_seeds
STATTOSUBTRACT=$FDIR/data_fit_staterrors

echo "#!/usr/bin/env bash" > $SDIR/newfit-data.sh
echo "$EXE <<EOF" >> $SDIR/newfit-data.sh
echo -e "n\\nn" >> $SDIR/newfit-data.sh
cat $FDIR/newfit-modedef >> $SDIR/newfit-data.sh
cat $YLDFILE >> $SDIR/newfit-data.sh
cat $BKGBRS >> $SDIR/newfit-data.sh
cat $SIGSINGEFFS >> $SDIR/newfit-data.sh
cat $SIGDOUBEFFS >> $SDIR/newfit-data.sh
cat $BKGEFFS >> $SDIR/newfit-data.sh
cat $SIGSINGERRS >> $SDIR/newfit-data.sh
cat $SIGDOUBERRS >> $SDIR/newfit-data.sh
cat $BKGERRS >> $SDIR/newfit-data.sh
#echo -e "0\\n0\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n1" >> \
$SDIR/newfit-data.sh
cat $SYSTERRORS >> $SDIR/newfit-data.sh
cat $SEEDS >> $SDIR/newfit-data.sh
echo -e "n\\nn\\ny" >> $SDIR/newfit-data.sh
cat $STATTOSUBTRACT >> $SDIR/newfit-data.sh
echo -e "y" >> $SDIR/newfit-data.sh
cat $FDIR/data_brratiodef >> $SDIR/newfit-data.sh
echo -e "\\ny" >> $SDIR/newfit-data.sh
cat $FDIR/data_crosssectionsdef >> $SDIR/newfit-data.sh
echo "EOF" >> $SDIR/newfit-data.sh
chmod +x $SDIR/newfit-data.sh
''' % (EXE, fdir, sdir)

    fo, bakfile = tools.backup_output(outfile)
    fo.write(bash_content)
    tools.check_output(fo, outfile, bakfile)
    bashfile = outfile
    os.chmod(bashfile, 0755)
    output = commands.getoutput(bashfile)
    if output:
        print 'Stop message from DHadBF:: create_bash_stat_syst:'
        print '-------------------------------------------------'
        print output
        print '-------------------------------------------------'
        sys.exit()
        
    new_bashfile = os.path.join(sdir, 'newfit-data.sh')
    return new_bashfile
Beispiel #35
0
def create_bash_statonly(fdir, sdir, outfile):

    EXE = attr.fitter

    sys.stdout.write('Using fitter: %s \n' % EXE)

    bash_content = '''#!/usr/bin/env bash

EXE=%s
FDIR=%s
SDIR=%s

YLDFILE=$FDIR/statonly_data_yields_for_werner
BKGBRS=$FDIR/data_statonly_external_bkg_bfs_for_werner
BKGEFFS=$FDIR/data_bkg_effs_for_werner
BKGERRS=$FDIR/data_bkg_effs_errs_for_werner
SIGSINGEFFS=$FDIR/signal_single_efficiencies_for_werner
SIGSINGERRS=$FDIR/zero_single_efficiencies_errors_for_werner
SIGDOUBEFFS=$FDIR/signal_double_efficiencies_for_werner
SIGDOUBERRS=$FDIR/zero_double_efficiencies_errors_for_werner
SYSTERRORS=$FDIR/newfit-data_statonly_systerrors
SEEDS=$FDIR/data_seeds

echo "#!/usr/bin/env bash" > $SDIR/newfit-data_statonly.sh
echo "$EXE <<EOF" >> $SDIR/newfit-data_statonly.sh
echo -e "n\\nn" >> $SDIR/newfit-data_statonly.sh
cat $FDIR/newfit-modedef >> $SDIR/newfit-data_statonly.sh
cat $YLDFILE >> $SDIR/newfit-data_statonly.sh
cat $BKGBRS >> $SDIR/newfit-data_statonly.sh
cat $SIGSINGEFFS >> $SDIR/newfit-data_statonly.sh
cat $SIGDOUBEFFS >> $SDIR/newfit-data_statonly.sh
cat $BKGEFFS >> $SDIR/newfit-data_statonly.sh
cat $SIGSINGERRS >> $SDIR/newfit-data_statonly.sh
cat $SIGDOUBERRS >> $SDIR/newfit-data_statonly.sh
cat $BKGERRS >> $SDIR/newfit-data_statonly.sh
#echo -e "0\\n0\\n0\\n0\\n0\\n0\\n1\\n1\\n1\\n1\\n1\\n1" >> \
$SDIR/newfit-data_statonly.sh
cat $SYSTERRORS >> $SDIR/newfit-data_statonly.sh
cat $SEEDS >> $SDIR/newfit-data_statonly.sh
echo -e "n\\nn\\nn\\ny" >> $SDIR/newfit-data_statonly.sh
cat $FDIR/data_statonly_brratiodef >> $SDIR/newfit-data_statonly.sh
echo -e "\\ny" >> $SDIR/newfit-data_statonly.sh
cat $FDIR/data_statonly_crosssectionsdef >> $SDIR/newfit-data_statonly.sh
echo "EOF" >> $SDIR/newfit-data_statonly.sh
chmod +x $SDIR/newfit-data_statonly.sh
''' % (EXE, fdir, sdir)

    fo, bakfile = tools.backup_output(outfile)
    fo.write(bash_content)
    tools.check_output(fo, outfile, bakfile)
    bashfile = outfile
    os.chmod(bashfile, 0755)
    output = commands.getoutput(bashfile)
    if output:
        print 'Stop message from DHadBF:: create_bash_statonly:'
        print '-------------------------------------------------'
        print output
        print '-------------------------------------------------'
        sys.exit()

    new_bashfile = os.path.join(sdir, 'newfit-data_statonly.sh')

    return new_bashfile
Beispiel #36
0
    APPCONFPATH = pathJoin(getenv("HOME"), '.config', APPHOME)
    # Define .desktop files locations for indicator auto-start facility
    APPAUTOSTARTSRC = '/usr/share/applications/Yandex.Disk-indicator.desktop'
    APPAUTOSTARTDST = expanduser(
        '~/.config/autostart/Yandex.Disk-indicator.desktop')

    # Get command line arguments or their default values
    args = argParse(APPVER)

    # Change the process name
    setProcName(APPHOME)

    # Check for already running instance of the indicator application
    # Get PIDs of all runnig processes (of current user) with name 'yd-tools' and compare it with current process PID
    if str(getpid()) != check_output(
        ["pgrep", '-u', str(geteuid()), APPHOME],
            universal_newlines=True).strip():
        sysExit(_('The indicator instance is already running.'))

    # Set user specified logging level
    LOGGER.setLevel(args.level)

    # Report app version and logging level
    LOGGER.info('%s v.%s', APPNAME, APPVER)
    LOGGER.debug('Logging level: %s', str(args.level))

    # Application configuration
    """
    User configuration is stored in ~/.config/<APPHOME>/<APPNAME>.conf file.
    This file can contain comments (line starts with '#') and config values in
    form: key=value[,value[,value ...]] where keys and values can be quoted ("...") or not.