Exemple #1
0
def __find_attack_node(log, picker, pn, node):
	osloader.set_logdir(log)

	s = os.stat(pn)
	hint = ('ino', s.st_dev, s.st_ino) # ipopov: useful for reference
	mgrapi.RegisteredObject.by_name_load(hint)

	done = False
	for o in mgrapi.RegisteredObject.all():
		if done:
			break
		if isinstance(o, mgrutil.StatelessActor):
			for a in o.actions:
				cond = picker(a.argsnode.origdata)
				if cond is None:
					continue
				if cond & PICK_ATTACK:
					attack_node_name = o.name
				if cond & PICK_STOP:
					done = True

	if not done:
		raise "Failed to find attacker's binary `%s' with `%s'" % (pn, pick)

	node.value = str(attack_node_name)
Exemple #2
0
def last():
    if stats:
        results = [(v, k) for k, v in stats.items()]
        results.sort(reverse=True)
        sys.stderr.write(
            "\n     size   cnt   ave       time  #cnt     syscall\n")
        sys.stderr.write("=" * 70 + "\n")
        syms = ["", ">", "<", "<>"]
        for (size, count, time, time_cnt), (nr, usage) in results:
            name = syscalls[nr].name
            avr_time = (time / time_cnt if time_cnt != 0 else time)
            sys.stderr.write("%9s %5s %5s %10s %5s %5s %s\n" \
                % (size, count, size/count,
                   avr_time, time_cnt,
                   syms[usage], name))
        sys.stderr.write("=" * 70 + "\n")

        sys.stderr.write("pids:\n")
        for (pid, r) in pids.iteritems():
            sys.stderr.write("  %s:%s\n" % (pid, r))


if __name__ == "__main__":
    d = True
    for fn in sys.argv[1:]:
        if d:
            osloader.set_logdir(os.path.dirname(fn))
            d = False
        main(fn)
    last()
Exemple #3
0
    except:
        pass
    return "connection refused"

global logd
logd = "/tmp"

# repair event generators
class Worker(threading.Thread):
    def run(self):
        while True:
            if The(CtrlFSM).curstate == "repairing":
                if The(CtrlFSM).repair() == False:
                    The(CtrlFSM).set_state("ready")
            else:
                # repsonse time
                time.sleep(0.1)

if __name__ == '__main__':
    if "-d" in sys.argv:
        if len(sys.argv) > 2:
            logd = sys.argv[-1]
        osloader.set_logdir(logd)
        Worker().start()
        daemon_main()
    else:
        rtn = send_request(os.popen("hostname -I").read(), PORT, *sys.argv[1:])
        print "=" * 60
        print "%s" % rtn
        print "=" * 60
Exemple #4
0
def strace(dirp):
    osloader.set_logdir(dirp)
    for x in record.load(dirp):
        print('0x%04x' % x.sid), x
Exemple #5
0
def main():
    atexit.register(retroctl.disable)

    parser = optparse.OptionParser(usage="%prog [options] LOG-DIRECTORY")
    parser.add_option("-d",
                      "--dry",
                      default=False,
                      action="store_true",
                      dest="dryrun",
                      help="dry run for repair")
    parser.add_option("-a",
                      "--attk",
                      dest="attack",
                      metavar="NAME",
                      default="pick_attack_execve",
                      help="algorithm to pick attacker's node")
    parser.add_option("-p",
                      "--profile",
                      default=False,
                      action="store_true",
                      dest="profile",
                      help="profiling execution time")

    # hints
    parser.add_option("-i",
                      "--inode",
                      dest="inode_hint",
                      metavar="FILE",
                      default=None,
                      help="attacker's binary")

    (opts, args) = parser.parse_args()

    if opts.profile:
        runopts.set_profile()

    if len(args) != 1 or not opts.inode_hint:
        parser.print_usage()
        exit(1)

    # pick attack
    attack = attacker.find_attack_node(args[0], opts.attack, opts.inode_hint)

    osloader.set_logdir(args[0])
    attack_node = mgrapi.RegisteredObject.by_name_load(attack)
    print_tics_tacs()
    if attack_node is None:
        raise Exception('missing attack node', attack)

    chkpt = max(c for c in attack_node.checkpoints
                if c < min(attack_node.actions))
    assert chkpt

    assert len(attack_node.actions) == 1
    #code.interact(local=locals())
    #pdb.set_trace()

    # cancel exec syscall actor
    for a in attack_node.actions:
        dbg.info("cancel: %s" % a.argsnode)
        a.argsnode.data = None
        a.cancel = True

    dbg.info("pick:", chkpt)

    runopts.set_dryrun(opts.dryrun)

    ctrl.repair(attack_node, chkpt)