Beispiel #1
0
def nmapcall(data):
  if app.config["nmap_child"]:
    socketio.send("nmap already running", namespace="/notify")
    return
  host = data['host']
  args = data['args'].split(' ')
  workspace = data['workspace']
  if not host:
    socketio.send("no host set", namespace="/notify")
    return
  final = ['nmap'] + args + [host]
  
  with subprocess.Popen(final,
          stdout=subprocess.PIPE,
          stdin=subprocess.PIPE,
          stderr=subprocess.PIPE,
          bufsize=1,
          universal_newlines=True) as process:
    app.config["nmap_child"] = process.pid
    nmapofname = str(uuid.uuid4().hex)+ "-" + str(process.pid) +".nmap"
    nmapoutfile = open("./workspace/"+workspace+"/temp/" + str(nmapofname), "a")

    for line in process.stdout:
        line = line.rstrip()
        socketio.emit("nmapout", {"output": line}, namespace="/nmap")
        nmapoutfile.write(line + "\n")
        if "Nmap done:" in line:
            app.config["nmap_child"] = None
            socketio.send("nmap done", namespace="/notify")
    socketio.emit("nmapfname",nmapofname, namespace="/nmap")
    socketio.send("File written to: " + nmapofname, namespace="/notify")
    nmapoutfile.close()
Beispiel #2
0
def read_and_forward_pty_output():
    max_read_bytes = 1024 * 20
    while True:
        socketio.sleep(0.01)
        if app.config["fd"]:
            timeout_sec = 0
            (data_ready, _, _) = select.select([app.config["fd"]], [], [],
                                               timeout_sec)
            if data_ready:
                output = os.read(app.config["fd"], max_read_bytes).decode()
                socketio.emit("pty-output", {"output": output},
                              namespace="/pty")
def setwksp(data):
    if not data:
        socketio.send("No requested workspace", namespace="/notify")
        return
    wksp = "./workspace/workspaces.xml"
    tree = lxml.etree.parse(wksp)
    parent = tree.xpath(".//name[text()='" + data + "']/..")
    curractive = tree.xpath(".//active[text()='true']/..")
    if not parent:
        socketio.send("Workspace not found", namespace="/notify")
        return

    if curractive == parent:
        socketio.send("Already using this workspace", namespace="/notify")
        return
    parent[0][1].text = "true"
    curractive[0][1].text = "false"
    tree.write(wksp, pretty_print=True, xml_declaration=True, encoding="utf-8")
    socketio.send("Now using workspace " + data +
                  " | Window will refresh to reflect changes",
                  namespace="/notify")
    socketio.emit("reloadws", namespace="/wscommand")
    return
Beispiel #4
0
def update():
    global lastdata
    cpuusg = psutil.cpu_percent()
    memusg = psutil.virtual_memory().percent

    #If the revshell is connected, check if it's still
    if app.revshell["status"] == "connected":
        try:
            data = app.revshell["client"].recv(1024, socket.MSG_PEEK)
            if len(data) == 0 or lastdata == data:
                app.revshell["status"] = "disconnected"
                app.revshell["client"] = None
            else:
                lastdata = data
        except:
            pass

    #Try to connect the revshell
    else:
        try:
            client, _ = app.revshell["sock"].accept()
            client.setblocking(0)
            print("received revshell conn")
            app.revshell["status"] = "connected"
            app.revshell["client"] = client
        except:
            pass

    socketio.emit(
        'update', {
            'cpuusage': cpuusg,
            'memusage': memusg,
            'revshell': {
                'status': app.revshell["status"]
            }
        })
Beispiel #5
0
def read_and_forward():
    while True:
        socketio.sleep(.01)
        if app.revshell["status"] == "connected":
            try:
                data = app.revshell["client"].recv(1024)
                socketio.emit("rshell-update", {
                    "status": "connected",
                    "data": data.decode("utf-8")
                })
            except:
                socketio.emit("rshell-update", {
                    "status": "connected",
                    "data": ""
                })
                pass
        else:
            socketio.emit("rshell-update", {"status": "disconnected"})
Beispiel #6
0
def getusg():
    cpuusg = psutil.cpu_percent()
    memusg = psutil.virtual_memory().percent
    socketio.emit('getusg', {'cpuusage': cpuusg, 'memusage': memusg})