0

I'm having a heck of a time trying to assign the Login and Password JSON parameters to a python variable using PyMongo. Here is the JSON stored in Mongo:

{"_id":"5a2700c9eb0a197ba6f8120d"
"protocol":"ssh"
"hpfeed_id":"5a2700c7eb0a197ba6f8120a"
"timestamp":"2017-12-05T20:25:43.922Z"
"source_ip":"37.221.198.242"
"session_ssh":{"version":"SSH-2.0-libssh2_1.4.3"}
"source_port":45557
"destination_port":22
"identifier":"da258962-c5b5-11e7-9c0a-1e7dbf5015ae"
"honeypot":"cowrie"
"auth_attempts":[{"login":"worker2","password":"worker2"}]}

enter image description here

The auth_attempts is an array type and I can not for the life of me figure out how to get it to a string in Python. Here is what I have been trying so far:

# Query the MongoDB for required data
def query():
    sessionData = session.find({})
    numOfSessions = session.find({}).count()
    pprint.pprint(session.find_one({'auth_attempts': { 'login': [0] }}))
    for item in sessionData:
       if (item['honeypot'] != 'p0f'):
            test = item({'auth_attempts': { '$in': [0] }})
            print(str(test))

1 Answer 1

1

Im guessing you would like a string something like:

"login: worker2, password:worker2"

From your code snippet your item is a dict. So to get the auth_attempts in string you should be able to do something like:

for item in sessionData:
    for auth in item.get('auth_attempts'):
        print('login: {}, password:{}'.format(auth.get('login'), auth.get('password'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.