Пример #1
0
 def do_Reboot(self, args):
     command = docopt(str(self.doc), args)
     e = ExecHelper()
     e.reset("Reboot")
     e.setExecCodes("Reboot", "Unknown error", "Fail")
     prepare = 'echo %s|sudo -S shutdown -k +1' % (
         command['<sudopassword>'])
     e.Log("Checking our permissions")
     e.Log(prepare)
     if e.Execute(prepare) == 0:
         cmd = 'shutdown -r +1 &'
         e.Log(cmd)
         e.Log(
             "Alert: This will wipe out all the variables created before.")
         p = e.Execute('echo %s|sudo -S %s' %
                       (command['<sudopassword>'], cmd))
         e.setExecCodes("Reboot", "Going down in 1 minute", "Reboot")
Пример #2
0
 def do_Gdm(self, args):
     command = docopt(str(self.doc), args)
     e = ExecHelper()
     e.reset("Gdm")
     cmd = "pidof X"
     pid = e.RetOutput(cmd).strip()
     cmd = "sh -c 'xargs -0 < /proc/" + pid + "/cmdline'"
     e.Log(cmd)
     xcmdline = e.RetOutput(cmd).split()
     count = len(xcmdline)
     i = 0
     while i < count:
         if xcmdline[i] == "-auth":
             xauthority = xcmdline[i + 1]
         i += 1
     os.environ['XAUTHORITY'] = xauthority
     if command['login']:
         for word in command['PHRASE']:
             word = word.strip()
             if word == "{Tab}":
                 cmd = 'echo %s|sudo -S xdotool key Tab' % (
                     command['<sudopassword>'])
             elif word == "{Return}":
                 cmd = 'echo %s|sudo -S xdotool key Return' % (
                     command['<sudopassword>'])
             elif word == "{Clear}":
                 cmd = 'echo %s|sudo -S xdotool key ctrl+a Delete' % (
                     command['<sudopassword>'])
             elif word == "{Space}":
                 cmd = 'echo %s|sudo -S xdotool key space' % (
                     command['<sudopassword>'])
             else:
                 cmd = 'echo %s|sudo -S xdotool type %s' % (
                     command['<sudopassword>'], word)
             e.Log(cmd)
             e.Execute(cmd)
             time.sleep(2)
             e.Log(e.r.output)
     else:
         cmd = "xdotool key ctrl+alt+Delete"
         e.Execute(cmd)
         time.sleep(2)
         e.Execute("sleep 30 && xdotool key Return &")
         e.setExecCodes("Reboot", "Going out in 1/2 minute", "Reboot")
         e.Log(e.r.output)
Пример #3
0
 def do_Mcast(self, args):
     command = docopt(str(self.doc), args)
     e = ExecHelper()
     e.reset("Mcast")
     if command['server']:
         cmd = "python /tmp/mcastfirmware/server.py %s" % (
             command['<filepath>'])
         e.Spawn(cmd)
     elif command['client']:
         cmd = "python /tmp/mcastfirmware/client.py"
         e.Execute(cmd)
     e.Log(e.r.getOutput())
Пример #4
0
 def initialize(self, sudopassword):
     cmds = [
         "sudo -S iptables -F AF", "sudo iptables -F OUTPUT",
         "sudo iptables -X AF", "sudo -S iptables -N AF",
         "sudo -S iptables -A AF -p tcp --dport 80 -m string --string 'GET /' --algo bm -j ACCEPT",
         "sudo -S iptables -A AF -p tcp --dport 80 -m string --string 'POST /' --algo bm -j ACCEPT",
         "sudo -S iptables -A AF -p tcp --dport 80 -m string --string 'PUT /' --algo bm -j ACCEPT",
         "sudo -S iptables -A OUTPUT -o lo -j AF"
     ]
     e = ExecHelper()
     for c in cmds:
         cmd = "echo %s|%s" % (sudopassword, c)
         e.Execute(cmd)
Пример #5
0
 def do_HTTPCounter(self, args):
     command = docopt(str(self.doc), args)
     e = ExecHelper()
     e.reset("HTTPCounter")
     sudopassword = command['<sudopassword>']
     if command["initialize"]:
         e.Log("HTTPCounter initalizing")
         self.initialize(sudopassword)
         e.setExecCodes(args, "Warning: Does not verify execution", "Pass")
     elif command["resetCounter"]:
         cmd = "echo %s|sudo -S iptables -Z AF" % (sudopassword)
         e.Log("HTTPCounter resetCounter")
         e.Execute(cmd)
         e.setExecCodes(args, "Warning: Does not verify execution", "Pass")
     elif command["getCount"]:
         cmd = "sh -c 'echo %s|sudo -S iptables -vL AF'" % (sudopassword)
         lines = e.RetOutput(cmd).split(os.linesep)
         output = " GET  " + lines[2].split()[0]
         output += " POST " + lines[3].split()[0]
         output += " PUT " + lines[4].split()[0]
         e.r.setOutput(output)
         print output
Пример #6
0
 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"')