_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q244100
TcExPlaybook.read
train
def read(self, key, array=False, embedded=True): """Read method of CRUD operation for working with KeyValue DB. This method will automatically check to see if a single variable is passed or if "mixed" data is passed and return the results from the DB. It will also automatically determin...
python
{ "resource": "" }
q244101
TcExPlaybook.read_data_types
train
def read_data_types(self): """Map of standard playbook variable types to read method.""" return { 'Binary': self.read_binary, 'BinaryArray': self.read_binary_array, 'KeyValue': self.read_key_value, 'KeyValueArray': self.read_key_value_array,
python
{ "resource": "" }
q244102
TcExPlaybook.read_embedded
train
def read_embedded(self, data, parent_var_type): """Read method for "mixed" variable type. .. Note:: The ``read()`` method will automatically determine if the input is a variable or needs to be searched for embedded variables. There usually is no reason to call this m...
python
{ "resource": "" }
q244103
TcExPlaybook.variable_type
train
def variable_type(self, variable): """Get the Type from the variable string or default to String type. The default type is "String" for those cases when the input variable is contains not "DB variable" and is just a String. **Example Variable**:: #App:1234:output!StringArr...
python
{ "resource": "" }
q244104
TcExPlaybook.wrap_embedded_keyvalue
train
def wrap_embedded_keyvalue(self, data): """Wrap keyvalue embedded variable in double quotes. Args: data (string): The data with embedded variables. Returns: (string): Results retrieved from DB """ if data is not None: try: dat...
python
{ "resource": "" }
q244105
TcExPlaybook.write_output
train
def write_output(self): """Write all stored output data to storage.""" for data in self.output_data.values():
python
{ "resource": "" }
q244106
TcExPlaybook.create_binary
train
def create_binary(self, key, value): """Create method of CRUD operation for binary data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write. """ data = None ...
python
{ "resource": "" }
q244107
TcExPlaybook.read_binary
train
def read_binary(self, key, b64decode=True, decode=False): """Read method of CRUD operation for binary data. Args: key (string): The variable to read from the DB. b64decode (bool): If true the data will be base64 decoded. decode (bool): If true the data will be decode...
python
{ "resource": "" }
q244108
TcExPlaybook.create_binary_array
train
def create_binary_array(self, key, value): """Create method of CRUD operation for binary array data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write. """ dat...
python
{ "resource": "" }
q244109
TcExPlaybook.read_binary_array
train
def read_binary_array(self, key, b64decode=True, decode=False): """Read method of CRUD operation for binary array data. Args: key (string): The variable to read from the DB. b64decode (bool): If true the data will be base64 decoded. decode (bool): If true the data wi...
python
{ "resource": "" }
q244110
TcExPlaybook.create_raw
train
def create_raw(self, key, value): """Create method of CRUD operation for raw data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB.
python
{ "resource": "" }
q244111
TcExPlaybook.read_raw
train
def read_raw(self, key): """Read method of CRUD operation for raw data. Args: key (string): The variable to read from the DB. Returns: (any): Results retrieved from DB. """ data =
python
{ "resource": "" }
q244112
TcExPlaybook.create_string
train
def create_string(self, key, value): """Create method of CRUD operation for string data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write. """ data = None ...
python
{ "resource": "" }
q244113
TcExPlaybook.read_string
train
def read_string(self, key, embedded=True): """Read method of CRUD operation for string data. Args: key (string): The variable to read from the DB. embedded (boolean): Resolve embedded variables. Returns: (string): Results retrieved from DB. """ ...
python
{ "resource": "" }
q244114
TcExPlaybook.create_string_array
train
def create_string_array(self, key, value): """Create method of CRUD operation for string array data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write. """ dat...
python
{ "resource": "" }
q244115
TcExPlaybook.read_string_array
train
def read_string_array(self, key, embedded=True): """Read method of CRUD operation for string array data. Args: key (string): The variable to read from the DB. embedded (boolean): Resolve embedded variables. Returns: (list): Results retrieved from DB. ...
python
{ "resource": "" }
q244116
TcExPlaybook.create_tc_entity
train
def create_tc_entity(self, key, value): """Create method of CRUD operation for TC entity data. Args: key (string): The variable to write to the DB. value (any): The data to write to the DB. Returns: (string): Result of DB write. """ data = No...
python
{ "resource": "" }
q244117
TcExPlaybook.entity_to_bulk
train
def entity_to_bulk(entities, resource_type_parent): """Convert Single TC Entity to Bulk format. .. Attention:: This method is subject to frequent changes Args: entities (dictionary): TC Entity to be converted to Bulk. resource_type_parent (string): The resource parent t...
python
{ "resource": "" }
q244118
TcExPlaybook.indicator_arrays
train
def indicator_arrays(tc_entity_array): """Convert TCEntityArray to Indicator Type dictionary. Args: tc_entity_array (dictionary): The TCEntityArray to convert. Returns: (dictionary): Dictionary containing arrays of indicators for each indicator type.
python
{ "resource": "" }
q244119
TcExPlaybook.json_to_bulk
train
def json_to_bulk(tc_data, value_fields, resource_type, resource_type_parent): """Convert ThreatConnect JSON response to a Bulk Format. .. Attention:: This method is subject to frequent changes Args: tc_data (dictionary): Array of data returned from TC API call. value_fi...
python
{ "resource": "" }
q244120
TcExPlaybook.json_to_entity
train
def json_to_entity(tc_data, value_fields, resource_type, resource_type_parent): """Convert ThreatConnect JSON response to a TCEntityArray. .. Attention:: This method is subject to frequent changes. Args: tc_data (dictionary): Array of data returned from TC API call. val...
python
{ "resource": "" }
q244121
TcExUtils.any_to_datetime
train
def any_to_datetime(self, time_input, tz=None): """Return datetime object from multiple formats. Formats: #. Human Input (e.g 30 days ago, last friday) #. ISO 8601 (e.g. 2017-11-08T16:52:42Z) #. Loose Date format (e.g. 2017 12 25) #. Unix Time/Posix ...
python
{ "resource": "" }
q244122
TcExUtils.date_to_datetime
train
def date_to_datetime(self, time_input, tz=None): """ Convert ISO 8601 and other date strings to datetime.datetime type. Args: time_input (string): The time input string (see formats above). tz (string): The time zone for the returned data. Returns: (datetime...
python
{ "resource": "" }
q244123
TcExUtils.format_datetime
train
def format_datetime(self, time_input, tz=None, date_format=None): """ Return timestamp from multiple input formats. Formats: #. Human Input (e.g 30 days ago, last friday) #. ISO 8601 (e.g. 2017-11-08T16:52:42Z) #. Loose Date format (e.g. 2017 12 25) ...
python
{ "resource": "" }
q244124
TcExUtils.inflect
train
def inflect(self): """Return instance of inflect.""" if self._inflect is None: import inflect
python
{ "resource": "" }
q244125
TcExUtils.write_temp_file
train
def write_temp_file(self, content, filename=None, mode='w'): """Write content to a temporary file. Args: content (bytes|str): The file content. If passing binary data the mode needs to be set to 'wb'. filename (str, optional): The filename to use when writing the...
python
{ "resource": "" }
q244126
TcExUtils.timedelta
train
def timedelta(self, time_input1, time_input2): """ Calculates time delta between two time expressions. Args: time_input1 (string): The time input string (see formats above). time_input2 (string): The time input string (see formats above). Returns: (dict): Di...
python
{ "resource": "" }
q244127
Incident.event_date
train
def event_date(self, event_date): """ Updates the event_date. Args: event_date: Converted to %Y-%m-%dT%H:%M:%SZ date format. Returns: """ if not self.can_update():
python
{ "resource": "" }
q244128
Victim.add_asset
train
def add_asset(self, asset, asset_name, asset_type): """ Adds a asset to the Victim Valid asset_type: + PHONE + EMAIL + NETWORK + SOCIAL + WEB Args: asset: asset_name: asset_type: PHONE, EMAIL, NETWORK, SOCIAL, ...
python
{ "resource": "" }
q244129
Victim.update_asset
train
def update_asset(self, asset, asset_id, asset_name, asset_type): """ Update a asset of a Victim Valid asset_type: + PHONE + EMAIL + NETWORK + SOCIAL + WEB Args: asset: asset_name: asset_id: asset_ty...
python
{ "resource": "" }
q244130
Victim.asset
train
def asset(self, asset_id, asset_type, action='GET'): """ Gets a asset of a Victim Valid asset_type: + PHONE + EMAIL + NETWORK + SOCIAL + WEB Args: asset_type: asset_id: action: Returns: """ ...
python
{ "resource": "" }
q244131
Victim.assets
train
def assets(self, asset_type=None): """ Gets the assets of a Victim Args: asset_type: Yields: asset json """ if not self.can_update(): self._tcex.handle_error(910, [self.type]) if not asset_type: for a in self.tc_requests.vic...
python
{ "resource": "" }
q244132
TcExBin.db_conn
train
def db_conn(self): """Create a temporary in memory DB and return the connection.""" if self._db_conn is None: try: self._db_conn = sqlite3.connect(':memory:')
python
{ "resource": "" }
q244133
TcExBin.db_create_table
train
def db_create_table(self, table_name, columns): """Create a temporary DB table. Arguments: table_name (str): The name of the table. columns (list): List of columns to add to the DB. """ formatted_columns = '' for col in set(columns): formatted...
python
{ "resource": "" }
q244134
TcExBin.handle_error
train
def handle_error(err, halt=True): """Print errors message and optionally exit. Args: err (str): The error message to print.
python
{ "resource": "" }
q244135
TcExBin.install_json
train
def install_json(self): """Return install.json contents.""" file_fqpn = os.path.join(self.app_path, 'install.json') if self._install_json is None: if os.path.isfile(file_fqpn): try: with open(file_fqpn, 'r') as fh: self._ins...
python
{ "resource": "" }
q244136
TcExBin.install_json_params
train
def install_json_params(self, ij=None): """Return install.json params in a dict with name param as key. Args: ij (dict, optional): Defaults to None. The install.json contents. Returns: dict: A dictionary containing the install.json input params with name as key.
python
{ "resource": "" }
q244137
TcExBin.install_json_output_variables
train
def install_json_output_variables(self, ij=None): """Return install.json output variables in a dict with name param as key. Args: ij (dict, optional): Defaults to None. The install.json contents. Returns: dict: A dictionary containing the install.json output variables w...
python
{ "resource": "" }
q244138
TcExBin.layout_json
train
def layout_json(self): """Return layout.json contents.""" file_fqpn = os.path.join(self.app_path, 'layout.json') if self._layout_json is None: if os.path.isfile(file_fqpn): try: with open(file_fqpn, 'r') as fh: self._layout_...
python
{ "resource": "" }
q244139
TcExBin.layout_json_params
train
def layout_json_params(self): """Return layout.json params in a flattened dict with name param as key.""" if self._layout_json_params is None: self._layout_json_params = {} for i in self.layout_json.get('inputs', []):
python
{ "resource": "" }
q244140
TcExBin.layout_json_names
train
def layout_json_names(self): """Return layout.json names.""" if self._layout_json_names is
python
{ "resource": "" }
q244141
TcExBin.layout_json_outputs
train
def layout_json_outputs(self): """Return layout.json outputs in a flattened dict with name param as key.""" if self._layout_json_outputs is None:
python
{ "resource": "" }
q244142
TcExBin.load_install_json
train
def load_install_json(self, filename=None): """Return install.json data. Args: filename (str, optional): Defaults to None. The install.json filename (for bundled Apps). Returns: dict: The contents of the install.json file. """ if filename...
python
{ "resource": "" }
q244143
TcExBin.redis
train
def redis(self): """Return instance of Redis.""" if self._redis is None:
python
{ "resource": "" }
q244144
TcExBin.tcex_json
train
def tcex_json(self): """Return tcex.json file contents.""" file_fqpn = os.path.join(self.app_path, 'tcex.json') if self._tcex_json is None: if os.path.isfile(file_fqpn): try: with open(file_fqpn, 'r') as fh: self._tcex_json ...
python
{ "resource": "" }
q244145
TcExBin.update_system_path
train
def update_system_path(): """Update the system path to ensure project modules and dependencies can be found.""" cwd = os.getcwd() lib_dir = os.path.join(os.getcwd(), 'lib_') lib_latest = os.path.join(os.getcwd(), 'lib_latest') # insert the lib_latest directory into the system Pa...
python
{ "resource": "" }
q244146
TcExSession._hmac_auth
train
def _hmac_auth(self): """Add ThreatConnect HMAC Auth to Session.""" return
python
{ "resource": "" }
q244147
TcExSession._token_auth
train
def _token_auth(self): """Add ThreatConnect Token Auth to Session.""" return TcExTokenAuth( self, self.args.tc_token,
python
{ "resource": "" }
q244148
TcExSession.request
train
def request(self, method, url, **kwargs): """Override request method disabling verify on token renewal if disabled on session.""" if not url.startswith('https'):
python
{ "resource": "" }
q244149
Indicator.add_key_value
train
def add_key_value(self, key, value): """Add custom field to Indicator object. .. note:: The key must be the exact name required by the batch schema. Example:: file_hash = tcex.batch.file('File', '1d878cdc391461e392678ba3fc9f6f32') file_hash.add_key_value('size', '1024'...
python
{ "resource": "" }
q244150
Indicator.association
train
def association(self, group_xid): """Add association using xid value. Args: group_xid (str): The external id of the Group to associate. """
python
{ "resource": "" }
q244151
Indicator.attribute
train
def attribute( self, attr_type, attr_value, displayed=False, source=None, unique=True, formatter=None ): """Return instance of Attribute unique: * False - Attribute type:value can be duplicated. * Type - Attribute type has to be unique (e.g., only 1 Description Attri...
python
{ "resource": "" }
q244152
Indicator.data
train
def data(self): """Return Indicator data.""" # add attributes if self._attributes: self._indicator_data['attribute'] = [] for attr in self._attributes: if attr.valid: self._indicator_data['attribute'].append(attr.data) # add fil...
python
{ "resource": "" }
q244153
Indicator.last_modified
train
def last_modified(self, last_modified): """Set Indicator lastModified.""" self._indicator_data['lastModified']
python
{ "resource": "" }
q244154
Indicator.occurrence
train
def occurrence(self, file_name=None, path=None, date=None): """Add a file Occurrence. Args: file_name (str, optional): The file name for this occurrence. path (str, optional): The file path for this occurrence. date (str, optional): The datetime expression for
python
{ "resource": "" }
q244155
File.action
train
def action(self, relationship): """Add a File Action.""" action_obj = FileAction(self._indicator_data.get('xid'),
python
{ "resource": "" }
q244156
FileAction.data
train
def data(self): """Return File Occurrence data.""" if self._children: for child in self._children:
python
{ "resource": "" }
q244157
FileAction.action
train
def action(self, relationship): """Add a nested File Action.""" action_obj
python
{ "resource": "" }
q244158
FileOccurrence.date
train
def date(self, date): """Set File Occurrence date.""" self._occurrence_data['date'] = self._utils.format_datetime(
python
{ "resource": "" }
q244159
TcExTi.address
train
def address(self, ip, owner=None, **kwargs): """ Create the Address TI object. Args: owner: ip:
python
{ "resource": "" }
q244160
TcExTi.url
train
def url(self, url, owner=None, **kwargs): """ Create the URL TI object. Args: owner: url:
python
{ "resource": "" }
q244161
TcExTi.email_address
train
def email_address(self, address, owner=None, **kwargs): """ Create the Email Address TI object. Args: owner: address:
python
{ "resource": "" }
q244162
TcExTi.file
train
def file(self, owner=None, **kwargs): """ Create the File TI object. Args: owner: **kwargs:
python
{ "resource": "" }
q244163
TcExTi.host
train
def host(self, hostname, owner=None, **kwargs): """ Create the Host TI object. Args: owner: hostname:
python
{ "resource": "" }
q244164
TcExTi.indicator
train
def indicator(self, indicator_type=None, owner=None, **kwargs): """ Create the Indicator TI object. Args: owner: indicator_type: **kwargs: Return: """ if not indicator_type: return Indicator(self.tcex, None, owner=owner, ...
python
{ "resource": "" }
q244165
TcExTi.group
train
def group(self, group_type=None, owner=None, **kwargs): """ Create the Group TI object. Args: owner: group_type: **kwargs: Return: """ group = None if not group_type: return Group(self.tcex, None, None, owner=own...
python
{ "resource": "" }
q244166
TcExTi.adversary
train
def adversary(self, name, owner=None, **kwargs): """ Create the Adversary TI object. Args: owner: name:
python
{ "resource": "" }
q244167
TcExTi.campaign
train
def campaign(self, name, owner=None, **kwargs): """ Create the Campaign TI object. Args: owner: name:
python
{ "resource": "" }
q244168
TcExTi.document
train
def document(self, name, file_name, owner=None, **kwargs): """ Create the Document TI object. Args: owner: name:
python
{ "resource": "" }
q244169
TcExTi.event
train
def event(self, name, owner=None, **kwargs): """ Create the Event TI object. Args: name: **kwargs:
python
{ "resource": "" }
q244170
TcExTi.email
train
def email(self, name, to, from_addr, subject, body, header, owner=None, **kwargs): """ Create the Email TI object. Args: owner: to: from_addr: name: subject: header: body:
python
{ "resource": "" }
q244171
TcExTi.incident
train
def incident(self, name, owner=None, **kwargs): """ Create the Incident TI object. Args: owner: name:
python
{ "resource": "" }
q244172
TcExTi.intrusion_sets
train
def intrusion_sets(self, name, owner=None, **kwargs): """ Create the Intrustion Set TI object. Args: owner: name:
python
{ "resource": "" }
q244173
TcExTi.report
train
def report(self, name, owner=None, **kwargs): """ Create the Report TI object. Args: owner: name:
python
{ "resource": "" }
q244174
TcExTi.signature
train
def signature(self, name, file_name, file_type, file_content, owner=None, **kwargs): """ Create the Signature TI object. Args: owner:
python
{ "resource": "" }
q244175
TcExTi.threat
train
def threat(self, name, owner=None, **kwargs): """ Create the Threat TI object. Args: owner: name:
python
{ "resource": "" }
q244176
TcExTi.victim
train
def victim(self, name, owner=None, **kwargs): """ Create the Victim TI object. Args: owner: name:
python
{ "resource": "" }
q244177
TcExLogFormatter.format
train
def format(self, record): """Format log record for ThreatConnect API. Example log event:: [{ "timestamp": 1478907537000, "message": "Test Message",
python
{ "resource": "" }
q244178
TcExLogHandler.emit
train
def emit(self, record): """Emit the log record.""" self.entries.append(self.format(record)) if
python
{ "resource": "" }
q244179
TcExLogHandler.log_to_api
train
def log_to_api(self): """Best effort API logger. Send logs to the ThreatConnect API and do nothing if the attempt fails. """ if self.entries: try: headers = {'Content-Type': 'application/json'} self.session.post('/v2/logs/app', headers=headers...
python
{ "resource": "" }
q244180
class_factory
train
def class_factory(name, base_class, class_dict): """Internal method for dynamically building Custom Indicator classes.""" def __init__(self, tcex): base_class.__init__(self, tcex) for k, v in class_dict.items():
python
{ "resource": "" }
q244181
Resource._apply_filters
train
def _apply_filters(self): """Apply any filters added to the resource. """ # apply filters filters = [] for f in self._filters: filters.append('{}{}{}'.format(f['name'], f['operator'], f['value']))
python
{ "resource": "" }
q244182
Resource._request_process_json
train
def _request_process_json(self, response): """Handle response data of type JSON Return: (string): The data from the download (string): The status of the download """ data = [] try: if self._api_branch == 'bulk': response_data =...
python
{ "resource": "" }
q244183
Resource._request_process_json_bulk
train
def _request_process_json_bulk(self, response_data): """Handle bulk JSON response Return: (string): The response data (string): The response status """ status = 'Failure'
python
{ "resource": "" }
q244184
Resource._request_process_json_standard
train
def _request_process_json_standard(self, response_data): """Handle JSON response This should be the most common response from the ThreatConnect API. Return: (string): The response data (string): The response status
python
{ "resource": "" }
q244185
Resource._request_process_octet
train
def _request_process_octet(response): """Handle Document download. Return: (string): The data from the download (string): The status of the download """ status = 'Failure'
python
{ "resource": "" }
q244186
Resource._request_process_text
train
def _request_process_text(response): """Handle Signature download. Return: (string): The data from the download (string): The status of the download """ status = 'Failure'
python
{ "resource": "" }
q244187
Resource.add_filter
train
def add_filter(self, name, operator, value): """Add ThreatConnect API Filter for this resource request. External Reference: https://docs.threatconnect.com Args: name (string): The filter field name.
python
{ "resource": "" }
q244188
Resource.association_custom
train
def association_custom(self, association_name, association_resource=None): """Custom Indicator association for this resource with resource value. **Example Endpoints URI's** +--------+--------------------------------------------------------------------------+ | HTTP | API Endpoint UR...
python
{ "resource": "" }
q244189
Resource.association_pivot
train
def association_pivot(self, association_resource): """Pivot point on association for this resource. This method will return all *resources* (group, indicators, task, victims, etc) for this resource that are associated with the provided resource. **Example Endpoints URI's** +--...
python
{ "resource": "" }
q244190
Resource.associations
train
def associations(self, association_resource): """Retrieve Association for this resource of the type in association_resource. This method will return all *resources* (group, indicators, task, victims, etc) for this resource that are associated with the provided association resource_type. ...
python
{ "resource": "" }
q244191
Resource.attributes
train
def attributes(self, resource_id=None): """Attribute endpoint for this resource with optional attribute id. This method will set the resource endpoint for working with Attributes. The HTTP GET method will return all attributes applied to this resource or if a resource id (attribute id) ...
python
{ "resource": "" }
q244192
Resource.copy_reset
train
def copy_reset(self): """Reset values after instance has been copied""" # Reset settings self._filters = []
python
{ "resource": "" }
q244193
Resource.copy
train
def copy(self): """Return a "clean" copy of this instance. Return: (instance): A clean copy of this instance. """ resource = copy.copy(self) # workaround for bytes/str issue in Py3 with copy of instance # TypeError: a bytes-like object is required, not 'str'...
python
{ "resource": "" }
q244194
Resource.group_pivot
train
def group_pivot(self, group_resource): """Pivot point on groups for this resource. This method will return all *resources* (indicators, tasks, victims, etc) for this resource that are associated with the provided resource id (indicator value). **Example Endpoints URI's** +----...
python
{ "resource": "" }
q244195
Resource.http_method
train
def http_method(self, data): """The HTTP Method for this resource request.""" data = data.upper() if data in ['DELETE', 'GET', 'POST', 'PUT']:
python
{ "resource": "" }
q244196
Resource.indicator_pivot
train
def indicator_pivot(self, indicator_resource): """Pivot point on indicators for this resource. This method will return all *resources* (groups, tasks, victims, etc) for this resource that are associated with the provided resource id (indicator value). **Example Endpoints URI's*...
python
{ "resource": "" }
q244197
Resource.owner
train
def owner(self, data): """The Owner payload value for this resource request.""" if data is not None: self._request.add_payload('owner', data)
python
{ "resource": "" }
q244198
Resource.paginate
train
def paginate(self): """Paginate results from ThreatConnect API .. Attention:: This method will be deprecated in a future release. Return: (dictionary): Resource Data """ self.tcex.log.warning(u'Using deprecated method (paginate).') resources = [] sel...
python
{ "resource": "" }
q244199
Resource.request
train
def request(self): """Send the request to the API. This method will send the request to the API. It will try to handle all the types of responses and provide the relevant data when possible. Some basic error detection and handling is implemented, but not all failure cases will ...
python
{ "resource": "" }