How to use threatexchange - 10 common examples

To help you get started, we’ve selected a few threatexchange examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crits / crits_services / threatexchange / __init__.py View on Github external
def get_config(existing_config):
        # Generate default config from form and initial values.
        config = {}
        fields = forms.ThreatExchangeConfigForm().fields
        for name, field in fields.iteritems():
            config[name] = field.initial

        # If there is a config in the database, use values from that.
        if existing_config:
            for key, value in existing_config.iteritems():
                config[key] = value
        return config
github crits / crits_services / threatexchange / forms.py View on Github external
def __init__(self, *args, **kwargs):
        kwargs.setdefault('label_suffix', ':')
        super(ThreatExchangeConfigForm, self).__init__(*args, **kwargs)
github crits / crits_services / threatexchange / __init__.py View on Github external
def generate_config_form(self, config):
        html = render_to_string('services_config_form.html',
                                {'name': self.name,
                                 'form': forms.ThreatExchangeConfigForm(
                                     initial=config),
                                 'config_error': None})
        form = forms.ThreatExchangeConfigForm
        return form, html
github crits / crits_services / threatexchange / __init__.py View on Github external
def get_config_details(config):
        display_config = {}

        # Rename keys so they render nice.
        fields = forms.ThreatExchangeConfigForm().fields
        for name, field in fields.iteritems():
            display_config[field.label] = config[name]

        return display_config
github crits / crits_services / threatexchange / __init__.py View on Github external
def generate_config_form(self, config):
        html = render_to_string('services_config_form.html',
                                {'name': self.name,
                                 'form': forms.ThreatExchangeConfigForm(
                                     initial=config),
                                 'config_error': None})
        form = forms.ThreatExchangeConfigForm
        return form, html
github crits / crits_services / threatexchange / views.py View on Github external
def get_privacy_group_form(request):
    if request.method == "POST" and request.is_ajax():
        initial = request.POST.copy()
        form = forms.ThreatExchangePrivacyGroupForm(initial=initial)
        template = render_to_string("privacy_form.html",
                                    {'privacy_group_form': form})
        result = {'success': True,
                'html': template}
        return HttpResponse(json.dumps(result),
                            content_type="application/json")
    else:
        return render_to_response('error.html',
                                  {'error': "Must be AJAX."},
                                  RequestContext(request))
github crits / crits_services / threatexchange / forms.py View on Github external
def __init__(self, *args, **kwargs):
        kwargs.setdefault('label_suffix', ':')
        super(ThreatExchangePrivacyGroupForm, self).__init__(*args, **kwargs)
github crits / crits_services / threatexchange / views.py View on Github external
url = params.get('url', None)
        type_ = params.get('type', None)
        indicator_type = params.get('indicator_type', None)

        if type_:
            del params['type']
        if indicator_type is not None:

            # can probably do better validation here against the attribute
            # of the pytx "Types" enum.
            if indicator_type.strip() != "":
                params['type_'] = params.get('indicator_type')

            del params['indicator_type']

        results = handlers.submit_query(request, url, type_, params=params)
        return HttpResponse(json.dumps(results),
                            content_type="application/json")
    else:
        return render_to_response('error.html',
                                  {'error': "Must be AJAX."},
                                  RequestContext(request))
github crits / crits_services / threatexchange / views.py View on Github external
id_ = request.POST.get('id', None)
        related_type = request.POST.get('related_type', None)
        td = {
            'descriptors': "Threat Descriptors",
            'dropped': "Malware Analyses",
            'dropped_by': "Malware Analyses",
            'families': "Malware Families",
            'related': "Threat Indicators",
            'similar_malware': "Malware Analyses",
            'threat_indicators': "Threat Indicators",
            'variants': "Malware Analyses"
        }
        type_ = td.get(related_type, None)
        if id_ and related_type and type_:
            url = tx.URL + tx.VERSION + id_ + '/' + related_type + '/'
            results = handlers.submit_query(request, url, type_)
            return HttpResponse(json.dumps(results),
                                content_type="application/json")
        else:
            return HttpResponse({'success': False,
                                 'message': "Need ID and valid related type."},
                                content_type="application/json")
    else:
        return render_to_response('error.html',
                                  {'error': "Must be AJAX."},
                                  RequestContext(request))
github crits / crits_services / threatexchange / views.py View on Github external
def add_edit_privacy_group(request):
    if request.method == "POST" and request.is_ajax():
        id_ = request.POST.get('id', None)
        name = request.POST.get('name', None)
        description = request.POST.get('description', None)
        members = request.POST.get('members', None)
        members_can_see = request.POST.get('members_can_see', False)
        if members_can_see == "false":
            members_can_see = False
        members_can_use = request.POST.get('members_can_use', False)
        if members_can_use == "false":
            members_can_use = False
        results = handlers.add_edit_privacy_group(id_=id_,
                                                  name=name,
                                                  description=description,
                                                  members=members,
                                                  members_can_see=members_can_see,
                                                  members_can_use=members_can_use)
        return HttpResponse(json.dumps(results),
                            content_type="application/json")
    else:
        return render_to_response('error.html',
                                  {'error': "Must be AJAX."},
                                  RequestContext(request))