Issue trying to create a forge_relationship patch api call using python

21 views
Skip to first unread message

Nate P

unread,
Jun 5, 2017, 3:46:33 PM6/5/17
to crits-users
Hello group,
  A lot of the answers here have helped me through getting different aspects of the code to work, but for whatever reason I am having a difficult time writing a patch to forge a relationship between two objects. In the code example below I am creating a new object and returning the object's id as a new variable. I am then attempting to forge a relationship between that new domain and an actor whose ID I am hard coding into the script for testing purposes. Running the code returns the following error:

{"message": "Could not find relationship type", "type": "Actor", "return_code":
1, "id": "593576213a044e5646baa191"}

Could anyone point me in the right direction? 

Bonus question when looking at the handler for relationships can someone point me in the direction on how to figure out the class for right_class and class_? I feel like that will be my next big hurdle.

Thank you!

Nate

Example Code

import requests
import json
import datetime

data = {
'api_key': 'REDACTED',
'username': 'testuser',
'source': 'Test',
'domain': 'www.fakedomain.com',
'ip': '127.0.0.2'
}
r = requests.post(url, data=data, verify=False)
event_id = r.json().get('id')

params = {
    'api_key' : 'REDACTED',
    'username' : 'testuser'
}

headers = {
    'Content-Type' : 'application/json',
}

# date must be in the format %Y-%m-%d %H:%M:%S.%f
formatted_date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')

data = {
    'action' : 'forge_relationship',
    'right_type': 'Domain',
    'right_id':  event_id,
    'type_': 'Actor',
    'id_': '593576213a044e5646baa191'

}


r = requests.patch(submit_url, headers=headers, params=params, data=json.dumps(data), verify=False)

Nate P

unread,
Jun 6, 2017, 12:33:14 PM6/6/17
to crits-users
I was able to solve it, and here is how!

First off the data section used to forge the relationship ended up looking like this:

data = {
    'action' : 'forge_relationship',
    'right_type': 'Domain',
    'right_id':  event_id,
    'type_': 'Actor',
    'id_': '593576213a044e5646baa191',
    'rel_type': 'Related To',
    'rel_confidence': 'high'

}

What I realized I could do, was go into the GUI and under relationship use that box to build out what fields I needed for my script. This then matched in the handlers section, and worked. 

Hopefully his helps someone!


Reply all
Reply to author
Forward
0 new messages