INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
The actual query happens here. Time from queries is replaced with isoformat.
:param domain: The domain which should gets queried.
:type domain: str
:returns: List of dicts containing the search results.
:rtype: [list, dict] | def query(self, domain):
"""The actual query happens here. Time from queries is replaced with isoformat.
:param domain: The domain which should gets queried.
:type domain: str
:returns: List of dicts containing the search results.
:rtype: [list, dict]
"""
result ... |
Queries Circl.lu Passive SSL for an ip using PyPSSL class. Returns error if nothing is found.
:param ip: IP to query for
:type ip: str
:returns: python dict of results
:rtype: dict | def query_ip(self, ip):
"""
Queries Circl.lu Passive SSL for an ip using PyPSSL class. Returns error if nothing is found.
:param ip: IP to query for
:type ip: str
:returns: python dict of results
:rtype: dict
"""
try:
result = self.pssl.query(... |
Queries Circl.lu Passive SSL for a certificate hash using PyPSSL class. Returns error if nothing is found.
:param cert_hash: hash to query for
:type cert_hash: str
:return: python dict of results
:rtype: dict | def query_certificate(self, cert_hash):
"""
Queries Circl.lu Passive SSL for a certificate hash using PyPSSL class. Returns error if nothing is found.
:param cert_hash: hash to query for
:type cert_hash: str
:return: python dict of results
:rtype: dict
"""
... |
Specialized wrapper arround the requests module to request data from Onyphe
:param path: The URL path after the onyphe FQDN
:type path: str
:param query_params: The dictionnary of query parameters that gets appended to the URL
:type query_params: str | def _request(self, path: str, query_params: dict={}):
"""Specialized wrapper arround the requests module to request data from Onyphe
:param path: The URL path after the onyphe FQDN
:type path: str
:param query_params: The dictionnary of query parameters that gets appended to the URL
... |
Return geolocate information from ip address (Geolocate doesn't need apikey !!) | def geolocate(self, ip: str):
"""Return geolocate information from ip address (Geolocate doesn't need apikey !!)
"""
url_path = "/api/geoloc/{ip}".format(ip=ip)
return self._request_without_api(path=url_path) |
Return threatlist information we have for the given IPv{4,6} address with history of changes | def threatlist(self, ip: str):
"""Return threatlist information we have for the given IPv{4,6} address with history of changes
"""
url_path = "/api/threatlist/{ip}".format(ip=ip)
return self._request(path=url_path) |
Return datascan information we have for the given IPv{4,6} address or string with history of changes | def datascan(self, search: str):
"""Return datascan information we have for the given IPv{4,6} address or string with history of changes
"""
url_path = "/api/datascan/{search}".format(search=search)
return self._request(path=url_path) |
Return reverse DNS lookup information we have for the given IPv{4,6} address with history of changes. Multiple reverse DNS entries may match. We return all of them. | def reverse(self, search: str):
"""Return reverse DNS lookup information we have for the given IPv{4,6} address with history of changes. Multiple reverse DNS entries may match. We return all of them.
"""
url_path = "/api/reverse/{search}".format(search=search)
return self._request(path=u... |
Return forward DNS lookup information we have for the given IPv{4,6} address with history of changes. Multiple forward DNS entries may match. We return all of them. | def forward(self, search: str):
"""Return forward DNS lookup information we have for the given IPv{4,6} address with history of changes. Multiple forward DNS entries may match. We return all of them.
"""
url_path = "/api/forward/{search}".format(search=search)
return self._request(path=u... |
Checks a given file against all available yara rules
:param file: Path to file
:type file:str
:returns: Python list with matched rules info
:rtype: list | def check(self, file):
"""
Checks a given file against all available yara rules
:param file: Path to file
:type file:str
:returns: Python list with matched rules info
:rtype: list
"""
result = []
all_matches = []
for filerules in os.listdir... |
Here all the workload happens. Read the files, check if the ip is in there and report the results.
If the lock file is found, which gets created when lists are getting updated, the script starts to sleep 10
seconds before checking again. Also reads the source file date and checks, if its too old (ignore... | def _check_ip(self, ip):
"""Here all the workload happens. Read the files, check if the ip is in there and report the results.
If the lock file is found, which gets created when lists are getting updated, the script starts to sleep 10
seconds before checking again. Also reads the source file dat... |
Map GreyNoise intentions to Cortex maliciousness levels.
Accept a Cortex level and a GreyNoise intention, the return the more malicious of the two.
:param current_level: A Cortex maliciousness level
https://github.com/TheHive-Project/CortexDocs/blob/master/api/how-to-create-an-analyzer.md#o... | def _get_level(current_level, new_intention):
"""
Map GreyNoise intentions to Cortex maliciousness levels.
Accept a Cortex level and a GreyNoise intention, the return the more malicious of the two.
:param current_level: A Cortex maliciousness level
https://github.com/TheHive... |
Return one taxonomy summarizing the reported tags
If there is only one tag, use it as the predicate
If there are multiple tags, use "entries" as the predicate
Use the total count as the value
Use the most malicious level found
Examples:
Input
{... | def summary(self, raw):
"""
Return one taxonomy summarizing the reported tags
If there is only one tag, use it as the predicate
If there are multiple tags, use "entries" as the predicate
Use the total count as the value
Use the most malicious level found
... |
Output the requests response JSON and status code
:rtype : dict
:param response: requests response object
:return: dict containing the JSON response and/or the status code with error string. | def _return_response_and_status_code(response):
""" Output the requests response JSON and status code
:rtype : dict
:param response: requests response object
:return: dict containing the JSON response and/or the status code with error string.
"""
if response.status_code == requests.codes.ok:
... |
Submit a file to be scanned by VirusTotal
:param this_file: File to be scanned (32MB file size limit)
:return: JSON response that contains scan_id and permalink. | def scan_file(self, this_file):
""" Submit a file to be scanned by VirusTotal
:param this_file: File to be scanned (32MB file size limit)
:return: JSON response that contains scan_id and permalink.
"""
params = {'apikey': self.api_key}
try:
if type(this_file)... |
Submit a URL to be scanned by VirusTotal.
:param this_url: The URL that should be scanned. This parameter accepts a list of URLs (up to 4 with the
standard request rate) so as to perform a batch scanning request with one single call. The
URLs must be separated ... | def scan_url(self, this_url):
""" Submit a URL to be scanned by VirusTotal.
:param this_url: The URL that should be scanned. This parameter accepts a list of URLs (up to 4 with the
standard request rate) so as to perform a batch scanning request with one single call. The
... |
Submit a file to be scanned by VirusTotal.
Allows you to send a file for scanning with VirusTotal. Before performing your submissions we encourage you to
retrieve the latest report on the files, if it is recent enough you might want to save time and bandwidth by
making use of it. File size limi... | def scan_file(self, this_file, notify_url=None, notify_changes_only=None):
""" Submit a file to be scanned by VirusTotal.
Allows you to send a file for scanning with VirusTotal. Before performing your submissions we encourage you to
retrieve the latest report on the files, if it is recent enoug... |
Download a file by its hash.
Downloads a file from VirusTotal's store given one of its hashes. This call can be used in conjuction with
the file searching call in order to download samples that match a given set of criteria.
:param this_hash: The md5/sha1/sha256 hash of the file you want to do... | def get_file(self, this_hash):
""" Download a file by its hash.
Downloads a file from VirusTotal's store given one of its hashes. This call can be used in conjuction with
the file searching call in order to download samples that match a given set of criteria.
:param this_hash: The md5/... |
Get the scan results for a URL.
:param this_url: A URL for which you want to retrieve the most recent report. You may also specify a scan_id
(sha256-timestamp as returned by the URL submission API) to access a specific report. At the same time, you
can specify a CSV list made up of a combinatio... | def get_url_report(self, this_url, scan='0', allinfo=1):
""" Get the scan results for a URL.
:param this_url: A URL for which you want to retrieve the most recent report. You may also specify a scan_id
(sha256-timestamp as returned by the URL submission API) to access a specific report. At the ... |
Get comments for a file or URL.
Retrieve a list of VirusTotal Community comments for a given file or URL. VirusTotal Community comments are
user submitted reviews on a given item, these comments may contain anything from the in-the-wild locations of
files up to fully-featured reverse engineerin... | def get_comments(self, resource, before=None):
""" Get comments for a file or URL.
Retrieve a list of VirusTotal Community comments for a given file or URL. VirusTotal Community comments are
user submitted reviews on a given item, these comments may contain anything from the in-the-wild locatio... |
Get the scan results for a file.
Even if you do not have a Private Mass API key that you can use, you can still automate VirusTotal Intelligence
searches pretty much in the same way that the searching for files api call works.
:param query: a VirusTotal Intelligence search string in accordance... | def get_hashes_from_search(self, query, page=None):
""" Get the scan results for a file.
Even if you do not have a Private Mass API key that you can use, you can still automate VirusTotal Intelligence
searches pretty much in the same way that the searching for files api call works.
:pa... |
Get the scan results for a file.
Even if you do not have a Private Mass API key that you can use, you can still download files from the
VirusTotal storage making use of your VirusTotal Intelligence quota, i.e. programmatic downloads will
also deduct quota.
:param file_hash: You may use... | def get_file(self, file_hash, save_file_at):
""" Get the scan results for a file.
Even if you do not have a Private Mass API key that you can use, you can still download files from the
VirusTotal storage making use of your VirusTotal Intelligence quota, i.e. programmatic downloads will
... |
Get File Report (All Pages).
:param query: a VirusTotal Intelligence search string in accordance with the file search documentation.
:return: All JSON responses appended together. | def get_all_file_report_pages(self, query):
""" Get File Report (All Pages).
:param query: a VirusTotal Intelligence search string in accordance with the file search documentation.
:return: All JSON responses appended together.
"""
responses = []
next_page, response = se... |
Save Downloaded File to Disk Helper Function
:param save_file_at: Path of where to save the file.
:param file_stream: File stream
:param filename: Name to save the file. | def save_downloaded_file(filename, save_file_at, file_stream):
""" Save Downloaded File to Disk Helper Function
:param save_file_at: Path of where to save the file.
:param file_stream: File stream
:param filename: Name to save the file.
"""
filename = os.path.join(save_f... |
Dict with locale codes as keys and localized name as value | def name(self):
"""Dict with locale codes as keys and localized name as value"""
# pylint:disable=E1101
return next((self.names.get(x) for x in self._locales if x in
self.names), None) |
Parse, format and return scan summary. | def summary(self, raw):
"""Parse, format and return scan summary."""
taxonomies = []
level = "info"
namespace = "Patrowl"
# getreport service
if self.service == 'getreport':
if 'risk_level' in raw and raw['risk_level']:
risk_level = raw['risk_... |
Run the analyzer. | def run(self):
"""Run the analyzer."""
try:
if self.service == 'getreport':
service_url = '{}/assets/api/v1/details/{}'.format(
self.url, self.get_data())
headers = {
'Authorization': 'token {}'.format(s... |
Run the process to get observation data from Backscatter.io. | def run(self):
"""Run the process to get observation data from Backscatter.io."""
kwargs = {'query': self.get_data()}
if self.data_type == "ip":
kwargs.update({'query_type': 'ip'})
elif self.data_type == "network":
kwargs.update({'query_type': 'network'})
... |
Use the Backscatter.io summary data to create a view. | def summary(self, raw):
"""Use the Backscatter.io summary data to create a view."""
taxonomies = list()
level = 'info'
namespace = 'Backscatter.io'
if self.service == 'observations':
summary = raw.get('results', dict()).get('summary', dict())
taxonomies =... |
Decode a section of the data section starting at offset
Arguments:
offset -- the location of the data structure to decode | def decode(self, offset):
"""Decode a section of the data section starting at offset
Arguments:
offset -- the location of the data structure to decode
"""
new_offset = offset + 1
(ctrl_byte,) = struct.unpack(b'!B', self._buffer[offset:new_offset])
type_num = ctrl... |
Downloads information about a sample using a given hash.
:param samplehash: hash to search for. Has to be either md5, sha1 or sha256
:type samplehash: str
:returns: Dictionary of results
:rtype: dict | def get_sample(self, samplehash):
"""
Downloads information about a sample using a given hash.
:param samplehash: hash to search for. Has to be either md5, sha1 or sha256
:type samplehash: str
:returns: Dictionary of results
:rtype: dict
"""
apiurl = '/re... |
Uploads a new sample to VMRay api. Filename gets sent base64 encoded.
:param filepath: path to sample
:type filepath: str
:param filename: filename of the original file
:type filename: str
:param tags: List of tags to apply to the sample
:type tags: list(str)
:re... | def submit_sample(self, filepath, filename, tags=['TheHive']):
"""
Uploads a new sample to VMRay api. Filename gets sent base64 encoded.
:param filepath: path to sample
:type filepath: str
:param filename: filename of the original file
:type filename: str
:param ... |
Queries vmray to check id a job was
:param submissionid: ID of the job/submission
:type submissionid: int
:returns: True if job finished, false if not
:rtype: bool | def query_job_status(self, submissionid):
"""
Queries vmray to check id a job was
:param submissionid: ID of the job/submission
:type submissionid: int
:returns: True if job finished, false if not
:rtype: bool
"""
apiurl = '/rest/submission/'
... |
Properly format the results | def build_results(self, results):
"""Properly format the results"""
self.add_result_subsection(
'Exploit mitigation techniques',
{
'level': results.get('Plugins', {}).get('mitigation', {}).get('level', None),
'summary': results.get('Plugins', {}).g... |
Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
version: An Integer, 4 or 6. If set, don't try t... | def IPAddress(address, version=None):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
ver... |
Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by default.
version: An Integer, if set, don't try to automa... | def IPNetwork(address, version=None, strict=False):
"""Take an IP string/int and return an object of the correct type.
Args:
address: A string or integer, the IP address. Either IPv4 or
IPv6 addresses may be supplied; integers less than 2**32 will
be considered to be IPv4 by defaul... |
The binary representation of this address.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The binary representation of this address.
Raises:
ValueError: If the integer is too large to be an IPv4 IP
address. | def v4_int_to_packed(address):
"""The binary representation of this address.
Args:
address: An integer representation of an IPv4 IP address.
Returns:
The binary representation of this address.
Raises:
ValueError: If the integer is too large to be an IPv4 IP
address.
... |
Get the number of leading bits that are same for two numbers.
Args:
number1: an integer.
number2: another integer.
bits: the maximum number of bits to compare.
Returns:
The number of leading bits that are the same for two numbers. | def _get_prefix_length(number1, number2, bits):
"""Get the number of leading bits that are same for two numbers.
Args:
number1: an integer.
number2: another integer.
bits: the maximum number of bits to compare.
Returns:
The number of leading bits that are the same for two n... |
Summarize a network range given the first and last IP addresses.
Example:
>>> summarize_address_range(IPv4Address('1.1.1.0'),
IPv4Address('1.1.1.130'))
[IPv4Network('1.1.1.0/25'), IPv4Network('1.1.1.128/31'),
IPv4Network('1.1.1.130/32')]
Args:
first: the first IPv4A... | def summarize_address_range(first, last):
"""Summarize a network range given the first and last IP addresses.
Example:
>>> summarize_address_range(IPv4Address('1.1.1.0'),
IPv4Address('1.1.1.130'))
[IPv4Network('1.1.1.0/25'), IPv4Network('1.1.1.128/31'),
IPv4Network('1.1.1.13... |
Loops through the addresses, collapsing concurrent netblocks.
Example:
ip1 = IPv4Network('1.1.0.0/24')
ip2 = IPv4Network('1.1.1.0/24')
ip3 = IPv4Network('1.1.2.0/24')
ip4 = IPv4Network('1.1.3.0/24')
ip5 = IPv4Network('1.1.4.0/24')
ip6 = IPv4Network('1.1.0.1/22')
... | def _collapse_address_list_recursive(addresses):
"""Loops through the addresses, collapsing concurrent netblocks.
Example:
ip1 = IPv4Network('1.1.0.0/24')
ip2 = IPv4Network('1.1.1.0/24')
ip3 = IPv4Network('1.1.2.0/24')
ip4 = IPv4Network('1.1.3.0/24')
ip5 = IPv4Network('... |
Collapse a list of IP objects.
Example:
collapse_address_list([IPv4('1.1.0.0/24'), IPv4('1.1.1.0/24')]) ->
[IPv4('1.1.0.0/23')]
Args:
addresses: A list of IPv4Network or IPv6Network objects.
Returns:
A list of IPv4Network or IPv6Network objects depending on what we
... | def collapse_address_list(addresses):
"""Collapse a list of IP objects.
Example:
collapse_address_list([IPv4('1.1.0.0/24'), IPv4('1.1.1.0/24')]) ->
[IPv4('1.1.0.0/23')]
Args:
addresses: A list of IPv4Network or IPv6Network objects.
Returns:
A list of IPv4Network or I... |
Return a key suitable for sorting between networks and addresses.
Address and Network objects are not sortable by default; they're
fundamentally different so the expression
IPv4Address('1.1.1.1') <= IPv4Network('1.1.1.1/24')
doesn't make any sense. There are some times however, where you may wis... | def get_mixed_type_key(obj):
"""Return a key suitable for sorting between networks and addresses.
Address and Network objects are not sortable by default; they're
fundamentally different so the expression
IPv4Address('1.1.1.1') <= IPv4Network('1.1.1.1/24')
doesn't make any sense. There are s... |
Tell if self is partly contained in other. | def overlaps(self, other):
"""Tell if self is partly contained in other."""
return self.network in other or self.broadcast in other or (
other.network in self or other.broadcast in self) |
Remove an address from a larger block.
For example:
addr1 = IPNetwork('10.1.1.0/24')
addr2 = IPNetwork('10.1.1.0/26')
addr1.address_exclude(addr2) =
[IPNetwork('10.1.1.64/26'), IPNetwork('10.1.1.128/25')]
or IPv6:
addr1 = IPNetwork('::1... | def address_exclude(self, other):
"""Remove an address from a larger block.
For example:
addr1 = IPNetwork('10.1.1.0/24')
addr2 = IPNetwork('10.1.1.0/26')
addr1.address_exclude(addr2) =
[IPNetwork('10.1.1.64/26'), IPNetwork('10.1.1.128/25')]
... |
Compare two IP objects.
This is only concerned about the comparison of the integer
representation of the network addresses. This means that the
host bits aren't considered at all in this method. If you want
to compare host bits, you can easily enough do a
'HostA._ip < HostB._i... | def compare_networks(self, other):
"""Compare two IP objects.
This is only concerned about the comparison of the integer
representation of the network addresses. This means that the
host bits aren't considered at all in this method. If you want
to compare host bits, you can ea... |
Return prefix length from a bitwise netmask.
Args:
ip_int: An integer, the netmask in expanded bitwise format.
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid netmask. | def _prefix_from_ip_int(self, ip_int):
"""Return prefix length from a bitwise netmask.
Args:
ip_int: An integer, the netmask in expanded bitwise format.
Returns:
An integer, the prefix length.
Raises:
NetmaskValueError: If the input is not a valid n... |
Turn a prefix length string into an integer.
Args:
prefixlen_str: A decimal string containing the prefix length.
Returns:
The prefix length as an integer.
Raises:
NetmaskValueError: If the input is malformed or out of range. | def _prefix_from_prefix_string(self, prefixlen_str):
"""Turn a prefix length string into an integer.
Args:
prefixlen_str: A decimal string containing the prefix length.
Returns:
The prefix length as an integer.
Raises:
NetmaskValueError: If the inpu... |
Turn a netmask/hostmask string into a prefix length.
Args:
ip_str: A netmask or hostmask, formatted as an IP address.
Returns:
The prefix length as an integer.
Raises:
NetmaskValueError: If the input is not a netmask or hostmask. | def _prefix_from_ip_string(self, ip_str):
"""Turn a netmask/hostmask string into a prefix length.
Args:
ip_str: A netmask or hostmask, formatted as an IP address.
Returns:
The prefix length as an integer.
Raises:
NetmaskValueError: If the input is n... |
The subnets which join to make the current subnet.
In the case that self contains only one IP
(self._prefixlen == 32 for IPv4 or self._prefixlen == 128
for IPv6), return a list with just ourself.
Args:
prefixlen_diff: An integer, the amount the prefix length
s... | def iter_subnets(self, prefixlen_diff=1, new_prefix=None):
"""The subnets which join to make the current subnet.
In the case that self contains only one IP
(self._prefixlen == 32 for IPv4 or self._prefixlen == 128
for IPv6), return a list with just ourself.
Args:
pr... |
Return the network object with the host bits masked out. | def masked(self):
"""Return the network object with the host bits masked out."""
return IPNetwork('%s/%d' % (self.network, self._prefixlen),
version=self._version) |
The supernet containing the current network.
Args:
prefixlen_diff: An integer, the amount the prefix length of
the network should be decreased by. For example, given a
/24 network and a prefixlen_diff of 3, a supernet with a
/21 netmask is returned.
... | def supernet(self, prefixlen_diff=1, new_prefix=None):
"""The supernet containing the current network.
Args:
prefixlen_diff: An integer, the amount the prefix length of
the network should be decreased by. For example, given a
/24 network and a prefixlen_diff of ... |
Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address. | def _ip_int_from_string(self, ip_str):
"""Turn the given IP string into an integer for comparison.
Args:
ip_str: A string, the IP ip_str.
Returns:
The IP ip_str as an integer.
Raises:
AddressValueError: if ip_str isn't a valid IPv4 Address.
... |
Convert a decimal octet into an integer.
Args:
octet_str: A string, the number to parse.
Returns:
The octet as an integer.
Raises:
ValueError: if the octet isn't strictly a decimal from [0..255]. | def _parse_octet(self, octet_str):
"""Convert a decimal octet into an integer.
Args:
octet_str: A string, the number to parse.
Returns:
The octet as an integer.
Raises:
ValueError: if the octet isn't strictly a decimal from [0..255].
"""
... |
Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation. | def _string_from_ip_int(self, ip_int):
"""Turns a 32-bit integer into dotted decimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
The IP address as a string in dotted decimal notation.
"""
octets = []
for _ in xrange(4):
... |
Turn an IPv6 ip_str into an integer.
Args:
ip_str: A string, the IPv6 ip_str.
Returns:
A long, the IPv6 ip_str.
Raises:
AddressValueError: if ip_str isn't a valid IPv6 Address. | def _ip_int_from_string(self, ip_str):
"""Turn an IPv6 ip_str into an integer.
Args:
ip_str: A string, the IPv6 ip_str.
Returns:
A long, the IPv6 ip_str.
Raises:
AddressValueError: if ip_str isn't a valid IPv6 Address.
"""
parts = i... |
Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from [0..FFFF]. | def _parse_hextet(self, hextet_str):
"""Convert an IPv6 hextet string into an integer.
Args:
hextet_str: A string, the number to parse.
Returns:
The hextet as an integer.
Raises:
ValueError: if the input isn't strictly a hex number from [0..FFFF].
... |
Compresses a list of hextets.
Compresses a list of strings, replacing the longest continuous
sequence of "0" in the list with "" and adding empty strings at
the beginning or at the end of the string such that subsequently
calling ":".join(hextets) will produce the compressed version of
... | def _compress_hextets(self, hextets):
"""Compresses a list of hextets.
Compresses a list of strings, replacing the longest continuous
sequence of "0" in the list with "" and adding empty strings at
the beginning or at the end of the string such that subsequently
calling ":".join... |
Turns a 128-bit integer into hexadecimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
A string, the hexadecimal representation of the address.
Raises:
ValueError: The address is bigger than 128 bits of all ones. | def _string_from_ip_int(self, ip_int=None):
"""Turns a 128-bit integer into hexadecimal notation.
Args:
ip_int: An integer, the IP address.
Returns:
A string, the hexadecimal representation of the address.
Raises:
ValueError: The address is bigger t... |
Expand a shortened IPv6 address.
Args:
ip_str: A string, the IPv6 address.
Returns:
A string, the expanded IPv6 address. | def _explode_shorthand_ip_string(self):
"""Expand a shortened IPv6 address.
Args:
ip_str: A string, the IPv6 address.
Returns:
A string, the expanded IPv6 address.
"""
if isinstance(self, _BaseNet):
ip_str = str(self.ip)
else:
... |
Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges. | def is_reserved(self):
"""Test if the address is otherwise IETF reserved.
Returns:
A boolean, True if the address is within one of the
reserved IPv6 Network ranges.
"""
return (self in IPv6Network('::/8') or
self in IPv6Network('100::/8') or
... |
Output the requests response JSON and status code
:rtype : dict
:param response: requests response object
:return: dict containing the JSON response and/or the status code with error string. | def _return_response_and_status_code(response):
""" Output the requests response JSON and status code
:rtype : dict
:param response: requests response object
:return: dict containing the JSON response and/or the status code with error string.
"""
result_codes = {
"-11": "No matching da... |
Submit a file to be scanned by Malwares
:param this_file: File to be scanned (200MB file size limit)
:param this_filename: Filename for scanned file
:return: JSON response that contains scan_id and permalink. | def scan_file(self, this_file, this_filename):
""" Submit a file to be scanned by Malwares
:param this_file: File to be scanned (200MB file size limit)
:param this_filename: Filename for scanned file
:return: JSON response that contains scan_id and permalink.
"""
params ... |
Get the scan results for a file.
:param this_hash: The md5/sha1/sha256/scan_ids hash of the file whose dynamic behavioural report you want to
retrieve or scan_ids from a previous call to scan_file.
:return: | def get_file_report(self, this_hash):
""" Get the scan results for a file.
:param this_hash: The md5/sha1/sha256/scan_ids hash of the file whose dynamic behavioural report you want to
retrieve or scan_ids from a previous call to scan_file.
:return:
"""
... |
Prepares the http body for querying safebrowsing api. Maybe the list need to get adjusted.
:param search_value: value to search for
:type search_value: str
:param search_type: 'url' or 'ip'
:type search_type: str
:returns: http body as dict
:rtype: dict | def __prepare_body(self, search_value, search_type='url'):
"""
Prepares the http body for querying safebrowsing api. Maybe the list need to get adjusted.
:param search_value: value to search for
:type search_value: str
:param search_type: 'url' or 'ip'
:type search_type:... |
The actual query to safebrowsing api
:param search_value: value to search for
:type search_value: str
:param search_type: 'url' or 'ip'
:type search_type: str
:return: Results
:rtype: str | def __query_safebrowsing(self, search_value, search_type):
"""
The actual query to safebrowsing api
:param search_value: value to search for
:type search_value: str
:param search_type: 'url' or 'ip'
:type search_type: str
:return: Results
:rtype: ... |
Queries robtex reverse pdns-api using an ip as parameter
:return: Dictionary containing results
:rtype: list | def query_rpdns(self):
"""
Queries robtex reverse pdns-api using an ip as parameter
:return: Dictionary containing results
:rtype: list
"""
results = requests.get('https://freeapi.robtex.com/pdns/reverse/{}'.format(self.get_data())).text.split('\r\n')
jsonresults... |
Count the malicious and suspicious sections, check for CVE description | def module_summary(self):
"""Count the malicious and suspicious sections, check for CVE description"""
suspicious = 0
malicious = 0
count = 0
cve = False
taxonomies = []
for section in self.results:
if section['submodule_section_content']['class'] == ... |
Lookup an IP address to check if it is a known tor exit node.
:param ip: The IP address to lookup
:type ip: str
:return: Data relative to the tor node. If `ip`is a tor exit node
it will contain a `node` key with the hash of the node and
a `last_status` key with... | def search_tor_node(self, ip):
"""Lookup an IP address to check if it is a known tor exit node.
:param ip: The IP address to lookup
:type ip: str
:return: Data relative to the tor node. If `ip`is a tor exit node
it will contain a `node` key with the hash of the node and... |
Searches for a host using its ipv4 address
:param ip: ipv4 address as string
:type ip: str
:return: dict | def search_hosts(self, ip):
"""
Searches for a host using its ipv4 address
:param ip: ipv4 address as string
:type ip: str
:return: dict
"""
c = CensysIPv4(api_id=self.__uid, api_secret=self.__api_key)
return c.view(ip) |
Searches for a specific certificate using its hash
:param hash: certificate hash
:type hash: str
:return: dict | def search_certificate(self, hash):
"""
Searches for a specific certificate using its hash
:param hash: certificate hash
:type hash: str
:return: dict
"""
c = CensysCertificates(api_id=self.__uid, api_secret=self.__api_key)
return c.view(hash) |
Searches for a website using the domainname
:param dom: domain
:type dom: str
:return: dict | def search_website(self, dom):
"""
Searches for a website using the domainname
:param dom: domain
:type dom: str
:return: dict
"""
c = CensysWebsites(api_id=self.__uid, api_secret=self.__api_key)
return c.view(dom) |
:param level: info, safe, suspicious or malicious
:param namespace: Name of analyzer
:param predicate: Name of service
:param value: value
:return: dict | def build_taxonomy(self, level, namespace, predicate, value):
"""
:param level: info, safe, suspicious or malicious
:param namespace: Name of analyzer
:param predicate: Name of service
:param value: value
:return: dict
"""
return {
'level':... |
Look for an IP address or an email address in the spammer database.
:param datatype: Which type of data is to be looked up.
Allowed values are 'ip' or 'mail'.
:param data: The value to be looked up through the API.
:type datatype: str
:type data: str
:re... | def get_data(self, datatype, data):
""" Look for an IP address or an email address in the spammer database.
:param datatype: Which type of data is to be looked up.
Allowed values are 'ip' or 'mail'.
:param data: The value to be looked up through the API.
:type d... |
Create a new factory container.
:param faker: A faker generator instance
:type faker: faker.Generator
:param path_to_factories: The path to factories
:type path_to_factories: str
:rtype: Factory | def construct(cls, faker, path_to_factories=None):
"""
Create a new factory container.
:param faker: A faker generator instance
:type faker: faker.Generator
:param path_to_factories: The path to factories
:type path_to_factories: str
:rtype: Factory
"""... |
Define a class with a given set of attributes.
:param klass: The class
:type klass: class
:param name: The short name
:type name: str | def define(self, klass, name="default"):
"""
Define a class with a given set of attributes.
:param klass: The class
:type klass: class
:param name: The short name
:type name: str
"""
def decorate(func):
@wraps(func)
def wrapped(*... |
Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str | def register(self, klass, callback, name="default"):
"""
Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str
"""
... |
Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str | def register_as(self, klass, name, callback):
"""
Register a class with a function.
:param klass: The class
:type klass: class
:param callback: The callable
:type callback: callable
:param name: The short name
:type name: str
"""
return ... |
Create an instance of the given model and type and persist it to the database.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed | def create_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type and persist it to the database.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
... |
Create an instance of the given model and type.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: mixed | def make_as(self, klass, name, **attributes):
"""
Create an instance of the given model and type.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
... |
Get the raw attribute dict for a given named model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
:return: dict | def raw_of(self, klass, name, **attributes):
"""
Get the raw attribute dict for a given named model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param attributes: The instance attributes
:type attributes: dict
... |
Get the raw attribute dict for a given named model.
:param klass: The class
:type klass: class
:param _name: The type
:type _name: str
:param attributes: The instance attributes
:type attributes: dict
:return: dict | def raw(self, klass, _name="default", **attributes):
"""
Get the raw attribute dict for a given named model.
:param klass: The class
:type klass: class
:param _name: The type
:type _name: str
:param attributes: The instance attributes
:type attributes: ... |
Create a builder for the given model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:return: orator.orm.factory_builder.FactoryBuilder | def of(self, klass, name="default"):
"""
Create a builder for the given model.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:return: orator.orm.factory_builder.FactoryBuilder
"""
return FactoryBuilder(
... |
Makes a factory builder with a specified amount.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param amount: The number of models to create
:type amount: int
:return: mixed | def build(self, klass, name="default", amount=None):
"""
Makes a factory builder with a specified amount.
:param klass: The class
:type klass: class
:param name: The type
:type name: str
:param amount: The number of models to create
:type amount: int
... |
Resolve a migration instance from a file.
:param path: The path to factories directory
:type path: str
:param factory_file: The migration file
:type factory_file: str
:rtype: Factory | def _resolve(cls, path, factory_file):
"""
Resolve a migration instance from a file.
:param path: The path to factories directory
:type path: str
:param factory_file: The migration file
:type factory_file: str
:rtype: Factory
"""
variables = {}
... |
Initialize the relation on a set of models.
:type models: list
:type relation: str | def init_relation(self, models, relation):
"""
Initialize the relation on a set of models.
:type models: list
:type relation: str
"""
for model in models:
model.set_relation(
relation, Result(self._related.new_collection(), self, model)
... |
Match the eagerly loaded results to their parents.
:type models: list
:type results: Collection
:type relation: str | def match(self, models, results, relation):
"""
Match the eagerly loaded results to their parents.
:type models: list
:type results: Collection
:type relation: str
"""
return self.match_many(models, results, relation) |
Compile a rename column command.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The connection
:type connection: orator.connections.Connection
:rtype: list | def compile_rename_column(self, blueprint, command, connection):
"""
Compile a rename column command.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The connection
:type co... |
Get a new column instance with the new column name.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param column: The column
:type column: orator.dbal.Column
:param schema: The schema
:type ... | def _get_renamed_diff(self, blueprint, command, column, schema):
"""
Get a new column instance with the new column name.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param column: The column
... |
Set the renamed columns on the table diff.
:rtype: orator.dbal.TableDiff | def _set_renamed_columns(self, table_diff, command, column):
"""
Set the renamed columns on the table diff.
:rtype: orator.dbal.TableDiff
"""
new_column = Column(command.to, column.get_type(), column.to_dict())
table_diff.renamed_columns = {command.from_: new_column}
... |
Get the primary key command it it exists. | def _get_command_by_name(self, blueprint, name):
"""
Get the primary key command it it exists.
"""
commands = self._get_commands_by_name(blueprint, name)
if len(commands):
return commands[0] |
Get all of the commands with a given name. | def _get_commands_by_name(self, blueprint, name):
"""
Get all of the commands with a given name.
"""
return list(filter(lambda value: value.name == name, blueprint.get_commands())) |
Add a prefix to a list of values. | def prefix_list(self, prefix, values):
"""
Add a prefix to a list of values.
"""
return list(map(lambda value: prefix + " " + value, values)) |
Format a value so that it can be used in "default" clauses. | def _get_default_value(self, value):
"""
Format a value so that it can be used in "default" clauses.
"""
if isinstance(value, QueryExpression):
return value
if isinstance(value, bool):
return "'%s'" % int(value)
return "'%s'" % value |
Compile a change column command into a series of SQL statement.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The connection
:type connection: orator.connections.Connection
:rtyp... | def compile_change(self, blueprint, command, connection):
"""
Compile a change column command into a series of SQL statement.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param command: The command
:type command: Fluent
:param connection: The con... |
Get the table diffrence for the given changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff | def _get_changed_diff(self, blueprint, schema):
"""
Get the table diffrence for the given changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:param schema: The schema
:type schema: orator.dbal.SchemaManager
:rtype: orator.dbal.TableDiff
... |
Get a copy of the given table after making the column changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:type table: orator.dbal.table.Table
:rtype: orator.dbal.table.Table | def _get_table_with_column_changes(self, blueprint, table):
"""
Get a copy of the given table after making the column changes.
:param blueprint: The blueprint
:type blueprint: Blueprint
:type table: orator.dbal.table.Table
:rtype: orator.dbal.table.Table
"""
... |
Get the column instance for a column change.
:type table: orator.dbal.table.Table
:rtype: orator.dbal.column.Column | def _get_column_for_change(self, table, fluent):
"""
Get the column instance for a column change.
:type table: orator.dbal.table.Table
:rtype: orator.dbal.column.Column
"""
return table.change_column(
fluent.name, self._get_column_change_options(fluent)
... |
Get the column change options. | def _get_column_change_options(self, fluent):
"""
Get the column change options.
"""
options = {
"name": fluent.name,
"type": self._get_dbal_column_type(fluent.type),
"default": fluent.get("default"),
}
if fluent.type in ["string"]:
... |
Get the dbal column type.
:param type_: The fluent type
:type type_: str
:rtype: str | def _get_dbal_column_type(self, type_):
"""
Get the dbal column type.
:param type_: The fluent type
:type type_: str
:rtype: str
"""
type_ = type_.lower()
if type_ == "big_integer":
type_ = "bigint"
elif type == "small_integer":
... |
Set the keys for a save update query.
:param query: A Builder instance
:type query: orator.orm.Builder
:return: The Builder instance
:rtype: orator.orm.Builder | def _set_keys_for_save_query(self, query):
"""
Set the keys for a save update query.
:param query: A Builder instance
:type query: orator.orm.Builder
:return: The Builder instance
:rtype: orator.orm.Builder
"""
query.where(self.__foreign_key, self.get_at... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.