def do_Network(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Network") if (command["on"] == True): e.EvalRetVal("service network start") elif (command["off"] == True): e.EvalRetVal("service network stop") elif (command["restart"] == True): e.EvalRetVal("service network stop") e.EvalRetVal("service network start") e.Log(e.r.getOutput())
def do_Process(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Process") if command["monitor"]: psopts = "/bin/ps -C %s o pcpu,pmem --cumulative --no-heading" % ( command["<name>"]) e.Log("Executing monitor " + psopts) counter = 0 cpu = float(0) mem = float(0) while (counter < int(command["<duration>"])): pcpu, pmem = self.parse(e.RetOutput(psopts)) cpu = cpu + pcpu mem = mem + pmem time.sleep(1) counter = counter + 1 output = "%s consumed %s%% cpu and %s %% memory" % ( command["<name>"], cpu / counter, mem / counter) e.Log(output) print output if cpu > 0 or mem > 0: e.setExecCodes("Process monitor", output, "Pass") else: e.setExecCodes("Process monitor", output, "Fail") elif command["kill"]: killopts = "/usr/bin/killall %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts) elif command["spawn"]: spawnopts = ' '.join(command["PATH"]) e.Log(spawnopts) e.Spawn(spawnopts) elif command["exec"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) elif command["forfeit"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) e.r.setRetVal("Fail") elif command["thrive"]: execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) e.EvalRetVal(execopts) e.r.setRetVal("Pass") elif command["alive"]: killopts = "/usr/bin/killall -s 0 %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts) elif command["dead"]: killopts = "pidof %s" % (command["<name>"]) e.Log(killopts) e.EvalRetVal(killopts, 1) elif command["pid"]: execopts = "pidof %s" % (command["<name>"]) e.Log(execopts) e.EvalRetVal(execopts) elif command["output"]: # Process output contains 1360x78 xdpyinfo | grep dimensions execopts = ' '.join(command["PATH"]) e.Log(execopts) execopts = "/bin/sh -c '%s' " % (execopts) output = e.RetOutput(execopts) if command['<expectation>'] in output: e.setExecCodes(execopts, output, "Pass") else: e.setExecCodes(execopts, output, "Fail") e.Log(e.r.getOutput()) print e.r.getRetVal()
def do_Dot1x(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Dot1x") e.EvalRetVal("regset --temp Network-eth0 Enable802 yes") e.EvalRetVal("regset Network-eth0 ca_cert " + command['<cacert>']) if (command["tls"] == True): e.Log("Configuring for tls") e.EvalRetVal("regset Network-eth0 Authentication TLS") e.EvalRetVal("regset Network-eth0 client_cert " + command['<clientcert>']) e.EvalRetVal("regset Network-eth0 private_key " + command['<privkey>']) e.EvalRetVal("regset Network-eth0 private_key_password " + command['<pkeypass>']) e.EvalRetVal("regset Network-eth0 Authmode " + command['<authmode>']) elif (command["peap"] == True): e.Log("Configuring for PEAP") e.EvalRetVal("regset Network-eth0 Authentication PEAP") e.EvalRetVal("regset Network-eth0 Authmode " + command['<authmode>']) elif (command["reset"] == True): e.Log("Doing dot1x reset") e.EvalRetVal("regdel Network-eth0 Authmode") e.EvalRetVal("regdel Network-eth0 Authentication") e.EvalRetVal("regdel Network-eth0 Enable802") e.EvalRetVal("regdel Network-eth0 ca_cert") e.EvalRetVal("regdel Network-eth0 client_cert") e.EvalRetVal("regdel Network-eth0 private_key") e.EvalRetVal("regdel Network-eth0 private_key_password")
def do_Desktop(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Desktop") if command["logout"]: e.EvalRetVal("/usr/bin/gnome-session-quit --no-prompt") elif command["resolution"]: cmd = "xrandr -d :0 --output LVDS --mode " + command["<resolution>"] e.Log("Desktop Resolution: " + cmd) e.EvalRetVal(cmd) elif command["screenshot"]: scrot = MSSLinux() for filename in scrot.save(output="scrot.png", screen=-1): shutil.move("scrot.png", command['<filename>']) e.Log('File: "{}" created.'.format(filename)) elif command["legacyScreenshot"]: os.system("gnome-screenshot -b -f " + command['<filename>']) elif command["windowimg"]: e.Log("Executing commands for windowimg") cmd = 'xte "mousemove 0 0"' e.Log(cmd) e.Execute(cmd) cmd = "./agent/cli/bin/windowimg.sh %s %s" % ( command['<filename>'], command['<windowid>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["windowid"]: e.Log("Executing commands for windowid") cmd = "./agent/cli/bin/windowid.sh %s" % (command['<process>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["windowfocus"]: e.Log("Executing commands for windowfocus") cmd = 'xdotool windowactivate %s' % (command['<windowid>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["windowclose"]: cmd = 'wmctrl -i -c %s' % (command['<windowid>']) e.Log("Executing windowclose: " + cmd) e.EvalRetVal(cmd) elif command["keydown"]: cmd = "xte keydown %s" % (command['<key>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["keyup"]: cmd = "xte keyup %s" % (command['<key>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["keypress"]: cmd = 'xte "sleep 1" "key %s"' % (command['<key>']) e.Log(cmd) e.EvalRetVal(cmd) elif command["type"]: e.Log("Desktop Typing keys") special = ["Alt", "Control", "Shift", "Super"] press = [] release = [] l = 0 for k in command['KEYS']: if k in special: press.append('"keydown ' + k + '_R"') release.append('"keyup ' + k + '_R"') elif len(release) > 0: press.append('"key ' + k + '"') release.reverse() press.extend(release) release = [] else: for char in k: press.append('"usleep 30000" "str ' + char + '"') #press.append('"str ' + k + '"') cmd = "xte " + ' '.join(press) e.EvalRetVal(cmd) elif command["mouseclick"]: e.Log("Desktop mouseclick") cmd = "./agent/cli/bin/mouseclick.sh %s %s %s" % ( command['<windowid>'], command['<windowimg>'], ' '.join( command['PATTERN'])) e.Log(cmd) e.EvalRetVal(cmd) #move the mouse out before it pollutes next screenshot e.Execute('xte "sleep 1" "mousemove 0 0"')
def do_Ping(self, args): command = docopt(str(self.doc), args) e = ExecHelper() e.reset("Ping") e.EvalRetVal("ping -c 1 " + command['<host>']) e.Log(e.r.getOutput())