lmco / dart

DART is a test documentation tool created by the Lockheed Martin Red Team to document and report on penetration tests, especially in isolated network environments.
Apache License 2.0
257 stars 56 forks source link

Fluent MongoDB (Security Data/Mongor) #22

Closed howtotalktogirlsatparties closed 4 months ago

howtotalktogirlsatparties commented 1 year ago

If you’ve Mongo you’ve discovered that communicating with MongoDB via Documents is painful. We care about storing our domain objects and having powerful ways of fetching them again from the data store. How do we accomplish those tasks when then tool doesn’t offer those options?

The answer is, of course, we extend the tool so that we can express our intent in the most natural language we can. To me this means Linq or some reasonable subset thereof.

So lets start with the domain object Person:

mongodb
[Serializable]
    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

The object is marked Serializable but is otherwise unremarkable. If I have an instance of person I’d like to be able to simply pass it to a Save method on the collection as follows.

    var person = new Person
    {
        FirstName = "Loreena",
        LastName = "McKennitt"
    };
    _people.Save(person);

We can’t change the IMongoCollection object directly but we can use an extension method to build the interface we’re looking for:

    public static class IMongoCollectionExtensions
    {
        public static void Save<T>(this IMongoCollection collection, T item) where T: class
        {
            // magic happens
        }
    }

I know there is some support for FluentMongo, but is this possible?

Montana commented 1 year ago

Hi @howtotalktogirlsatparties,

It's outdated and deprecated probably, but why do this when you can use Lockheed Martin's python-mongor` Lockheed Martin have really good scripts til this day, for example:

#!/bin/bash

SPEC_FILE=python-pymongor.spec 

# Change to source dir
cd $(dirname $0)/../

SRC_DIR=`pwd`

echo 'Running setup.py bdist_rpm'
python setup.py bdist_rpm

echo 'Setting up build environment'
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

echo 'Copying source files to rpmbuild directory'
cp dist/*.tar.gz ~/rpmbuild/SOURCES/
cp rpm/rotate_mongodb.cron ~/rpmbuild/SOURCES/
cp scripts/mongor_manage.py ~/rpmbuild/SOURCES/
cp rpm/$SPEC_FILE ~/rpmbuild/SPECS/

echo 'Making RPM'
cd ~/rpmbuild/SPECS/
rpmbuild -ba $SPEC_FILE

I recommend you taking a look at the Mongo repo: https://github.com/lmco/python-mongor.

Cheers, Montana Mendy