INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Detects the usage of any deprecated built-in symbols.
Returns:
list of tuple: (state_variable | node, (detecting_signature, original_text, recommended_text)) | def detect_deprecated_references_in_contract(self, contract):
""" Detects the usage of any deprecated built-in symbols.
Returns:
list of tuple: (state_variable | node, (detecting_signature, original_text, recommended_text))"""
results = []
for state_variable in contract.var... |
Detects if an expression makes use of any deprecated standards.
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'deprecated_references'} | def _detect(self):
""" Detects if an expression makes use of any deprecated standards.
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func', 'deprecated_references'}
"""
results = []
for contract in self.contracts:
depr... |
The core high-level code for running Slither static analysis.
Returns:
list(result), int: Result list and number of contracts analyzed | def process(filename, args, detector_classes, printer_classes):
"""
The core high-level code for running Slither static analysis.
Returns:
list(result), int: Result list and number of contracts analyzed
"""
ast = '--ast-compact-json'
if args.legacy_ast:
ast = '--ast-json'
ar... |
NOTE: This contains just a few detectors and printers that we made public. | def get_detectors_and_printers():
"""
NOTE: This contains just a few detectors and printers that we made public.
"""
detectors = [getattr(all_detectors, name) for name in dir(all_detectors)]
detectors = [d for d in detectors if inspect.isclass(d) and issubclass(d, AbstractDetector)]
printers =... |
:param all_detector_classes: A list of all detectors that can be included/excluded.
:param all_printer_classes: A list of all printers that can be included. | def main_impl(all_detector_classes, all_printer_classes):
"""
:param all_detector_classes: A list of all detectors that can be included/excluded.
:param all_printer_classes: A list of all printers that can be included.
"""
args = parse_args(all_detector_classes, all_printer_classes)
# Set color... |
Detect the constant function changing the state
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func','#varsWritten'} | def _detect(self):
""" Detect the constant function changing the state
Recursively visit the calls
Returns:
list: {'vuln', 'filename,'contract','func','#varsWritten'}
"""
results = []
for c in self.contracts:
for f in c.functions:
... |
Compute the number of edges of the CFG
Args:
function (core.declarations.function.Function)
Returns:
int | def compute_number_edges(function):
"""
Compute the number of edges of the CFG
Args:
function (core.declarations.function.Function)
Returns:
int
"""
n = 0
for node in function.nodes:
n += len(node.sons)
return n |
Compute strongly connected components
Based on Kosaraju algo
Implem follows wikipedia algo: https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm#The_algorithm
Args:
function (core.declarations.function.Function)
Returns:
list(list(nodes)) | def compute_strongly_connected_components(function):
"""
Compute strongly connected components
Based on Kosaraju algo
Implem follows wikipedia algo: https://en.wikipedia.org/wiki/Kosaraju%27s_algorithm#The_algorithm
Args:
function (core.declarations.function.Function)
Returns... |
Compute the cyclomatic complexity of a function
Args:
function (core.declarations.function.Function)
Returns:
int | def compute_cyclomatic_complexity(function):
"""
Compute the cyclomatic complexity of a function
Args:
function (core.declarations.function.Function)
Returns:
int
"""
# from https://en.wikipedia.org/wiki/Cyclomatic_complexity
# M = E - N + 2P
# where M is the complexity
... |
_filename is not used
Args:
_filename(string) | def output(self, _filename):
"""
_filename is not used
Args:
_filename(string)
"""
txt = ''
for contract in self.slither.contracts_derived:
txt += '\n{}:\n'.format(contract.name)
table = PrettyTable(['Name', 'Type'])
... |
Return the parameters signature(without the return statetement) | def parameters_signature(self):
'''
Return the parameters signature(without the return statetement)
'''
# Use x.type
# x.name may be empty
params = ",".join([str(x.type) for x in self._params])
return '({})'.format(params) |
List all of the slithir variables (non SSA) | def slithir_variables(self):
'''
List all of the slithir variables (non SSA)
'''
slithir_variables = [f.slithir_variables for f in self.functions + self.modifiers]
slithir_variables = [item for sublist in slithir_variables for item in sublist]
return list(set(slithir_... |
Return the contract's immediate constructor.
If there is no immediate constructor, returns the first constructor
executed, following the c3 linearization
Return None if there is no constructor. | def constructor(self):
'''
Return the contract's immediate constructor.
If there is no immediate constructor, returns the first constructor
executed, following the c3 linearization
Return None if there is no constructor.
'''
cst = self.constructor_... |
list(Contract): Return the list of contracts derived from self | def derived_contracts(self):
'''
list(Contract): Return the list of contracts derived from self
'''
candidates = self.slither.contracts
return [c for c in candidates if self in c.inheritance] |
Return the functions reading the variable | def get_functions_reading_from_variable(self, variable):
'''
Return the functions reading the variable
'''
return [f for f in self.functions if f.is_reading(variable)] |
Return the functions writting the variable | def get_functions_writing_to_variable(self, variable):
'''
Return the functions writting the variable
'''
return [f for f in self.functions if f.is_writing(variable)] |
Return the source mapping where the variable is declared
Args:
var (str): variable name
Returns:
(dict): sourceMapping | def get_source_var_declaration(self, var):
""" Return the source mapping where the variable is declared
Args:
var (str): variable name
Returns:
(dict): sourceMapping
"""
return next((x.source_mapping for x in self.variables if x.name == var)) |
Return the source mapping where the event is declared
Args:
event (str): event name
Returns:
(dict): sourceMapping | def get_source_event_declaration(self, event):
""" Return the source mapping where the event is declared
Args:
event (str): event name
Returns:
(dict): sourceMapping
"""
return next((x.source_mapping for x in self.events if x.name == event)) |
Return a function from a signature
Args:
function_signature (str): signature of the function (without return statement)
Returns:
Function | def get_function_from_signature(self, function_signature):
"""
Return a function from a signature
Args:
function_signature (str): signature of the function (without return statement)
Returns:
Function
"""
return next((f for f in self.functions ... |
Return a modifier from a signature
Args:
modifier_name (str): signature of the modifier
Returns:
Modifier | def get_modifier_from_signature(self, modifier_signature):
"""
Return a modifier from a signature
Args:
modifier_name (str): signature of the modifier
Returns:
Modifier
"""
return next((m for m in self.modifiers if m.full_name == modifier_signa... |
Return a state variable from a name
Args:
varible_name (str): name of the variable
Returns:
StateVariable | def get_state_variable_from_name(self, variable_name):
"""
Return a state variable from a name
Args:
varible_name (str): name of the variable
Returns:
StateVariable
"""
return next((v for v in self.state_variables if v.name == variable_name), N... |
Return a structure from a name
Args:
structure_name (str): name of the structure
Returns:
Structure | def get_structure_from_name(self, structure_name):
"""
Return a structure from a name
Args:
structure_name (str): name of the structure
Returns:
Structure
"""
return next((st for st in self.structures if st.name == structure_name), None) |
Return a structure from a canonical name
Args:
structure_name (str): canonical name of the structure
Returns:
Structure | def get_structure_from_canonical_name(self, structure_name):
"""
Return a structure from a canonical name
Args:
structure_name (str): canonical name of the structure
Returns:
Structure
"""
return next((st for st in self.structures if st.canonic... |
Return an event from a name
Args:
event_name (str): name of the event
Returns:
Event | def get_event_from_name(self, event_name):
"""
Return an event from a name
Args:
event_name (str): name of the event
Returns:
Event
"""
return next((e for e in self.events if e.name == event_name), None) |
Return an enum from a name
Args:
enum_name (str): name of the enum
Returns:
Enum | def get_enum_from_name(self, enum_name):
"""
Return an enum from a name
Args:
enum_name (str): name of the enum
Returns:
Enum
"""
return next((e for e in self.enums if e.name == enum_name), None) |
Return an enum from a canonical name
Args:
enum_name (str): canonical name of the enum
Returns:
Enum | def get_enum_from_canonical_name(self, enum_name):
"""
Return an enum from a canonical name
Args:
enum_name (str): canonical name of the enum
Returns:
Enum
"""
return next((e for e in self.enums if e.canonical_name == enum_name), None) |
Return the list of functions overriden by the function
Args:
(core.Function)
Returns:
list(core.Function) | def get_functions_overridden_by(self, function):
'''
Return the list of functions overriden by the function
Args:
(core.Function)
Returns:
list(core.Function)
'''
candidates = [c.functions_not_inherited for c in self.inheritance]
candi... |
list(Function): List of functions reachable from the contract (include super) | def all_functions_called(self):
'''
list(Function): List of functions reachable from the contract (include super)
'''
all_calls = [f.all_internal_calls() for f in self.functions + self.modifiers] + [self.functions + self.modifiers]
all_calls = [item for sublist in all_calls f... |
list(StateVariable): List all of the state variables written | def all_state_variables_written(self):
'''
list(StateVariable): List all of the state variables written
'''
all_state_variables_written = [f.all_state_variables_written() for f in self.functions + self.modifiers]
all_state_variables_written = [item for sublist in all_state_va... |
list(StateVariable): List all of the state variables read | def all_state_variables_read(self):
'''
list(StateVariable): List all of the state variables read
'''
all_state_variables_read = [f.all_state_variables_read() for f in self.functions + self.modifiers]
all_state_variables_read = [item for sublist in all_state_variables_read fo... |
Return the function summary
Returns:
(str, list, list, list, list): (name, inheritance, variables, fuction summaries, modifier summaries) | def get_summary(self):
""" Return the function summary
Returns:
(str, list, list, list, list): (name, inheritance, variables, fuction summaries, modifier summaries)
"""
func_summaries = [f.get_summary() for f in self.functions]
modif_summaries = [f.get_summary() for ... |
Check if the contract is an erc20 token
Note: it does not check for correct return values
Returns:
bool | def is_erc20(self):
"""
Check if the contract is an erc20 token
Note: it does not check for correct return values
Returns:
bool
"""
full_names = [f.full_name for f in self.functions]
return 'transfer(address,uint256)' in full_names and\
... |
Compute line(s) numbers and starting/ending columns
from a start/end offset. All numbers start from 1.
Not done in an efficient way | def _compute_line(source_code, start, length):
"""
Compute line(s) numbers and starting/ending columns
from a start/end offset. All numbers start from 1.
Not done in an efficient way
"""
total_length = len(source_code)
source_code = source_code.splitl... |
Convert a text offset to a real offset
see https://solidity.readthedocs.io/en/develop/miscellaneous.html#source-mappings
Returns:
(dict): {'start':0, 'length':0, 'filename': 'file.sol'} | def _convert_source_mapping(offset, slither):
'''
Convert a text offset to a real offset
see https://solidity.readthedocs.io/en/develop/miscellaneous.html#source-mappings
Returns:
(dict): {'start':0, 'length':0, 'filename': 'file.sol'}
'''
sourceUnits = slithe... |
Return a list of potential signature
It is a list, as Constant variables can be converted to int256
Args:
ir (slithIR.operation)
Returns:
list(str) | def get_sig(ir, name):
'''
Return a list of potential signature
It is a list, as Constant variables can be converted to int256
Args:
ir (slithIR.operation)
Returns:
list(str)
'''
sig = '{}({})'
# list of list of arguments
argss = convert_arguments(ir.argument... |
Integrate value and gas temporary arguments to call instruction | def integrate_value_gas(result):
'''
Integrate value and gas temporary arguments to call instruction
'''
was_changed = True
calls = []
while was_changed:
# We loop until we do not find any call to value or gas
was_changed = False
# Find all the assignments
... |
Propagate the types variables and convert tmp call to real call operation | def propagate_type_and_convert_call(result, node):
'''
Propagate the types variables and convert tmp call to real call operation
'''
calls_value = {}
calls_gas = {}
call_data = []
idx = 0
# use of while len() as result can be modified during the iteration
while idx < len(result... |
Convert to a transfer/send/or low level call
The funciton assume to receive a correct IR
The checks must be done by the caller
Additionally convert abi... to solidityfunction | def convert_to_low_level(ir):
"""
Convert to a transfer/send/or low level call
The funciton assume to receive a correct IR
The checks must be done by the caller
Additionally convert abi... to solidityfunction
"""
if ir.function_name == 'transfer':
assert len(ir.argum... |
Convert a call to a PUSH operaiton
The funciton assume to receive a correct IR
The checks must be done by the caller
May necessitate to create an intermediate operation (InitArray)
Necessitate to return the lenght (see push documentation)
As a result, the function return may return a list | def convert_to_push(ir, node):
"""
Convert a call to a PUSH operaiton
The funciton assume to receive a correct IR
The checks must be done by the caller
May necessitate to create an intermediate operation (InitArray)
Necessitate to return the lenght (see push documentation)
As a result, the... |
Convert a type to a str
If the instance is a Contract, return 'address' instead | def get_type(t):
"""
Convert a type to a str
If the instance is a Contract, return 'address' instead
"""
if isinstance(t, UserDefinedType):
if isinstance(t.type, Contract):
return 'address'
return str(t) |
Make lvalue of each Index, Member operation
points to the left variable | def find_references_origin(irs):
"""
Make lvalue of each Index, Member operation
points to the left variable
"""
for ir in irs:
if isinstance(ir, (Index, Member)):
ir.lvalue.points_to = ir.variable_left |
Apply a set of heuristic to improve slithIR | def apply_ir_heuristics(irs, node):
"""
Apply a set of heuristic to improve slithIR
"""
irs = integrate_value_gas(irs)
irs = propagate_type_and_convert_call(irs, node)
irs = remove_unused(irs)
find_references_origin(irs)
return irs |
Variable Location
Can be storage/memory or default | def _analyze_variable_attributes(self, attributes):
''''
Variable Location
Can be storage/memory or default
'''
if 'storageLocation' in attributes:
location = attributes['storageLocation']
self._location = location
else:
if 'mem... |
Sets the appropriate flags to enable virtual terminal sequences in a Windows command prompt.
Reference: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences | def enable_windows_virtual_terminal_sequences():
"""
Sets the appropriate flags to enable virtual terminal sequences in a Windows command prompt.
Reference: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
"""
try:
from ctypes import windll, byref
... |
Sets the enabled state of output colorization.
:param enabled: Boolean indicating whether output should be colorized.
:return: None | def set_colorization_enabled(enabled):
"""
Sets the enabled state of output colorization.
:param enabled: Boolean indicating whether output should be colorized.
:return: None
"""
# If color is supposed to be enabled and this is windows, we have to enable console virtual terminal sequences:
i... |
str: func_name(type1,type2)
Return the function signature without the return values | def full_name(self):
"""
str: func_name(type1,type2)
Return the function signature without the return values
"""
name, parameters, _ = self.signature
return name+'('+','.join(parameters)+')' |
Return the list of return type
If no return, return None | def return_type(self):
"""
Return the list of return type
If no return, return None
"""
returns = self.returns
if returns:
return [r.type for r in returns]
return None |
Return all local variables (dont include paramters and return values) | def local_variables(self):
"""
Return all local variables (dont include paramters and return values)
"""
return list(set(self.variables) - set(self.returns) - set(self.parameters)) |
list(Expression): List of the expressions | def expressions(self):
"""
list(Expression): List of the expressions
"""
if self._expressions is None:
expressions = [n.expression for n in self.nodes]
expressions = [e for e in expressions if e]
self._expressions = expressions
return self.... |
list(Return Values): List of the return values | def return_values(self):
"""
list(Return Values): List of the return values
"""
from slither.core.cfg.node import NodeType
from slither.slithir.operations import Return
from slither.slithir.variables import Constant
if self._return_values is None:
... |
list(Return Values in SSA form): List of the return values in ssa form | def return_values_ssa(self):
"""
list(Return Values in SSA form): List of the return values in ssa form
"""
from slither.core.cfg.node import NodeType
from slither.slithir.operations import Return
from slither.slithir.variables import Constant
if self._return... |
list(Operation): List of the slithir operations | def slithir_operations(self):
"""
list(Operation): List of the slithir operations
"""
if self._slithir_operations is None:
operations = [n.irs for n in self.nodes]
operations = [item for sublist in operations for item in sublist if item]
self._slit... |
(str, list(str), list(str)): Function signature as
(name, list parameters type, list return values type) | def signature(self):
"""
(str, list(str), list(str)): Function signature as
(name, list parameters type, list return values type)
"""
return self.name, [str(x.type) for x in self.parameters], [str(x.type) for x in self.returns] |
str: func_name(type1,type2) returns (type3)
Return the function signature as a str (contains the return values) | def signature_str(self):
"""
str: func_name(type1,type2) returns (type3)
Return the function signature as a str (contains the return values)
"""
name, parameters, returnVars = self.signature
return name+'('+','.join(parameters)+') returns('+','.join(returnVars)+')... |
Return the list of functions shadowed
Returns:
list(core.Function) | def functions_shadowed(self):
'''
Return the list of functions shadowed
Returns:
list(core.Function)
'''
candidates = [c.functions_not_inherited for c in self.contract.inheritance]
candidates = [candidate for sublist in candidates for candidate in sublist... |
recursive version of variables_read | def all_state_variables_read(self):
""" recursive version of variables_read
"""
if self._all_state_variables_read is None:
self._all_state_variables_read = self._explore_functions(
lambda x: x.state_variables_read)
return self._all_state_variables_read |
recursive version of solidity_read | def all_solidity_variables_read(self):
""" recursive version of solidity_read
"""
if self._all_solidity_variables_read is None:
self._all_solidity_variables_read = self._explore_functions(
lambda x: x.solidity_variables_read)
return self._all_solidity_variable... |
recursive version of variables_read | def all_expressions(self):
""" recursive version of variables_read
"""
if self._all_expressions is None:
self._all_expressions = self._explore_functions(lambda x: x.expressions)
return self._all_expressions |
recursive version of variables_written | def all_state_variables_written(self):
""" recursive version of variables_written
"""
if self._all_state_variables_written is None:
self._all_state_variables_written = self._explore_functions(
lambda x: x.state_variables_written)
return self._all_state_variabl... |
recursive version of internal_calls | def all_internal_calls(self):
""" recursive version of internal_calls
"""
if self._all_internals_calls is None:
self._all_internals_calls = self._explore_functions(lambda x: x.internal_calls)
return self._all_internals_calls |
recursive version of low_level calls | def all_low_level_calls(self):
""" recursive version of low_level calls
"""
if self._all_low_level_calls is None:
self._all_low_level_calls = self._explore_functions(lambda x: x.low_level_calls)
return self._all_low_level_calls |
recursive version of high_level calls | def all_high_level_calls(self):
""" recursive version of high_level calls
"""
if self._all_high_level_calls is None:
self._all_high_level_calls = self._explore_functions(lambda x: x.high_level_calls)
return self._all_high_level_calls |
recursive version of library calls | def all_library_calls(self):
""" recursive version of library calls
"""
if self._all_library_calls is None:
self._all_library_calls = self._explore_functions(lambda x: x.library_calls)
return self._all_library_calls |
Return the state variable used in a condition
Over approximate and also return index access
It won't work if the variable is assigned to a temp variable | def all_conditional_state_variables_read(self, include_loop=True):
"""
Return the state variable used in a condition
Over approximate and also return index access
It won't work if the variable is assigned to a temp variable
"""
if include_loop:
if... |
Return the Soldiity variables directly used in a condtion
Use of the IR to filter index access
Assumption: the solidity vars are used directly in the conditional node
It won't work if the variable is assigned to a temp variable | def all_conditional_solidity_variables_read(self, include_loop=True):
"""
Return the Soldiity variables directly used in a condtion
Use of the IR to filter index access
Assumption: the solidity vars are used directly in the conditional node
It won't work if the v... |
Return the Soldiity variables directly used in a call
Use of the IR to filter index access
Used to catch check(msg.sender) | def all_solidity_variables_used_as_args(self):
"""
Return the Soldiity variables directly used in a call
Use of the IR to filter index access
Used to catch check(msg.sender)
"""
if self._all_solidity_variables_used_as_args is None:
self._all_solid... |
Apply a visitor to all the function expressions
Args:
Visitor: slither.visitors
Returns
list(): results of the visit | def apply_visitor(self, Visitor):
"""
Apply a visitor to all the function expressions
Args:
Visitor: slither.visitors
Returns
list(): results of the visit
"""
expressions = self.expressions
v = [Visitor(e).result() for e in expressions]... |
Return a local variable from a name
Args:
varible_name (str): name of the variable
Returns:
LocalVariable | def get_local_variable_from_name(self, variable_name):
"""
Return a local variable from a name
Args:
varible_name (str): name of the variable
Returns:
LocalVariable
"""
return next((v for v in self.variables if v.name == variable_name), None) |
Export the function to a dot file
Args:
filename (str) | def cfg_to_dot(self, filename):
"""
Export the function to a dot file
Args:
filename (str)
"""
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for node in self.nodes:
f.write('{}[label="{}"];\n'.format(... |
Export the function to a dot file
Args:
filename (str) | def slithir_cfg_to_dot(self, filename):
"""
Export the function to a dot file
Args:
filename (str)
"""
from slither.core.cfg.node import NodeType
with open(filename, 'w', encoding='utf8') as f:
f.write('digraph{\n')
for node in self... |
Export the dominator tree of the function to a dot file
Args:
filename (str) | def dominator_tree_to_dot(self, filename):
"""
Export the dominator tree of the function to a dot file
Args:
filename (str)
"""
def description(node):
desc ='{}\n'.format(node)
desc += 'id: {}'.format(node.node_id)
if node.domin... |
Check if the function reads the variable in a IF node
Args:
variable (Variable):
Returns:
bool: True if the variable is read | def is_reading_in_conditional_node(self, variable):
"""
Check if the function reads the variable in a IF node
Args:
variable (Variable):
Returns:
bool: True if the variable is read
"""
variables_read = [n.variables_read for n in self.nodes if n... |
Check if the function reads the variable in an require or assert
Args:
variable (Variable):
Returns:
bool: True if the variable is read | def is_reading_in_require_or_assert(self, variable):
"""
Check if the function reads the variable in an require or assert
Args:
variable (Variable):
Returns:
bool: True if the variable is read
"""
variables_read = [n.variables_read for n in sel... |
Return the function summary
Returns:
(str, str, str, list(str), list(str), listr(str), list(str), list(str);
contract_name, name, visibility, modifiers, vars read, vars written, internal_calls, external_calls_as_expressions | def get_summary(self):
"""
Return the function summary
Returns:
(str, str, str, list(str), list(str), listr(str), list(str), list(str);
contract_name, name, visibility, modifiers, vars read, vars written, internal_calls, external_calls_as_expressions
"""
... |
Determine if the function is protected using a check on msg.sender
Only detects if msg.sender is directly used in a condition
For example, it wont work for:
address a = msg.sender
require(a == owner)
Returns
(bool) | def is_protected(self):
"""
Determine if the function is protected using a check on msg.sender
Only detects if msg.sender is directly used in a condition
For example, it wont work for:
address a = msg.sender
require(a == owner)
Returns... |
Compute variables read/written/... | def _analyze_read_write(self):
""" Compute variables read/written/...
"""
write_var = [x.variables_written_as_expression for x in self.nodes]
write_var = [x for x in write_var if x]
write_var = [item for sublist in write_var for item in sublist]
write_var = list(set(writ... |
Authenticate based on username and token which is base64-encoded | def auth_string(self):
'''
Authenticate based on username and token which is base64-encoded
'''
username_token = '{username}:{token}'.format(username=self.username, token=self.token)
b64encoded_string = b64encode(username_token)
auth_string = 'Token {b64}'.format(b64=b64... |
Find related objects through SoltraEdge API | def api_related(self, query):
'''
Find related objects through SoltraEdge API
'''
url = "{0}/{1}/related/?format=json".format(self.base_url, query)
response = requests.get(url, headers=self.headers, verify=self.verify_ssl)
if response.status_code == 200:
ret... |
Classifier between Cortex and Soltra.
Soltra uses name-TLP, and Cortex "value-TLP" | def tlp_classifiers(self, name_tlp, val_tlp):
'''
Classifier between Cortex and Soltra.
Soltra uses name-TLP, and Cortex "value-TLP"
'''
classifier = {
"WHITE": 0,
"GREEN": 1,
"AMBER": 2,
"RED": 3
}
valid = True
... |
Pop the object element if the object contains an higher TLP then allowed. | def pop_object(self, element):
'''
Pop the object element if the object contains an higher TLP then allowed.
'''
redacted_text = "Redacted. Object contained TLP value higher than allowed."
element['id'] = ''
element['url'] = ''
element['type'] = ''
eleme... |
Gets a string representation of the requested filename.
Checks for both ASCII and Unicode representations and returns
a value if possible. If there are both ASCII and Unicode
versions, then the parameter /prefer/ specifies which will be
returned. | def _getStringStream(self, filename, prefer='unicode'):
"""Gets a string representation of the requested filename.
Checks for both ASCII and Unicode representations and returns
a value if possible. If there are both ASCII and Unicode
versions, then the parameter /prefer/ specifies which... |
Using the shell script to query pdns.cert.at is a hack, but python raises an error every time using subprocess
functions to call whois. So this hack is avoiding calling whois directly. Ugly, but works.
:param domain: The domain pdns is queried with.
:type domain: str
:param limit: Maximum number of res... | def __query(domain, limit=100):
"""Using the shell script to query pdns.cert.at is a hack, but python raises an error every time using subprocess
functions to call whois. So this hack is avoiding calling whois directly. Ugly, but works.
:param domain: The domain pdns is queried with.
:type domain: str
... |
Processes the result from __query to get valid json from every entry.
:param results: Results from __query
:type results: str
:returns: python list of dictionaries containing the relevant results.
:rtype: list | def __process_results(results):
"""Processes the result from __query to get valid json from every entry.
:param results: Results from __query
:type results: str
:returns: python list of dictionaries containing the relevant results.
:rtype: list
"""
if 'no match' in results and 'returning 0 ... |
Analyze a given sample for malicious vba. | def analyze_vba(self, path):
"""Analyze a given sample for malicious vba."""
try:
vba_parser = VBA_Parser_CLI(path, relaxed=True)
vbaparser_result = vba_parser.process_file_json(show_decoded_strings=True,
display_code=... |
Return the record for the ip_address in the MaxMind DB
Arguments:
ip_address -- an IP address in the standard string notation | def get(self, ip_address):
"""Return the record for the ip_address in the MaxMind DB
Arguments:
ip_address -- an IP address in the standard string notation
"""
address = ipaddress.ip_address(ip_address)
if address.version == 6 and self._metadata.ip_version == 4:
... |
Search crt.sh for the given domain.
domain -- Domain to search for
wildcard -- Whether or not to prepend a wildcard to the domain
(default: True)
Return a list of a certificate dict:
{
"issuer_ca_id": 16418,
"issuer_name": "C=US, O=Let's Enc... | def search(self, domain, wildcard=True):
"""
Search crt.sh for the given domain.
domain -- Domain to search for
wildcard -- Whether or not to prepend a wildcard to the domain
(default: True)
Return a list of a certificate dict:
{
"issuer... |
Just for better readability, all __misp*type methods return just a list of misp data types
:returns: MISP hash data types
:rtype: list | def __misphashtypes():
"""Just for better readability, all __misp*type methods return just a list of misp data types
:returns: MISP hash data types
:rtype: list
"""
hashtypes = ['md5', 'sha1', 'sha256', 'ssdeep', 'sha224', 'sha384', 'sha512', 'sha512/224', 'sha512/256',
... |
Strip relatedevent sub content of event for lighter output.
:param related_events:
:return: | def __clean_relatedevent(self, related_events):
"""
Strip relatedevent sub content of event for lighter output.
:param related_events:
:return:
"""
response = []
for event in related_events:
ev = {
'info': event['Event']['in... |
Strip event data for lighter output. Analyer report only contains useful data.
:param event: misp event
:return: misp event | def __clean_event(self, misp_event):
"""
Strip event data for lighter output. Analyer report only contains useful data.
:param event: misp event
:return: misp event
"""
filters = ['Attribute',
'ShadowAttribute',
'Org',
... |
:param misp_response:
:return: | def __clean(self, misp_response):
"""
:param misp_response:
:return:
"""
response = []
for event in misp_response.get('response', []):
response.append(self.__clean_event(event['Event']))
return response |
Search method call wrapper.
:param value: value to search for.
:type value: str
:param type_attribute: attribute types to search for.
:type type_attribute: [list, none] | def __search(self, value, type_attribute):
"""Search method call wrapper.
:param value: value to search for.
:type value: str
:param type_attribute: attribute types to search for.
:type type_attribute: [list, none]
"""
results = []
if not value:
... |
Search for URLs
:type searchterm: str
:rtype: list | def search_url(self, searchterm):
"""Search for URLs
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispurltypes(), value=searchterm) |
Search for hashes
:type searchterm: str
:rtype: list | def search_hash(self, searchterm):
"""Search for hashes
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__misphashtypes(), value=searchterm) |
Search for domains
:type searchterm: str
:rtype: list | def search_domain(self, searchterm):
"""Search for domains
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispdomaintypes(), value=searchterm) |
Search for emails
:type searchterm: str
:rtype: list | def search_mail(self, searchterm):
"""Search for emails
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispmailtypes(), value=searchterm) |
Search for ips
:type searchterm: str
:rtype: list | def search_ip(self, searchterm):
"""Search for ips
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispiptypes(), value=searchterm) |
Search for registry keys and values
:type searchterm: str
:rtype: list | def search_registry(self, searchterm):
"""Search for registry keys and values
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispregistrytypes(), value=searchterm) |
Search for filenames
:type searchterm: str
:rtype: list | def search_filename(self, searchterm):
"""Search for filenames
:type searchterm: str
:rtype: list
"""
return self.__search(type_attribute=self.__mispfilenametypes(), value=searchterm) |
Lookup an artifact to check if it is a known tor exit node.
:param data_type: The artifact type. Must be one of 'ip', 'fqdn'
or 'domain'
:param data: The artifact to lookup
:type data_type: str
:type data: str
:return: Data relative to the tor node. If ... | def search_tor_node(self, data_type, data):
"""Lookup an artifact to check if it is a known tor exit node.
:param data_type: The artifact type. Must be one of 'ip', 'fqdn'
or 'domain'
:param data: The artifact to lookup
:type data_type: str
:type data: ... |
Checks a given file against all available yara rules
:param file: Path to file
:type file:str
:returns: Python dictionary containing the results
: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 dictionary containing the results
:rtype: list
"""
result = []
for rule in self.ruleset:
matches ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.