Exemple #1
0
# REF: https://en.wikipedia.org/wiki/Test_functions_for_optimization
import os

os.environ['OMP_NUM_THREADS'] = '1'
from cso import CSO


def himmelblaus_function(x, *args, **kwargs):
    return (((x[0]**2) + x[1] - 11)**2) + ((x[0] + (x[1]**2) - 7)**2)


o = CSO(himmelblaus_function,
        lb=[-5, -5],
        ub=[5, 5],
        workers=1,
        threads=1,
        maxiter=200,
        cats=500,
        mr=0.5,
        smp=10,
        cdc=1,
        srd=0.1,
        spc=False,
        omega=0.5)

best = o.run()

print(best)
Exemple #2
0
from interactive import *
from time import sleep
from optparse import OptionParser
import csv

if len(argv) > 1:
    with open(argv[1]) as f:
        reader = csv.DictReader(f)
        raw = [r for r in reader]
else:
    print "reading from stdin"
    reader = csv.DictReader(stdin)
    raw = [r for r in reader]

# Make fieldnames / dictionary keys lowercase
#XXX wish there was a better way to do this
data = []
for d in raw:
    datum = {}
    for k in d:
        datum[k.lower()] = d[k]
    data.append(datum)

c = CSO()
c.start()
prompt(
    'Navigate to client Answer Risk Controls and click on first control in Sequential Answer Mode'
)
c.batchAddData(data, 'risk')
c.close()
Exemple #3
0
from cso import CSO
from sys import argv, stdout
import os
from interactive import *
from time import sleep
from optparse import OptionParser
import csv


def usage():
    raise Exception("read_report <output filename>")


if len(argv) < 2:
    usage()
c = CSO()
c.start()
prompt(
    'Navigate to client "Analyze Vulnerabilities" section and click on first control in Sequential Answer Mode'
)
data = c.getAllControls()
c.close()

fieldnames = [
    'asset', 'control', 'verification', 'resources', 'observation',
    'recommendation', 'date', 'method', 'source'
]

recoded = []
for d in data:
    datum = {}
Exemple #4
0
    '-f',
    '--format',
    help=
    "format string for resource title. eg '2017 ITA-{title}' ({title} fills in filename) "
)
parser.add_option('-d',
                  '--driver',
                  help='Specify firefox/chromium driver',
                  default='firefox')
(options, args) = parser.parse_args()

if len(args) == 0:
    print parser.print_help()
    exit(1)

c = CSO(driver=options.driver)
c.start()
prompt("Navigate to client file repository")
for f in args:
    print_status("Adding File '{}'".format(f))
    try:
        if options.format is not None:
            c.addFileToRepo(f, title_fmt=options.format)
        else:
            c.addFileToRepo(f)
        sleep(3)
    except:
        print_status("Failed to add file '{}'".format(f))
        raise
        prompt("Navigate to client file repository")
c.close()
Exemple #5
0
#!/usr/bin/python
from sys import argv
from cso import CSO

if len(argv) < 2:
    print 'Usage: scan2top COMPANY'
    exit(1)
c = CSO()
c.start()
c.moveToTop(argv[1])
c.driver.close()
# REF: https://en.wikipedia.org/wiki/Test_functions_for_optimization
import os

os.environ['OMP_NUM_THREADS'] = '1'
from cso import CSO


def matyas_function(x, *args, **kwargs):
    return 0.26 * (x[0]**2 + x[1]**2) - 0.48 * x[0] * x[1]


o = CSO(matyas_function,
        lb=[-10, -10],
        ub=[10, 10],
        workers=2,
        threads=1,
        maxiter=200,
        cats=500,
        mr=0.5,
        smp=10,
        cdc=1,
        srd=0.1,
        spc=False,
        omega=0.5)

best = o.run()

print(best)
# REF: https://en.wikipedia.org/wiki/Test_functions_for_optimization
import os

os.environ['OMP_NUM_THREADS'] = '1'

from cso import CSO

dimension = 3

def sphere_function(x, *args, **kwargs):
    return sum([a**2 for a in x])

o = CSO(sphere_function, lb=[-10] * dimension, ub=[10] * dimension,
            workers=3, threads=2, maxiter=200,
            cats=500, mr=0.5, smp=10, cdc=1, srd=0.1, spc=False, omega=0.5)

best = o.run()

print(best)
Exemple #8
0
from cso import CSO


def test_function(x, *args, **kwargs):
    return 20 * x[0] - 2 * (x[0]**2)


o = CSO(test_function,
        maximize=True,
        lb=[-10],
        ub=[10],
        n_cats=100,
        smp=10,
        maxiter=100,
        cdc=1,
        mr=0.5)

best = o.run()

print(best)
Exemple #9
0
# REF: https://en.wikipedia.org/wiki/Test_functions_for_optimization
import os

os.environ['OMP_NUM_THREADS'] = '1'
from cso import CSO


def beale_function(x, *args, **kwargs):
    return ( 1.5 - x[0] + x[0] * x[1]) ** 2 + \
            (2.25 - x[0] + ((x[0] * x[1]) ** 2)) ** 2 + \
            (2.625 - x[0] + ((x[0]) * x[1])**3) ** 2


o = CSO(beale_function,
        lb=[-4.5, -4.5],
        ub=[4.5, 4.5],
        workers=1,
        threads=1,
        maxiter=200,
        cats=500,
        mr=0.5,
        smp=10,
        cdc=1,
        srd=0.1,
        spc=False,
        omega=0.5)

best = o.run()

print(best)
Exemple #10
0
import numpy as np
import pandas as pd
from cso import CSO

# fit = np.zeros((40, 10))
# xi = np.zeros(20)
# x = pd.DataFrame(-1 + 2 * np.random.rand(40, 20)) * 100
# test = Benchmark(20)
# for i in np.arange(40):
#     xi = x.iloc[i]
#     fit[i] = test.Fitness(xi)
# print(fit)
c = CSO()
c.runcso()
Exemple #11
0
from interactive import *
from time import sleep
from optparse import OptionParser
import csv

if len(argv) > 1:
    with open(argv[1]) as f:
        reader = csv.DictReader(f)
        raw = [r for r in reader]
else:
    print "reading from stdin"
    reader = csv.DictReader(stdin)
    raw = [r for r in reader]

# Make fieldnames / dictionary keys lowercase
#XXX wish there was a better way to do this
data = []
for d in raw:
    datum = {}
    for k in d:
        datum[k.lower()] = d[k]
    data.append(datum)

c = CSO()
c.start()
prompt(
    'Navigate to client "Analyze Vulnerabilities" section and click on first control in Sequential Answer Mode'
)
c.batchAddData(data, 'audit')
c.close()
Exemple #12
0
#!/usr/bin/python

import os
from cso import CSO
from ps import popsummary
from interactive import *
from time import sleep

c = CSO()
c.start()
w = os.environ['WORKDIR']
vdirs = [
    os.path.join(w, 'vuln', v) for v in os.listdir(os.path.join(w, 'vuln'))
]
prompt("Navigate to report vulnerabilites tab")
for v in vdirs:
    c.addVulnerability(v)
    sleep(2)
prompt("Navigate to 'Summaries' tab")
with open(os.path.join(w, 'appendix')) as f:
    for file in f:
        c.addAppendixFigure(file.strip())
ls = os.listdir(os.path.join(w, 'combined'))
gnmaps = [
    os.path.realpath(os.path.join(w, 'combined', g)) for g in ls
    if g[-6:] == '.gnmap'
]
script = popsummary(os.path.join(w, 'ICMP Echo Request.spl'), gnmaps, "gnmap")
c.driver.execute_script(script)