libtaxii is a Python library that provides:
Use pip:
$ pip install libtaxii
You might also want to consider using a virtualenv.
The libtaxii library is developed on Python 2.7 and tested against both Python 2.6 and 2.7. Besides the Python Standard Library, libtaxii relies on the following Python libraries:
Each of these can be installed with pip or by manually downloading packages from PyPI. On Windows, you will probably have the most luck using pre-compiled binaries for lxml. On Ubuntu (12.04 or 14.04), you should make sure the following packages are installed before attempting to compile lxml from source:
Note
In libtaxii 1.0.101 and earlier, the M2Crypto library was also required. This dependency was removed as of libtaxii 1.0.102.
Warning
Users have encountered errors with versions of libxml2 (a dependency of lxml) prior to version 2.9.1. The default version of libxml2 provided on Ubuntu 12.04 is currently 2.7.8. Users are encouraged to upgrade libxml2 manually if they have any issues. Ubuntu 14.04 provides libxml2 version 2.9.1.
If you are unable to use pip, you can also install libtaxii with setuptools. If you don’t already have setuptools installed, please install it before continuing.
$ tar -zxf libtaxii-1.1.106.tar.gz $ ls libtaxii-1.1.106 libtaxii-1.1.106.tar.gz
OR
$ unzip libtaxii-1.1.106.zip $ ls libtaxii-1.1.106 libtaxii-1.1.106.zip
$ cd libtaxii-1.1.106 $ python setup.py install
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libtaxii
>>>
If you don’t see an ImportError, the installation was successful.
If you’re new to installing Python packages, you can learn more at the Python Packaging User Guide, specifically the Installing Python Packages section.
This page gives an introduction to libtaxii and how to use it. Please note that this page is being actively worked on and feedback is welcome.
The libtaxii library contains the following modules:
In the TAXII message modules (libtaxii.messages_10 and libtaxii.messages_11), there is a class corresponding to each type of TAXII message. For example, there is a DiscoveryRequest class for the Discovery Request message:
import libtaxii.messages_11 as tm11
discovery_request = tm11.DiscoveryRequest( ... )
For types that can been used across multiple messages (e.g., a Content Block can exist in both Poll Response and Inbox Message), the corresponding class (ContentBlock) is (and always has always been) defined at the module level.
content_block = tm11.ContentBlock( ... )
Other types that are used exclusively within a particular TAXII message type were previously defined as nested classes on the corresponding message class; however, they are now defined at the top level of the module. For example, a Service Instance is only used in a Discovery Response message, so the class representing a Service Instance, now just ServiceInstance, was previously DiscoveryResponse.ServiceInstance. The latter name still works for backward compatibilty reasons, but is deprecated and may be removed in the future.
service_instance = tm11.ServiceInstance( ... )
service_instance = tm11.DiscoveryRequest.ServiceInstance( ... )
See the API Documentation for proper constructor arguments for each type above.
Each class in the message modules has serialization and deserialization methods for XML Strings, Python dictionaries, and LXML ElementTrees. All serialization methods (to_*()) are instance methods called on specific objects (e.g., discovery_request.to_xml()). Deserialization methods (from_*()) are class methods and should be called on the class itself (e.g., tm11.DiscoveryRequest.from_xml(xml_string)).
Each class in messages.py defines the following:
To create a TAXII Message from XML:
xml_string = '<taxii:Discovery_Response ... />' # Note: Invalid XML
discovery_response = tm11.DiscoveryResponse.from_xml(xml_string)
To create an XML string from a TAXII Message:
new_xml_string = discovery_response.to_xml()
The same approach can be used for Python dictionaries:
msg_dict = { ... } # Note: Invalid dictionary syntax
discovery_response = tm11.DiscoveryResponse.from_dict(msg_dict)
new_dict = discovery_response.to_dict()
and for LXML ElementTrees:
msg_etree = etree.Element( ... ) # Note: Invalid Element constructor
discovery_response = tm11.DiscoveryResponse.from_etree(msg_etree)
new_etree = discovery_response.to_etree()
You can use libtaxii to Schema Validate XML, etree, and file representations of TAXII Messages. XML Schema validation cannot be performed on a TAXII Message Python object, since XML Schema validation can only be performed on XML.
A full code example of XML Schema validation can be found in API Documentation
The libtaxii.clients module defines a single class HttpClient capable of invoking TAXII services over both HTTP and HTTPS. The client is a fairly straighforward wrapper around Python’s builtin httplib and supports the use of of both HTTP Basic and TLS Certificate authentication.
Example usage of clients:
import libtaxii as t
import libtaxii.clients as tc
import libtaxii.messages_11 as tm11
client = tc.HttpClient()
client.set_auth_type(tc.HttpClient.AUTH_BASIC)
client.set_use_https(True)
client.set_auth_credentials({'username': 'MyUsername', 'password': 'MyPassword'})
discovery_request = tm11.DiscoveryRequest(tm11.generate_message_id())
discovery_xml = discovery_request.to_xml()
http_resp = client.call_taxii_service2('example.com', '/pollservice/', t.VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml()
This page provides documentation on the scripts that are included with libtaxii. All clients are configured to use the TAXII Test Server (http://taxiitest.mitre.org) by default; provide command line options for specifying most aspects of the script (e.g., host, port, client certs, username/password, HTTP or HTTPS, etc); and support TAXII 1.1 unless otherwise noted.
Note that the scripts should be callable from anywhere on the command line as long as you have the python scripts directory on your path.
All scripts use these command line arguments:
Note: As of libtaxii 1.1.106, the following arguments are now deprecated in favor of --url
For example, to call the discovery_client using all these arguments, you would do: discovery_client --url http://taxiitest.mitre.org/services/discovery/ --cert MyCert.crt --key MyKey.key --username foo --pass bar --proxy http://myproxy.example.com:80 --xml-output
The Discovery Client does not use any additional command line arguments.
In addition to the command line arguments listed above, the Poll Fulfillment Client uses these:
Example: fulfillment_client --collection MyCollection --result_id someId --result_part_number 1
In addition to the command line arguments listed above, the Inbox Client uses these:
Example: inbox_client --content-binding urn:stix.mitre.org:xml:1.1 --content-file stix_file.xml
In addition to the command line arguments listed above, the Poll Client uses these:
Example: poll_client --collection MyCollection
In addition to the command line arguments listed above, the Poll Client 1.0 uses these:
Example: poll_client_10 --feed MyFeedName --subscription-id SomeSubscriptionId
In addition to the command line arguments listed above, the Query Client uses these:
Example: query_client --collection MyQueryCollection --ip 10.0.0.0
In terms of code organization, there are a few big changes beginning to take place in this version of libtaxii. Constants and commonly used classes/functions are being moved to common locations (libtaxii.constants and libtaxii.common, respectively). Also, nested classes (e.g., messages_11.DiscoveryResponse.ServiceInstance) have been de-nested (e.g., is now messages_11.ServiceInstance). All of these changes are intended to make using libtaxii easier. For the time being, backward compatibility has been maintained, but many of these changes may result in a backward compatibility breaking change in a future, major release of libtaxii.
Major changes:
Minor changes:
Bug fixes:
The biggest change was the addition of scripts to libtaxii. Now when you install libtaxii, you get a number of scripts that are by default configured to hit the TAXII Test server (taxiitest.mitre.org). You can specify a number of parameters on the command line to change where/how the scripts connect. The scripts are:
We also had a number of bug fixes and impprovements for this version of libtaxii:
Lots of changes in this release, including some important bug fixes.
This version contains known bugs. Use a more recent version of libtaxii when possible.
This version fixes a schema validation bug. Schema validation did not work prior to this version.
This version adds better proxy support to libtaxii in libtaxii.clients. A function to set a proxy (setProxy) was added as well as a new callTaxiiService2 function that can properly use proxies. The original callTaxiiService function did not support proxies well. The APIs have the full documentation for callTaxiiService, callTaxiiService2, and setProxy (Client API).
This version added missing source files for distribution on PyPI. No functionality changes were made.
Version 1.0.100 represents the first TAXII 1.0 compliant version of libtaxii. This version removes all code not compliant with TAXII 1.0.
This version of libtaxii has components that are TAXII 1.0 conformant and experimental functionality that conforms to a draft version of TAXII. This version should only be used to transition from 1.0.000draft to 1.0.100.
This version of libtaxii represents experimental functionality that conforms to a draft version of TAXII. This code should no longer be used. For those using this code, you should upgrade to 1.0.090 and migrate your code to use the TAXII 1.0 components, then transition to 1.0.100.
Create a TAXII message from an HTTPResponse object.
This function parses the httplib.HTTPResponse by reading the X-TAXII-Content-Type HTTP header to determine if the message binding is supported. If the X-TAXII-Content-Type header is present and the value indicates a supported Message Binding, this function will attempt to parse the HTTP Response body.
If the X-TAXII-Content-Type header is not present, this function will attempt to build a Failure Status Message per the HTTP Binding 1.0 specification.
If the X-TAXII-Content-Type header is present and indicates an unsupported Message Binding, this function will raise a ValueError.
Parameters: |
|
---|
Common utility classes and functions used throughout libtaxii.
Return the XML parser currently in use.
If one has not already been set (via set_xml_parser()), a new etree.XMLParser is constructed with no_network=True and huge_tree=True.
Set the libtaxii.messages XML parser.
Parameters: | xml_parser (etree.XMLParser) – The parser to use to parse TAXII XML. |
---|
Base class for all TAXII Messages and Message component types.
libtaxii users should not need to use this class directly.
Generic method used to check equality of objects of any TAXII type.
Also allows for print-based debugging output showing differences.
In order for subclasses to use this function, they must meet the following criteria: 1. All class properties start with one underscore. 2. The sort_key property is implemented.
Parameters: |
|
---|
Create an instance of this class from a dictionary.
Subclasses must implement this method.
Create an instance of this class from an etree.
Subclasses must implement this method.
Create an instance of this class from XML.
Subclasses should not need to implement this method.
This property allows list of TAXII objects to be compared efficiently. The __eq__ method uses this property to sort the lists before comparisons are made.
Subclasses must implement this property.
Create a dictionary representation of this class.
Subclasses must implement this method.
Create an etree representation of this class.
Subclasses must implement this method.
Create a nice looking (this is a subjective term!) textual representation of this class. Subclasses should implement this method.
Note that this is just a convenience method for making TAXII Messages nice to read for humans and may change drastically in future versions of libtaxii.
Create an XML representation of this class.
Subclasses should not need to implement this method.
The following constants can be used as TAXII Version IDs
Version ID for the TAXII Services Specification 1.0
Version ID for the TAXII Services Specification 1.1
Version ID for the TAXII XML Message Binding Specification 1.0
Version ID for the TAXII XML Message Binding Specification 1.1
Version ID for the TAXII HTTP Protocol Binding Specification 1.0
Version ID for the TAXII HTTPS Protocol Binding Specification 1.0
The following are third-party Version IDs included in libtaxii for convenience.
Version ID for the CERT EU JSON Message Binding
The following constants should be used as the Content Binding ID for STIX XML.
Content Binding ID for STIX XML 1.0
Content Binding ID for STIX XML 1.0.1
Content Binding ID for STIX XML 1.1
Content Binding ID for STIX XML 1.1.1
These other Content Binding IDs are included for convenience as well.
Content Binding ID for CAP 1.1
Content Binding ID for XML Encryption
Content Binding ID for SMIME
This constant contains commonly namespaces and aliases in TAXII.
Namespace map of namespaces libtaxii knows about
Constant identifying a Status Message
Constant identifying a Discovery Request Message
Constant identifying a Discovery Response Message
Constant identifying a Feed Information Request Message
Constant identifying a Feed Information Response Message
Constant identifying a Subscription Management Request Message
Constant identifying a Subscription Management Response Message
Constant identifying a Poll Request Message
Constant identifying a Poll Response Message
Constant identifying a Inbox Message
TAXII 1.0 Message Types
Constant identifying a Status Message
Constant identifying a Collection Information Request
Constant identifying a Collection Information Response
Constant identifying a Subscription Request
Constant identifying a Subscription Response
Tuple of all TAXII 1.1 Message Types
These constants are used in StatusMessage.
Constant identifying a Status Type of Bad Message
Constant identifying a Status Type of Denied
Constant identifying a Status Type of Failure
Constant identifying a Status Type of Not Found
Constant identifying a Status Type of Polling Unsupported
Constant identifying a Status Type of Retry
Constant identifying a Status Type of Success
Constant identifying a Status Type of Unauthorized
Constant identifying a Status Type of Unsupported Message Binding
Constant identifying a Status Type of Unsupported Content Binding
Constant identifying a Status Type of Unsupported Protocol Binding
Tuple of all TAXII 1.0 Status Types
Constant identifying a Status Type of Asynchronous Poll Error
Constant identifying a Status Type of Destination Collection Error
Constant identifying a Status Type of Invalid Response Part
Constant identifying a Status Type of Network Error
Constant identifying a Status Type of Pending
Constant identifying a Status Type of Unsupported Query Format
Tuple of all TAXII 1.1 Status types
These constants are used in ManageFeedSubscriptionRequest
Constant identifying an Action of Subscribe
Constant identifying an Action of Unsubscribe
Constant identifying an Action of Status
Tuple of all TAXII 1.0 Action Types
Constant identifying an Action of Pause
Constant identifying an Action of Resume
Tuple of all TAXII 1.1 Action types
These constants are used to indicate the type of service.
Constant identifying a Service Type of Inbox
Constant identifying a Service Type of Poll
Constant identifying a Service Type of Feed Management
Constant identifying a Service Type of Discovery
Tuple of all TAXII 1.0 Service Types
Constant identifying a Service Type of Collection Management. “Feed Management” was renamed to “Collection Management” in TAXII 1.1.
Tuple of all TAXII 1.1 Service Types
These constants are used in ManageCollectionSubscriptionResponse
Subscription Status of Active
Subscription Status of Paused
Subscription Status of Unsubscribed
Tuple of all TAXII 1.1 Subscription Statues
These constants are used to indicate the type of response returned.
Constant identifying a response type of Full
Constant identifying a response type of Count only
Tuple of all TAXII 1.1 Response Types
These constants are used to indicate the type of collection.
Constant identifying a collection type of Data Feed
Constant identifying a collection type of Data Set
Tuple of all TAXII 1.1 Collection Types
These constants are used in StatusMessage.
Constant Identifying the Acceptable Destination Status Detail
Constant Identifying the Max Part Number Status Detail
Constant Identifying the Item Status Detail
Constant Identifying the Estimated Wait Status Detail
Constant Identifying the Result ID Status Detail
Constant Identifying the Will Push Status Detail
Constant Identifying the Supported Binding Status Detail
Constant Identifying the Supported Content Status Detail
Constant Identifying the Supported Protocol Status Detail
Constant Identifying the Supported Query Status Detail
Tuple of all TAXII 1.1 Status Detail Keys
(For TAXII Default Query) Constant identifying supported Capability Modules
(For TAXII Default Query) Constant identifying Preferred Scopes
(For TAXII Default Query) Constant identifying Allowed Scopes
(For TAXII Default Query) Constant identifying supported Targeting Expression IDs
These constants are used to indicate query format.
..autodata:: FID_TAXII_DEFAULT_QUERY_10
These constants are used to indicate TAXII Default Query Capability Modules
Capability Module ID for Core
Capability Module ID for Regex
Capability Module ID for Timestamp
Tuple of all capability modules defined in TAXII Default Query 1.0
These constants are used to identify the operator in :py:class`Criteria`
Operator OR
Operator AND
Tuple of all operators
TAXII Default Query 1.0 identifies three additional Status Types:
Status Type indicating an unsupported capability module
Status Type indicating an unsupported targeting expression
Status Type indicating an unsupported targeting expression id
These constants are used to identify parameters.
Parameter name: value
Parameter name: match_type
Parameter name: case_sensitive
Tuple of all parameter names
These constants are used to identify relationships
Relationship name: equals
Relationship name: not_requals
Relationship name: greater_than
Relationship name: greater_than_or_equal
Relationship name: less_than
Relationship name: less_than_or_equal
Relationship name: does_not_exist
Relationship name: exists
Relationship name: begins_with
Relationship name: ends_with
Relationship name: contains
Relationship name: matches
Tuple of all relationship names
Call a TAXII service.
Note: this uses urllib2 instead of httplib, and therefore returns a different kind of object than call_taxii_service().
Returns: | urllib2.Response |
---|
Set the authentication credentials used later when making a request.
Note that it is possible to pass in one dict containing credentials for different authentication types and swap between them later.
Parameters: | dict (auth_credentials_dict) – The dictionary containing authentication credentials. e.g.: - {‘key_file’: ‘/path/to/key.key’, ‘cert_file’: ‘/path/to/cert.crt’} - {‘username’: ‘abc’, ‘password’: ‘xyz’} - Or both, if both username/password and certificate based auth are used |
---|
Set the authentication type for this client.
Parameters: | auth_type (string) – Must be one of AUTH_NONE, AUTH_BASIC, or AUTH_CERT |
---|
Set the proxy settings to use when making a connection.
Parameters: |
|
---|
TAXII clients have three types of authentication credentials: None, HTTP Basic, and TLS Certificate. This section demonstrates usage of all three auth types.
All examples assume the following imports:
import libtaxii as t import libtaxii.messages_11 as tm11 import libtaxii.clients as tc from libtaxii.common import generate_message_id from libtaxii.constants import * from dateutil.tz import tzutc
client = tc.HttpClient()
client.set_auth_type(tc.AUTH_NONE)
client.set_use_https(False)
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)
client = tc.HttpClient()
client.set_use_https(True)
client.set_auth_type(tc.HttpClient.AUTH_BASIC)
client.set_auth_credentials({'username': 'MyUsername', 'password': 'MyPassword'})
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)
client = tc.HttpClient()
client.set_use_https(True)
client.set_auth_type(tc.HttpClient.AUTH_CERT)
client.set_auth_credentials({'key_file': '../PATH_TO_KEY_FILE.key', 'cert_file': '../PATH_TO_CERT_FILE.crt'})
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)
Creating, handling, and parsing TAXII 1.0 messages.
Note
The examples on this page assume that you have run the equivalent of
import datetime
from dateutil.tz import tzutc
import libtaxii as t
import libtaxii.messages_10 as tm10
A TAXII Status message.
Parameters: |
|
---|
Example:
status_message1 = tm10.StatusMessage(
message_id=tm10.generate_message_id(),
in_response_to="12345",
status_type=tm10.ST_SUCCESS,
status_detail='Machine-processable info here!',
message='This is a message.')
A TAXII Discovery Request message.
Parameters: |
|
---|
Example:
ext_headers = {'name1': 'val1', 'name2': 'val2'}
discovery_request = tm10.DiscoveryRequest(
message_id=tm10.generate_message_id(),
extended_headers=ext_headers)
A TAXII Discovery Response message.
Parameters: |
|
---|
The Service Instance component of a TAXII Discovery Response Message.
Parameters: |
|
---|
The message_bindings list must contain at least one value.
Example:
discovery_response = tm10.DiscoveryResponse(
message_id=tm10.generate_message_id(),
in_response_to=discovery_request.message_id)
service_instance = tm10.ServiceInstance(
service_type=tm10.SVC_INBOX,
services_version=t.VID_TAXII_SERVICES_10,
protocol_binding=t.VID_TAXII_HTTPS_10,
service_address='https://example.com/inbox/',
message_bindings=[t.VID_TAXII_XML_10],
inbox_service_accepted_content=[t.CB_STIX_XML_10],
available=True,
message='This is a sample inbox service instance')
discovery_response.service_instances.append(service_instance)
# Alternatively, you could define the service instance(s) first and use the
# following:
service_instance_list = [service_instance]
discovery_response = tm10.DiscoveryResponse(
message_id=tm10.generate_message_id(),
in_response_to=discovery_request.message_id,
service_instances=service_instance_list)
A TAXII Feed Information Request message.
Parameters: |
|
---|
Example:
ext_headers = {'name1': 'val1', 'name2': 'val2'}
feed_information_request= tm10.FeedInformationRequest(
message_id=tm10.generate_message_id(),
extended_headers=ext_headers)
A TAXII Feed Information Response message.
Parameters: |
|
---|
The Feed Information component of a TAXII Feed Information Response Message.
Parameters: |
|
---|
The absense of push_methods indicates no push methods. The absense of polling_service_instances indicates no polling services. At least one of push_methods and polling_service_instances must not be empty. The absense of subscription_methods indicates no subscription services.
The Push Method component of a TAXII Feed Information component.
Parameters: |
|
---|
The Polling Service Instance component of a TAXII Feed Information component.
Parameters: |
|
---|
The Subscription Method component of a TAXII Feed Information component.
Parameters: |
|
---|
Example:
push_method1 = tm10.PushMethod(
push_protocol=t.VID_TAXII_HTTP_10,
push_message_bindings=[t.VID_TAXII_XML_10])
polling_service1 = tm10.PollingServiceInstance(
poll_protocol=t.VID_TAXII_HTTP_10,
poll_address='http://example.com/PollService/',
poll_message_bindings=[t.VID_TAXII_XML_10])
subscription_service1 = tm10.SubscriptionMethod(
subscription_protocol=t.VID_TAXII_HTTP_10,
subscription_address='http://example.com/SubsService/',
subscription_message_bindings=[t.VID_TAXII_XML_10])
feed1 = tm10.FeedInformation(
feed_name='Feed1',
feed_description='Description of a feed',
supported_contents=[t.CB_STIX_XML_10],
available=True,
push_methods=[push_method1],
polling_service_instances=[polling_service1],
subscription_methods=[subscription_service1])
feed_information_response1 = tm10.FeedInformationResponse(
message_id=tm10.generate_message_id(),
in_response_to=tm10.generate_message_id(),
feed_informations=[feed1])
A TAXII Manage Feed Subscription Request message.
Parameters: |
|
---|
Example:
delivery_parameters1 = tm10.DeliveryParameters(
inbox_protocol=t.VID_TAXII_HTTP_10,
inbox_address='http://example.com/inbox',
delivery_message_binding=t.VID_TAXII_XML_10,
content_bindings=[t.CB_STIX_XML_10])
manage_feed_subscription_request1 = tm10.ManageFeedSubscriptionRequest(
message_id=tm10.generate_message_id(),
feed_name='SomeFeedName',
action=tm10.ACT_UNSUBSCRIBE,
subscription_id='SubsId056',
delivery_parameters=delivery_parameters1)
A TAXII Manage Feed Subscription Response message.
Parameters: |
|
---|
The Subscription Instance component of the Manage Feed Subscription Response message.
Parameters: |
|
---|
The Poll Instance component of the Manage Feed Subscription Response message.
Parameters: |
|
---|
Example:
poll_instance1 = tm10.PollInstance(
poll_protocol=t.VID_TAXII_HTTP_10,
poll_address='http://example.com/poll',
poll_message_bindings=[t.VID_TAXII_XML_10])
subscription_instance1 = tm10.SubscriptionInstance(
subscription_id='SubsId234',
delivery_parameters=[delivery_parameters1],
poll_instances=[poll_instance1])
manage_feed_subscription_response1 = tm10.ManageFeedSubscriptionResponse(
message_id=tm10.generate_message_id(),
in_response_to="12345",
feed_name='Feed001',
message='This is a message',
subscription_instances=[subscription_instance1])
A TAXII Poll Request message.
Parameters: |
|
---|
Example:
poll_request1 = tm10.PollRequest(
message_id=tm10.generate_message_id(),
feed_name='TheFeedToPoll',
exclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()),
subscription_id='SubsId002',
content_bindings=[t.CB_STIX_XML_10])
A TAXII Poll Response message.
Parameters: |
|
---|
Example:
poll_response1 = tm10.PollResponse(
message_id=tm10.generate_message_id(),
in_response_to="12345",
feed_name='FeedName',
inclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()),
subscription_id='SubsId001',
message='This is a message.',
content_blocks=[])
A TAXII Inbox message.
Parameters: |
|
---|
The Subscription Information component of a TAXII Inbox message.
Parameters: |
|
---|
Example:
cb1 = tm10.ContentBlock(t.CB_STIX_XML_11, "")
subscription_information1 = tm10.SubscriptionInformation(
feed_name='SomeFeedName',
subscription_id='SubsId021',
inclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()))
inbox_message1 = tm10.InboxMessage(
message_id=tm10.generate_message_id(),
message='This is a message.',
subscription_information=subscription_information1,
content_blocks=[cb1])
Encapsulate properties common to all TAXII Messages (such as headers).
This class is extended by each Message Type (e.g., DiscoveryRequest), with each subclass containing subclass-specific information
A TAXII Content Block.
Parameters: |
|
---|
Example:
cb1 = tm10.ContentBlock(
content_binding=t.CB_STIX_XML_10,
content='<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>')
Delivery Parameters.
Parameters: |
|
---|
Generate a TAXII Message ID.
Parameters: | maxlen (int) – maximum length of the ID, in characters |
---|
Example
msg_id = tm11.generate_message_id()
message = tm11.DiscoveryRequest(msg_id)
# Or...
message = tm11.DiscoveryRequest(tm11.generate_message_id())
Note that this function has been deprecated. Please see libtaxii.validators.SchemaValidator.
Validate XML with the TAXII XML Schema 1.0.
Parameters: | xml_string (str) – The XML to validate. |
---|
Example
is_valid = tm10.validate_xml(message.to_xml())
Create a TAXIIMessage object from an XML string.
This function automatically detects which type of Message should be created based on the XML.
Parameters: | xml_string (str) – The XML to parse into a TAXII message. |
---|
Example
message_xml = message.to_xml()
new_message = tm10.get_message_from_xml(message_xml)
Create a TAXIIMessage object from a dictonary.
This function automatically detects which type of Message should be created based on the ‘message_type’ key in the dictionary.
Parameters: | d (dict) – The dictionary to build the TAXII message from. |
---|
Example
message_dict = message.to_dict()
new_message = tm10.get_message_from_dict(message_dict)
Create a TAXIIMessage object from a JSON string.
This function automatically detects which type of Message should be created based on the JSON.
Parameters: | json_string (str) – The JSON to parse into a TAXII message. |
---|
Creating, handling, and parsing TAXII 1.1 messages.
Note
The examples on this page assume that you have run the equivalent of
import datetime
from dateutil.tz import tzutc
import libtaxii as t
import libtaxii.messages_11 as tm11
A TAXII Status message.
Parameters: |
|
---|
Example:
sm03 = tm11.StatusMessage(
message_id='SM03',
in_response_to=tm11.generate_message_id(),
status_type=tm11.ST_DESTINATION_COLLECTION_ERROR,
status_detail={'ACCEPTABLE_DESTINATION': ['Collection1','Collection2']})
A TAXII Discovery Request message.
Parameters: |
|
---|
Example:
headers={'ext_header1': 'value1', 'ext_header2': 'value2'}
discovery_request = tm11.DiscoveryRequest(
message_id=tm11.generate_message_id(),
extended_headers=headers)
A TAXII Discovery Response message.
Parameters: |
|
---|
The Service Instance component of a TAXII Discovery Response Message.
Parameters: |
|
---|
The message_bindings list must contain at least one value. The supported_query parameter is optional when service_type is SVC_POLL.
Example:
discovery_response = tm11.DiscoveryResponse(
message_id=tm11.generate_message_id(),
in_response_to=discovery_request.message_id)
service_instance = tm11.ServiceInstance(
service_type=tm11.SVC_POLL,
services_version=t.VID_TAXII_SERVICES_11,
protocol_binding=t.VID_TAXII_HTTP_10,
service_address='http://example.com/poll/',
message_bindings=[t.VID_TAXII_XML_11],
available=True,
message='This is a message.',
#supported_query=[tdq1],
)
discovery_response.service_instances.append(service_instance)
# Alternatively, you could define the service instance(s) first and use the
# following:
service_instance_list = [service_instance]
discovery_response = tm11.DiscoveryResponse(
message_id=tm11.generate_message_id(),
in_response_to=discovery_request.message_id,
service_instances=service_instance_list)
A TAXII Collection Information Request message.
Parameters: |
|
---|
Example:
ext_headers = {'name1': 'val1', 'name2': 'val2'}
collection_information_request = tm11.CollectionInformationRequest(
message_id='CIReq01',
extended_headers=ext_headers)
A TAXII Collection Information Response message.
Parameters: |
|
---|
The Collection Information component of a TAXII Collection Information Response Message.
Parameters: |
|
---|
If supported_contents is omitted, then the collection supports all content bindings. The absense of push_methods indicates no push methods. The absense of polling_service_instances indicates no polling services. The absense of subscription_methods indicates no subscription services. The absense of receiving_inbox_services indicates no receiving inbox services.
The Push Method component of a TAXII Collection Information component.
Parameters: |
|
---|
The Polling Service Instance component of a TAXII Collection Information component.
Parameters: |
|
---|
The Subscription Method component of a TAXII Collection Information component.
Parameters: |
|
---|
The Receiving Inbox Service component of a TAXII Collection Information component.
Parameters: |
|
---|
Example:
push_method1 = tm11.PushMethod(
push_protocol=t.VID_TAXII_HTTP_10,
push_message_bindings=[t.VID_TAXII_XML_11])
poll_service1 = tm11.PollingServiceInstance(
poll_protocol=t.VID_TAXII_HTTPS_10,
poll_address='https://example.com/PollService1',
poll_message_bindings=[t.VID_TAXII_XML_11])
poll_service2 = tm11.PollingServiceInstance(
poll_protocol=t.VID_TAXII_HTTPS_10,
poll_address='https://example.com/PollService2',
poll_message_bindings=[t.VID_TAXII_XML_11])
subs_method1 = tm11.SubscriptionMethod(
subscription_protocol=t.VID_TAXII_HTTPS_10,
subscription_address='https://example.com/SubscriptionService',
subscription_message_bindings=[t.VID_TAXII_XML_11])
inbox_service1 = tm11.ReceivingInboxService(
inbox_protocol=t.VID_TAXII_HTTPS_10,
inbox_address='https://example.com/InboxService',
inbox_message_bindings=[t.VID_TAXII_XML_11],
supported_contents=None)
collection1 = tm11.CollectionInformation(
collection_name='collection1',
collection_description='This is a collection',
supported_contents=[tm11.ContentBinding(t.CB_STIX_XML_101)],
available=False,
push_methods=[push_method1],
polling_service_instances=[poll_service1, poll_service2],
subscription_methods=[subs_method1],
collection_volume=4,
collection_type=tm11.CT_DATA_FEED,
receiving_inbox_services=[inbox_service1])
collection_response1 = tm11.CollectionInformationResponse(
message_id='CIR01',
in_response_to='0',
collection_informations=[collection1])
A TAXII Manage Collection Subscription Request message.
Parameters: |
|
---|
Example:
subscription_parameters1 = tm11.SubscriptionParameters()
push_parameters1 = tm11.PushParameters("", "", "")
subs_req1 = tm11.ManageCollectionSubscriptionRequest(
message_id='SubsReq01',
action=tm11.ACT_SUBSCRIBE,
collection_name='collection1',
subscription_parameters=subscription_parameters1,
push_parameters=push_parameters1)
A TAXII Manage Collection Subscription Response message.
Parameters: |
|
---|
The Subscription Instance component of the Manage Collection Subscription Response message.
Parameters: |
|
---|
The Poll Instance component of the Manage Collection Subscription Response message.
Parameters: |
|
---|
Example:
subscription_parameters1 = tm11.SubscriptionParameters()
push_parameters1 = tm11.PushParameters("", "", "")
poll_instance1 = tm11.PollInstance(
poll_protocol=t.VID_TAXII_HTTPS_10,
poll_address='https://example.com/poll1/',
poll_message_bindings=[t.VID_TAXII_XML_11])
subs1 = tm11.SubscriptionInstance(
subscription_id='Subs001',
status=tm11.SS_ACTIVE,
subscription_parameters=subscription_parameters1,
push_parameters=push_parameters1,
poll_instances=[poll_instance1])
subs_resp1 = tm11.ManageCollectionSubscriptionResponse(
message_id='SubsResp01',
in_response_to='xyz',
collection_name='abc123',
message='Hullo!',
subscription_instances=[subs1])
A TAXII Poll Request message.
Parameters: |
|
---|
Exactly one of subscription_id and poll_parameters is Required.
The Poll Parameters component of a TAXII Poll Request message.
Parameters: |
|
---|
If content_bindings in not provided, this indicates that all bindings are accepted as a response.
Example:
delivery_parameters1 = tm11.DeliveryParameters(
inbox_protocol=t.VID_TAXII_HTTPS_10,
inbox_address='https://example.com/inboxAddress/',
delivery_message_binding=t.VID_TAXII_XML_11)
poll_params1 = tm11.PollParameters(
allow_asynch=False,
response_type=tm11.RT_COUNT_ONLY,
content_bindings=[tm11.ContentBinding(binding_id=t.CB_STIX_XML_11)],
#query=query1,
delivery_parameters=delivery_parameters1)
poll_req3 = tm11.PollRequest(
message_id='PollReq03',
collection_name='collection100',
exclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()),
poll_parameters=poll_params1)
A TAXII Poll Response message.
Parameters: |
|
---|
Example:
cb1 = tm11.ContentBlock(t.CB_STIX_XML_11, "")
cb2 = tm11.ContentBlock(t.CB_STIX_XML_11, "")
count = tm11.RecordCount(record_count=22, partial_count=False)
poll_resp1 = tm11.PollResponse(
message_id='PollResp1',
in_response_to='tmp',
collection_name='blah',
exclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()),
subscription_id='24',
message='This is a test message',
content_blocks=[cb1, cb2],
more=True,
result_id='123',
result_part_number=1,
record_count=count)
A TAXII Inbox message.
Parameters: |
|
---|
The Subscription Information component of a TAXII Inbox message.
Parameters: |
|
---|
Example:
cb1 = tm11.ContentBlock(t.CB_STIX_XML_11, "")
cb2 = tm11.ContentBlock(t.CB_STIX_XML_11, "")
subs_info1 = tm11.SubscriptionInformation(
collection_name='SomeCollectionName',
subscription_id='SubsId021',
exclusive_begin_timestamp_label=datetime.datetime.now(tzutc()),
inclusive_end_timestamp_label=datetime.datetime.now(tzutc()))
inbox1 = tm11.InboxMessage(
message_id='Inbox1',
result_id='123',
destination_collection_names=['collection1','collection2'],
message='Hello!',
subscription_information=subs_info1,
record_count=tm11.RecordCount(22, partial_count=True),
content_blocks=[cb1, cb2])
A TAXII Poll Fulfillment Request message.
Parameters: |
|
---|
Example:
pf1 = tm11.PollFulfillmentRequest(
message_id='pf1',
collection_name='1-800-collection',
result_id='123',
result_part_number=1)
Encapsulate properties common to all TAXII Messages (such as headers).
This class is extended by each Message Type (e.g., DiscoveryRequest), with each subclass containing subclass-specific information
TAXII Content Binding component
Parameters: |
|
---|
A TAXII Content Block.
Parameters: |
|
---|
Example:
cb001 = tm11.ContentBlock(
content_binding=tm11.ContentBinding(t.CB_STIX_XML_11),
content='<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>',
timestamp_label=datetime.datetime.now(tzutc()),
message='Hullo!',
padding='The quick brown fox jumped over the lazy dogs.')
Set up Delivery Parameters.
Parameters: |
|
---|
Set up Push Parameters.
Parameters: |
|
---|
Information summarizing the number of records.
Parameters: |
|
---|
TAXII Subscription Parameters.
Parameters: |
|
---|
Generate a TAXII Message ID.
Parameters: | maxlen (int) – maximum length of the ID, in characters |
---|
Example
msg_id = tm11.generate_message_id()
message = tm11.DiscoveryRequest(msg_id)
# Or...
message = tm11.DiscoveryRequest(tm11.generate_message_id())
Note that this function has been deprecated. Please see libtaxii.validators.SchemaValidator.
Validate XML with the TAXII XML Schema 1.1.
Parameters: | xml_string (str) – The XML to validate. |
---|
Example
is_valid = tm11.validate_xml(message.to_xml())
Create a TAXIIMessage object from an XML string.
This function automatically detects which type of Message should be created based on the XML.
Parameters: | xml_string (str) – The XML to parse into a TAXII message. |
---|
Example
message_xml = message.to_xml()
new_message = tm11.get_message_from_xml(message_xml)
Create a TAXIIMessage object from a dictonary.
This function automatically detects which type of Message should be created based on the ‘message_type’ key in the dictionary.
Parameters: | d (dict) – The dictionary to build the TAXII message from. |
---|
Example
message_dict = message.to_dict()
new_message = tm11.get_message_from_dict(message_dict)
Create a TAXIIMessage object from a JSON string.
This function automatically detects which type of Message should be created based on the JSON.
Parameters: | json_string (str) – The JSON to parse into a TAXII message. |
---|
Creating, handling, and parsing TAXII Default Queries.
Bases: libtaxii.messages_11.Query
Conveys a TAXII Default Query.
Parameters: |
|
---|
Bases: libtaxii.common.TAXIIBase
Represents criteria for a DefaultQuery. Note: At least one criterion OR criteria MUST be present
Parameters: |
|
---|
Bases: libtaxii.common.TAXIIBase
Represents criterion for a DefaultQuery.Criteria
Parameters: |
|
---|
Bases: libtaxii.common.TAXIIBase
Parameters: |
---|
Example
import libtaxii as t
import libtaxii.taxii_default_query as tdq
import datetime
from dateutil.tz import tzutc
test1 = tdq.DefaultQuery.Criterion.Test(capability_id=tdq.CM_CORE, #Required
relationship='equals', #Required
parameters={'value': 'Test value',
'match_type': 'case_sensitive_string'}#Each relationship defines which params are and are not required
)
test2 = tdq.DefaultQuery.Criterion.Test(capability_id=tdq.CM_REGEX, #Required
relationship='matches',#Required
parameters={'value': '[A-Z]*',
'case_sensitive': True})#Each relationship defines which params are and are not required
test3 = tdq.DefaultQuery.Criterion.Test(capability_id=tdq.CM_TIMESTAMP,#Required
relationship='greater_than',#Required
parameters={'value': datetime.datetime.now()})#Each relationship defines which params are and are not required
criterion1 = tdq.DefaultQuery.Criterion(target='**', test=test1)
criterion2 = tdq.DefaultQuery.Criterion(target='STIX_Package/Indicators/Indicator/@id', test=test2)
criterion3 = tdq.DefaultQuery.Criterion(target='**/Description', test=test3)
criteria1 = tdq.DefaultQuery.Criteria(operator=tdq.OP_AND, criterion=[criterion1])
criteria2 = tdq.DefaultQuery.Criteria(operator=tdq.OP_OR, criterion=[criterion1, criterion2, criterion3])
criteria3 = tdq.DefaultQuery.Criteria(operator=tdq.OP_AND, criterion=[criterion1, criterion3], criteria=[criteria2])
query1 = tdq.DefaultQuery(t.CB_STIX_XML_11, criteria1)
query2 = tdq.DefaultQuery(t.CB_STIX_XML_11, criteria3)
#query1 and query2 would be able to be used in TAXII requests that contain queries (e.g., PollRequest messages)
Bases: libtaxii.messages_11.SupportedQuery
Used to describe the TAXII Default Queries that are supported.
Parameters: |
|
---|
Bases: libtaxii.common.TAXIIBase
This class describes supported Targeting Expressions
Parameters: |
---|
Example
import libtaxii as t
import libtaxii.taxii_default_query as tdq
import datetime
from dateutil.tz import tzutc
tei_01 = tdq.DefaultQueryInfo.TargetingExpressionInfo(
targeting_expression_id = t.CB_STIX_XML_10, #Required. Indicates a supported targeting vocabulary (in this case STIX 1.1)
preferred_scope=[], #At least one of Preferred/Allowed must be present. Indicates Preferred and allowed search scope.
allowed_scope=['**'])#This example has no preferred scope, and allows any scope
tei_02 = tdq.DefaultQueryInfo.TargetingExpressionInfo(
targeting_expression_id = t.CB_STIX_XML_11, #required. Indicates a supported targeting vocabulary (in this case STIX 1.1)
preferred_scope=['STIX_Package/Indicators/Indicator/**'], #At least one of Preferred/Allowed must be present. Indicates Preferred and allowed search scope.
allowed_scope=[])#This example prefers the Indicator scope and allows no other scope
tdqi1 = tdq.DefaultQueryInfo(
targeting_expression_infos = [tei_01, tei_02], #Required, 1-n. Indicates what targeting expressions are supported
capability_modules = [tdq.CM_CORE])#Required, 1-n. Indicates which capability modules can be used.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
str(object=’‘) -> string
Return a nice string representation of the object. If the argument is a string, the return value is the same object.
A helper class for TAXII Schema Validation.
Example
See validate_etree(...) for an example how to use this class
Validate an LXML etree with the specified schema_file.
Parameters: |
|
---|---|
Returns: | A SchemaValidationResult object |
Raises: | lxml.etree.XMLSyntaxError – When the XML to be validated is not well formed |
Example
from libtaxii import messages_11
from libtaxii.validation import SchemaValidator, TAXII_11_SCHEMA
from lxml.etree import XMLSyntaxError
sv = SchemaValidator(TAXII_11_SCHEMA)
try:
result = sv.validate_etree(some_etree)
# Note that validate_string() and validate_file() can also be used
except XMLSyntaxError:
# Handle this exception, which occurs when
# some_xml_string is not valid XML (e.g., 'foo')
if not result.valid:
for error in result.error_log:
print error
sys.exit(1)
# At this point, the XML is schema valid
do_something(some_xml_string)
A wrapper for validate_etree. Parses file_location, turns it into an etree, then calls validate_etree( ... )
A wrapper for validate_etree. Parses xml_string, turns it into an etree, then calls validate_etree( ... )
Automatically-calculated path to the bundled TAXII 1.0 schema.
Automatically-calculated path to the bundled TAXII 1.1 schema.
Bases: libtaxii.validation.SchemaValidator
A SchemaValidator that uses the TAXII 1.0 Schemas
Bases: libtaxii.validation.SchemaValidator
A SchemaValidator that uses the TAXII 1.1 Schemas