Beispiel #1
0
def nmapdel(data):
  reqfile = "workspace/" + data['workspace'] + "/temp/" + data['file']
  if not os.path.isfile(reqfile):
    socketio.send("Requested Delete on unknown file.", namespace="/notify")
    return
  os.remove(reqfile) 
  socketio.send("File removed", namespace="/notify")
Beispiel #2
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 #3
0
def nmapsave(data):
  reqfile = "workspace/" + data['workspace'] + "/temp/" + data['file']
  destfile = "workspace/" + data['workspace'] + "/nmap/" + data['file']
  if not os.path.isfile(reqfile):
    socketio.send("Requested Save on unknown file.", namespace="/notify")
    return

  shutil.move(reqfile, destfile)
  manifest = "./workspace/" +  data['workspace'] + "/manifest.xml"
  tree = lxml.etree.parse(manifest)
  parent = tree.xpath(".//nmap")
  lxml.etree.SubElement(parent[0], 'scan').text = data['file']

  # this has a filthy output. xml beautification is required to make the manifest readable
  tree.write(manifest, pretty_print=True, xml_declaration=True, encoding="utf-8")
  socketio.send("File saved to workspace", namespace="/notify")
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 #5
0
def addwksp(data):
    if not data:
        socketio.send("No requested workspace", namespace="/notify")
        return
    wksp = "./workspace/workspaces.xml"
    wkspdir = "./workspace/" + data
    tree = lxml.etree.parse(wksp)
    root = tree.getroot()
    parent = tree.xpath(".//name[text()='" + data + "']/..")
    if parent:
        socketio.send("Workspace already exists", namespace="/notify")
        return
    root.append(lxml.etree.Element("workspace"))

    lxml.etree.SubElement(root[-1], 'name').text = data
    lxml.etree.SubElement(root[-1], 'active').text = "false"
    lxml.etree.SubElement(root[-1], 'default').text = "false"
    tree.write(wksp, pretty_print=True, xml_declaration=True, encoding="utf-8")

    if not os.path.isdir(wkspdir):
        os.makedirs(wkspdir)
    socketio.send("Created workspace " + data, namespace="/notify")
    print(tree)