示例#1
0
    def run_probe(self, target, pcm_path, interval, outdir):
        logger.info(
            "Running Intel PCM probe with interval %s and writing to %s" %
            (interval, outdir))

        self.target = target

        outfile = outdir + "/tmp_pcm.csv"
        cmd_args = " ".join([interval, "/csv=" + outfile])
        self.pcm_thread = utils.run_anywhere(target, pcm_path + "/pcm.x",
                                             cmd_args, None, None, True)
        self.pcm_thread.remote_stdout = self.pcm_thread.local_stdout = outfile

        outfile = outdir + "/tmp_pcmmemory.csv"
        cmd_args = " ".join([interval, "/csv=" + outfile])
        self.pcmmemory_thread = utils.run_anywhere(target,
                                                   pcm_path + "/pcm-memory.x",
                                                   cmd_args, None, None, True)
        self.pcmmemory_thread.remote_stdout = self.pcmmemory_thread.local_stdout = outfile

        outfile = outdir + "/tmp_pcmpower.csv"
        cmd_args = " ".join([interval, "/csv=" + outfile])
        self.pcmpower_thread = utils.run_anywhere(target,
                                                  pcm_path + "/pcm-power.x",
                                                  cmd_args, None, None, True)
        self.pcmpower_thread.remote_stdout = self.pcmpower_thread.local_stdout = outfile
示例#2
0
    def run(self, target, paths, tshark_filter="tcp", background=False):
        logger.info("Starting PCAP to TCP CSV transformer for file %s" % paths)
        new_paths = []
        for path in paths:
            params = [
                "-r",
                "%s" % path, "-E", "header=y", "-E", "separator=;", "-Y",
                "%s" % tshark_filter, "-T", "fields", "-e",
                "frame.time_relative", "-e", "frame.time", "-e",
                "frame.number", "-e", "tcp.stream", "-e", "ip.src", "-e",
                "ip.dst", "-e", "tcp.srcport", "-e", "tcp.dstport", "-e",
                "tcp.flags.ack", "-e", "tcp.flags.fin", "-e",
                "tcp.flags.reset", "-e", "tcp.flags.syn", "-e",
                "tcp.analysis.keep_alive", "-e", "tcp.analysis.lost_segment",
                "-e", "tcp.analysis.out_of_order", "-e",
                "tcp.analysis.retransmission", "-e",
                "tcp.analysis.fast_retransmission", "-e",
                "tcp.analysis.spurious_retransmission"
            ]
            new_path = ".".join(path.split(".")[:-1]) + "_tcp.csv"
            utils.run_anywhere(target, "tshark", params, new_path, None,
                               background)
            new_paths.append(new_path)

        logger.info("Leaving PCAP to TCP CSV transformer")
        return None if new_paths == [] else new_paths
示例#3
0
def launch_fi(target, path, pid, input):
    logger.info("Launching hard reboot injector")

    #reboot --no-sync --no-wtmp --no-wall -f; reboot --no-sync --no-wtmp --no-wall -f;
    # Some systems do not have --no-sync
    utils.run_anywhere(target, "reboot", "--no-wtmp --no-wall -f", False, None,
                       False)

    logger.info("Leaving hard reboot injector")
示例#4
0
 def run_probe(self, target, local_dir, file):
     logger.info("Running Xentrace probe, saving on %s" % file)
     self.local_dir = local_dir
     self.target = target
     self.probe_thread = utils.run_anywhere(target, "xentrace", file, None,
                                            None, True)
     self.probe_thread.remote_stdout = file
示例#5
0
    def run(self, target, paths, keep=True):
        logger.info("Starting Sar to CSV transformer for files %s" % paths)

        new_paths = []
        for path in paths:
            cmd = "-U -d %s -- -b -B -q -r -S -u" % path
            (out, _) = utils.run_anywhere(target, "sadf", cmd, True, None,
                                          False)

            # Divide the output into several parts, according to headers
            parts = out.split("#")
            dfs = []
            for part in parts[1:]:
                tmp = pd.read_csv(StringIO(part.lstrip()),
                                  sep=";",
                                  header=0,
                                  decimal=',',
                                  index_col='timestamp')
                # Because of join() we need to delete the repeated columns, which are also useless for us...
                del tmp["interval"]
                del tmp["hostname"]
                dfs.append(tmp)

            final = dfs[0].join(dfs[1])
            new_path = ".".join(path.split(".")[:-1]) + ".csv"
            final.to_csv(new_path, sep=";")
            new_paths.append(new_path)

        logger.info("Leaving Sar to CSV transformer")
        return None if new_paths == [] else new_paths
示例#6
0
    def run_probe(self, source, local_dir, target, rate="0.1"):

        logger.info("Running Ping probe. Source %s to target %s" % (source, target))
        self.source = source
        self.target = target
        self.local_dir = local_dir
        self.remote_dir = "/tmp/ping_out%s.txt" % time.time()
        #cmd_args = "-D -A -n -O %s" % target.ip
        cmd_args = " ".join(["-D", "-n", "-i", rate,  target.ip])
        self.probe_thread = utils.run_anywhere(source, "ping", cmd_args, self.remote_dir, None, True)
示例#7
0
	def run_probe(self, target, local_dir, BINARY_FILE, interval_str):
		logger.info("Running SAR probe, writing to %s with interval %s" % (BINARY_FILE, interval_str))

		self.local_dir = local_dir

		#probe_thread = subprocess.Popen(["sar" ,"-b" ,"-B" ,"-q" ,"-r" ,"-R" ,"-S" ,"-u"  interval_str], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		# Some systems dont have -R
		#with open(os.devnull, 'w') as devnull:
		#	self.probe_thread = subprocess.Popen(["sar" ,"-b" ,"-B" ,"-q" ,"-r" ,"-S" ,"-u", "-o", BINARY_FILE, interval_str], stdin=None, stdout=devnull, stderr=subprocess.PIPE)
		self.target = target
		cmd_args = " ".join(["-b" ,"-B" ,"-q" ,"-r" ,"-S" ,"-u", "-o", BINARY_FILE, interval_str])
		self.probe_thread = utils.run_anywhere(target, "sar", cmd_args, None, None, True)
		self.probe_thread.remote_stdout = self.probe_thread.local_stdout = BINARY_FILE
示例#8
0
def launch_fi(target, fi_path, pid_selector_f, times, regs=None, bits=None):
	logger.info("Launching ucXception HW FI")
	(min_time, max_time) = times

	min_reg = 0
	max_reg = 26
	if regs is not None:
		(min_reg, max_reg) = regs

	min_bit = 0
	max_bit = 63
	if bits is not None:
		(min_bit, max_bit) = bits

	# Choose random injection time inside [min_time, max_time]
	inj_time = random.randint(min_time, max_time)

	# Choose random register to inject
	reg = random.randint(min_reg, max_reg)

	# Choose random bit to inject
	bit = random.randint(min_bit, max_bit)

	time.sleep(inj_time/1000.0)
	# Get all the threads from the process and choose one of them randomly to target
	# Uses Linux-specific way of doing so

	
	"""thread_list = apply(pid_selector_f[0], (pid_selector_f[1], ))
	chosen_thread = -1
	thread_rel_pos = -1
	if (len(thread_list) > 0):
		chosen_thread = int(random.choice(thread_list))
	else:
		print "Empty thread_list"""
	chosen_thread = pid_selector_f
	logger.debug("FI thread is %d" % chosen_thread)

	# Build the params
	fi_param = "%d %d %d %d" % (chosen_thread, reg, bit, inj_time)
	logger.debug("FI params are " + fi_param)
	fiHandle = utils.run_anywhere(target, fi_path, fi_param, True, None, False)
	(stdout, stderr) = fiHandle
	logger.debug("FI stdout: %s" % stdout)
	logger.debug("FI stderr: %s" % stderr)
	# Launch the injector and wait for it to finish to read the results
	#(stdout, stderr) = fiHandle.communicate()


	# Parse the results from stdout
	return inj_time, reg, bit, chosen_thread, stdout, stderr
示例#9
0
    def run_probe(self, target, local_dir, if_name, outfile, rule=None):
        logger.info(
            "Running Tcpdump probe, tapping on %s interface and writing to %s"
            % (if_name, outfile))

        # -K (not included right now) means dont verify checksums.
        # -B sets the buffer size in kilobytes, can be fine tuned to avoid loss packets
        # -p means no promiscuous mode. We dont need it usually as we just want to capture our traffic.
        if (rule == None):
            rule = ""
        cmd_args = " ".join([
            "-B", "62000", "-p", "-i", if_name, "-K", "-n", "-w", outfile, rule
        ])
        self.target = target
        self.local_dir = local_dir
        self.probe_thread = utils.run_anywhere(target, "tcpdump", cmd_args,
                                               None, None, True)
        self.probe_thread.remote_stdout = self.probe_thread.local_stdout = outfile
示例#10
0
    def run_probe(self,
                  target,
                  local_dir,
                  pid,
                  interval_str,
                  all_children=False):
        logger.info("Running Pidstat probe, tracing PID %d with interval %s" %
                    (pid, interval_str))

        self.target = target
        self.local_dir = local_dir
        local_file = os.path.join(self.local_dir,
                                  "%s_pidstat.txt" % utils.get_ip(self.target))

        task_type = "CHILD" if all_children else "TASK"
        cmd_args = " ".join([
            "-h", "-d", "-l", "-r", "-s", "-w", "-t", "-T", task_type, "-u",
            "-w", "-p",
            str(pid), interval_str
        ])
        self.probe_thread = utils.run_anywhere(target, "pidstat", cmd_args,
                                               local_file, subprocess.PIPE,
                                               True)
示例#11
0
 def launch(self):
     self._start_clock()
     self.p = utils.run_anywhere(self.remote_hosts["faulty"], "/bin/sleep",
                                 "10", None, None, True)
     self._stop_clock("launch")