Skip to content

Instantly share code, notes, and snippets.

@mad
Created January 28, 2012 11:50
Show Gist options
  • Save mad/1694062 to your computer and use it in GitHub Desktop.
Save mad/1694062 to your computer and use it in GitHub Desktop.
Trying retrieve collection from mongodb
Index: scripts/mongodb-databases.nse
===================================================================
--- scripts/mongodb-databases.nse (revision 27936)
+++ scripts/mongodb-databases.nse (working copy)
@@ -65,6 +65,20 @@
status, result = mongodb.query(socket, packet)
if not status then return result end-- Error message
+ for k,v in pairs(result["databases"]) do
+ local result2, colls
+
+ --Build packet
+ status, packetcolls = mongodb.listCollectionQuery(v["name"])
+ -- if not status then return result end-- Error message
+
+ -- Send packet
+ status, colls = mongodb.query(socket, packetcolls)
+ if status then
+ result["databases"][k]["collections"] = colls
+ end
+ end
+
port.version.name ='mongodb'
port.version.product='MongoDB'
nmap.set_port_version(host,port,'hardmatched')
@@ -73,6 +87,7 @@
if err ~= nil then
stdnse.log_error(err)
end
+
if result ~= nil then
return stdnse.format_output(true, output )
end
Index: nselib/mongodb.lua
===================================================================
--- nselib/mongodb.lua (revision 27936)
+++ nselib/mongodb.lua (working copy)
@@ -171,6 +171,8 @@
-- And return where the parsing stopped
return obj_size+1, object
--6 = _get_null
+ elseif 6 == code then -- null
+ return 0,nil
--7 = _get_oid
elseif 8 == code then -- Boolean
return 2, data:byte(1) == 1
@@ -452,6 +454,14 @@
local query = {listDatabases = 1}
return createQuery(collectionName, query)
end
+
+-- TODO:
+function listCollectionQuery(dbName)
+ local collectionName = dbName .. ".system.namespaces"
+ local query = {}
+ return createQuery(collectionName, query)
+end
+
-- Creates a build info query
-- @param responseTo optional identifier this packet is a response to
--@return status : true for OK, false for error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment