mirror of https://github.com/MISP/PyMISP
new: Helper to create MISP Objects for regcheck.org.uk
parent
64bcaad0e5
commit
1e060f669f
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from pymisp.tools import VehicleObject
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='Get information for a VehicleObject and add MISP objects to a MISP instance.')
|
||||||
|
parser.add_argument("-u", "--username", required=True, help="Account username.")
|
||||||
|
parser.add_argument("-c", "--country", required=True, help="Country.")
|
||||||
|
parser.add_argument("-r", "--registration", required=True, help="Registration ID.")
|
||||||
|
parser.add_argument("-d", "--dump", action='store_true', help="(Debug) Dump the object in the terminal.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.dump:
|
||||||
|
vehicle = VehicleObject(country=args.country, registration=args.registration, username=args.username)
|
||||||
|
print(vehicle.report)
|
||||||
|
print(vehicle.to_json())
|
||||||
|
else:
|
||||||
|
# not Implemented yet.
|
||||||
|
pass
|
|
@ -1 +1 @@
|
||||||
Subproject commit 047595ddeb496a9cba294064902dd6fb5641cde7
|
Subproject commit 0c6b7b4302b58b0b1ab8371acdd3e4b988609a88
|
|
@ -18,3 +18,4 @@ from .geolocationobject import GeolocationObject # noqa
|
||||||
|
|
||||||
if sys.version_info >= (3, 6):
|
if sys.version_info >= (3, 6):
|
||||||
from .emailobject import EMailObject # noqa
|
from .emailobject import EMailObject # noqa
|
||||||
|
from .vehicleobject import VehicleObject # noqa
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import getopt
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from pymisp import MISPObject
|
||||||
|
|
||||||
|
from .abstractgenerator import AbstractMISPObjectGenerator
|
||||||
|
|
||||||
|
# Original sourcecode: https://github.com/hayk57/MISP_registration_check
|
||||||
|
|
||||||
|
|
||||||
|
class VehicleObject(AbstractMISPObjectGenerator):
|
||||||
|
'''Vehicle object generator out of regcheck.org.uk'''
|
||||||
|
|
||||||
|
country_urls = {
|
||||||
|
'fr': "http://www.regcheck.org.uk/api/reg.asmx/CheckFrance",
|
||||||
|
'es': "http://www.regcheck.org.uk/api/reg.asmx/CheckSpain",
|
||||||
|
'uk': "http://www.regcheck.org.uk/api/reg.asmx/Check"
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, country: str, registration: str, username: str, standalone=True, **kwargs):
|
||||||
|
super(VehicleObject, self).__init__("vehicle", standalone=standalone, **kwargs)
|
||||||
|
self._country = country
|
||||||
|
self._registration = registration
|
||||||
|
self._username = username
|
||||||
|
self._report = self._query()
|
||||||
|
self.generate_attributes()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def report(self):
|
||||||
|
return self._report
|
||||||
|
|
||||||
|
def generate_attributes(self):
|
||||||
|
carDescription = self._report["Description"]
|
||||||
|
carMake = self._report["CarMake"]["CurrentTextValue"]
|
||||||
|
carModel = self._report["CarModel"]["CurrentTextValue"]
|
||||||
|
ImageUrl = self._report["ImageUrl"]
|
||||||
|
IndicativeValue = ''
|
||||||
|
if (self._country == "fr"):
|
||||||
|
IndicativeValue = self._report["IndicativeValue"]["CurrentTextValue"]
|
||||||
|
# BodyStyle = vehicleJson["BodyStyle"]["CurrentTextValue"]
|
||||||
|
# RegistrationDate = vehicleJson["RegistrationDate"]
|
||||||
|
VIN = self._report["ExtendedData"]["numSerieMoteur"]
|
||||||
|
gearbox = self._report["ExtendedData"]["boiteDeVitesse"]
|
||||||
|
dynoHP = self._report["ExtendedData"]["puissanceDyn"]
|
||||||
|
firstRegistration = self._report["ExtendedData"]["datePremiereMiseCirculation"]
|
||||||
|
|
||||||
|
self.add_attribute('dyno-power', type='text', value=dynoHP)
|
||||||
|
self.add_attribute('gearbox', type='text', value=gearbox)
|
||||||
|
|
||||||
|
if (self._country == "es"):
|
||||||
|
IndicativeValue = self._report["IndicativePrice"]
|
||||||
|
|
||||||
|
if (self._country == "es" or self._country == "uk"):
|
||||||
|
firstRegistration = self._report["RegistrationYear"]
|
||||||
|
VIN = self._report["VehicleIdentificationNumber"]
|
||||||
|
|
||||||
|
self.add_attribute('description', type='text', value=carDescription)
|
||||||
|
self.add_attribute('make', type='text', value=carMake)
|
||||||
|
self.add_attribute('model', type='text', value=carModel)
|
||||||
|
self.add_attribute('vin', type='text', value=VIN)
|
||||||
|
self.add_attribute('license-plate-number', type='text', value=self._registration)
|
||||||
|
|
||||||
|
self.add_attribute('indicative-value', type='text', value=IndicativeValue)
|
||||||
|
|
||||||
|
self.add_attribute('date-first-registration', type='text', value=firstRegistration)
|
||||||
|
self.add_attribute('image-url', type='text', value=ImageUrl)
|
||||||
|
|
||||||
|
def _query(self):
|
||||||
|
payload = "RegistrationNumber={}&username={}".format(self._registration, self._username)
|
||||||
|
headers = {
|
||||||
|
'Content-Type': "application/x-www-form-urlencoded",
|
||||||
|
'cache-control': "no-cache",
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.request("POST", self.country_urls.get(self._country), data=payload, headers=headers)
|
||||||
|
# FIXME: Clean that up.
|
||||||
|
for item in response.text.split("</vehicleJson>"):
|
||||||
|
if "<vehicleJson>" in item:
|
||||||
|
responseJson = item[item.find("<vehicleJson>") + len("<vehicleJson>"):]
|
||||||
|
|
||||||
|
return json.loads(responseJson)
|
Loading…
Reference in New Issue