desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Overrides the save method to update the
the last_update field.'
| def save(self, *args, **kwargs):
| self.last_update = timezone.now()
super(CoreEntry, self).save(*args, **kwargs)
|
'Builds and returns the entry\'s URL based on
the slug and the creation date.'
| @models.permalink
def get_absolute_url(self):
| publication_date = self.publication_date
if timezone.is_aware(publication_date):
publication_date = timezone.localtime(publication_date)
return ('zinnia:entry_detail', (), {'year': publication_date.strftime('%Y'), 'month': publication_date.strftime('%m'), 'day': publication_date.strftime('%d'), 'slu... |
'Returns the "content" field formatted in HTML.'
| @property
def html_content(self):
| return html_format(self.content)
|
'Returns a preview of the "content" field or
the "lead" field if defined, formatted in HTML.'
| @property
def html_preview(self):
| return HTMLPreview(self.html_content, getattr(self, 'html_lead', ''))
|
'Counts the number of words used in the content.'
| @property
def word_count(self):
| return len(strip_tags(self.html_content).split())
|
'Returns a queryset of the published discussions.'
| @property
def discussions(self):
| return comments.get_model().objects.for_model(self).filter(is_public=True, is_removed=False)
|
'Returns a queryset of the published comments.'
| @property
def comments(self):
| return self.discussions.filter((Q(flags=None) | Q(flags__flag=CommentFlag.MODERATOR_APPROVAL)))
|
'Returns a queryset of the published pingbacks.'
| @property
def pingbacks(self):
| return self.discussions.filter(flags__flag=PINGBACK)
|
'Return a queryset of the published trackbacks.'
| @property
def trackbacks(self):
| return self.discussions.filter(flags__flag=TRACKBACK)
|
'Checks if a type of discussion is still open
are a certain number of days.'
| def discussion_is_still_open(self, discussion_type, auto_close_after):
| discussion_enabled = getattr(self, discussion_type)
if (discussion_enabled and isinstance(auto_close_after, int) and (auto_close_after >= 0)):
return ((timezone.now() - (self.start_publication or self.publication_date)).days < auto_close_after)
return discussion_enabled
|
'Checks if the comments are open with the
AUTO_CLOSE_COMMENTS_AFTER setting.'
| @property
def comments_are_open(self):
| return self.discussion_is_still_open('comment_enabled', AUTO_CLOSE_COMMENTS_AFTER)
|
'Checks if the pingbacks are open with the
AUTO_CLOSE_PINGBACKS_AFTER setting.'
| @property
def pingbacks_are_open(self):
| return self.discussion_is_still_open('pingback_enabled', AUTO_CLOSE_PINGBACKS_AFTER)
|
'Checks if the trackbacks are open with the
AUTO_CLOSE_TRACKBACKS_AFTER setting.'
| @property
def trackbacks_are_open(self):
| return self.discussion_is_still_open('trackback_enabled', AUTO_CLOSE_TRACKBACKS_AFTER)
|
'Returns only related entries published.'
| @property
def related_published(self):
| return entries_published(self.related)
|
'Returns the "lead" field formatted in HTML.'
| @property
def html_lead(self):
| return html_format(self.lead)
|
'Overrides the save method to create an excerpt
from the content field if void.'
| def save(self, *args, **kwargs):
| if ((not self.excerpt) and (self.status == PUBLISHED)):
self.excerpt = Truncator(strip_tags(getattr(self, 'content', ''))).words(50)
super(ExcerptEntry, self).save(*args, **kwargs)
|
'Compute the upload path for the image field.'
| def image_upload_to(self, filename):
| now = timezone.now()
(filename, extension) = os.path.splitext(filename)
return os.path.join(UPLOAD_TO, now.strftime('%Y'), now.strftime('%m'), now.strftime('%d'), ('%s%s' % (slugify(filename), extension)))
|
'Return iterable list of tags.'
| @property
def tags_list(self):
| return parse_tag_input(self.tags)
|
'Database stores every info.
version int
#if value in file is unequal to value defined in this class.
#An database update will be applied.
user dict:
username str
key str
collections list:
collection_info(dict):
collection_name str
collection_type str
collection_describe str
collection_songs list:
song_id(int)
songs di... | def __init__(self):
| if hasattr(self, u'_init'):
return
self._init = True
self.version = 4
self.database = {u'version': 4, u'user': {u'username': u'', u'password': u'', u'user_id': u'', u'nickname': u''}, u'collections': [[]], u'songs': {}, u'player_info': {u'player_list': [], u'player_list_type': u'', u'player_list... |
'Runs the given args in subprocess.Popen, and then calls the function
onExit when the subprocess completes.
onExit is a callable object, and popenArgs is a lists/tuple of args
that would give to subprocess.Popen.'
| def popen_recall(self, onExit, popenArgs):
| def runInThread(onExit, arg):
para = [u'mpg123', u'-R']
para[1:1] = self.mpg123_parameters
try:
self.popen_handler = subprocess.Popen(para, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
self.popen_handler.stdin.write((('V ' + str(self.info[... |
'This class isn\'t actually ran as a thread, only the start_monitoring
method is. It can spawn/stop a process, wait for it to exit and report on
the exit status/code.'
| def __init__(self, start_command):
| self.start_command = start_command
self.tokens = start_command.split(' ')
self.cmd_args = []
self.pid = None
self.exit_status = None
self.alive = False
|
'self.exit_status = os.waitpid(self.pid, os.WNOHANG | os.WUNTRACED)
while self.exit_status == (0, 0):
self.exit_status = os.waitpid(self.pid, os.WNOHANG | os.WUNTRACED)'
| def start_monitoring(self):
| self.exit_status = os.waitpid(self.pid, 0)
self.exit_status = self.exit_status[1]
self.alive = False
|
'@type host: String
@param host: Hostname or IP address
@type port: Integer
@param port: Port to bind server to
@type crash_bin: String
@param crash_bin: Where to save monitored process crashes for analysis'
| def __init__(self, host, port, crash_bin, log_level=1):
| pedrpc.server.__init__(self, host, port)
self.crash_bin = crash_bin
self.log_level = log_level
self.dbg = None
self.log('Process Monitor PED-RPC server initialized:')
self.log(('Listening on %s:%s' % (host, port)))
self.log('awaiting requests...')
|
'Returns True. Useful for PED-RPC clients who want to see if the PED-RPC connection is still alive.'
| def alive(self):
| return True
|
'If the supplied message falls under the current log level, print the specified message to screen.
@type msg: String
@param msg: Message to log'
| def log(self, msg='', level=1):
| if (self.log_level >= level):
print ('[%s] %s' % (time.strftime('%I:%M.%S'), msg))
|
'This routine is called after the fuzzer transmits a test case and returns the status of the target.
@rtype: Boolean
@return: Return True if the target is still active, False otherwise.'
| def post_send(self):
| if (not self.dbg.isAlive()):
exit_status = self.dbg.get_exit_status()
rec_file = open(self.crash_bin, 'a')
if os.WCOREDUMP(exit_status):
reason = 'Segmentation fault'
elif os.WIFSTOPPED(exit_status):
reason = ('Stopped with signal ' + str(os.WTERMS... |
'This routine is called before the fuzzer transmits a test case and ensure the debugger thread is operational.
(In this implementation do nothing for now)
@type test_number: Integer
@param test_number: Test number to retrieve PCAP for.'
| def pre_send(self, test_number):
| if (self.dbg == None):
self.start_target()
self.log(('pre_send(%d)' % test_number), 10)
self.test_number = test_number
|
'Start up the target process by issuing the commands in self.start_commands.'
| def start_target(self):
| self.log('starting target process')
self.dbg = debugger_thread(self.start_commands[0])
self.dbg.spawn_target()
threading.Thread(target=self.dbg.start_monitoring).start()
self.log('done. target up and running, giving it 5 seconds to settle in.')
time.sleep(5... |
'Kill the current debugger thread and stop the target process by issuing the commands in self.stop_commands.'
| def stop_target(self):
| time.sleep(1)
self.log('stopping target process')
for command in self.stop_commands:
if (command == 'TERMINATE_PID'):
self.dbg.stop_target()
else:
os.system(command)
|
'We expect start_commands to be a list with one element for example
[\'/usr/bin/program arg1 arg2 arg3\']'
| def set_start_commands(self, start_commands):
| if (len(start_commands) > 1):
self.log('This process monitor does not accept > 1 start command')
return
self.log(('updating start commands to: %s' % start_commands))
self.start_commands = start_commands
|
'Return the last recorded crash synopsis.
@rtype: String
@return: Synopsis of last recorded crash.'
| def get_crash_synopsis(self):
| return self.last_synopsis
|
'@type host: str
@param host: Hostname or IP address to bind server to
@type port: int
@param port: Port to bind server to
@type monitor_device: str
@param monitor_device: Name of device to capture packets on
@type bpf_filter: str
@param bpf_filter: BPF filter to appl... | def __init__(self, host, port, monitor_device, bpf_filter='', path='./', level=1):
| pedrpc.server.__init__(self, host, port)
self.device = monitor_device
self.filter = bpf_filter
self.log_path = path
self.log_level = level
self.pcap = None
self.pcap_thread = None
if (not os.access(self.log_path, os.X_OK)):
self.log(('invalid log path: %s' % self.log_pat... |
'Kill the PCAP thread.'
| def __stop(self):
| if self.pcap_thread:
self.log('stopping active packet capture thread.', 10)
self.pcap_thread.active = False
self.pcap_thread = None
|
'Returns True. Useful for PED-RPC clients who want to see if the PED-RPC connection is still alive.'
| def alive(self):
| return True
|
'This routine is called after the fuzzer transmits a test case and returns the number of bytes captured by the
PCAP thread.
@rtype: Integer
@return: Number of bytes captured in PCAP thread.'
| def post_send(self):
| data_bytes = self.pcap_thread.data_bytes
self.__stop()
self.log(('stopped PCAP thread, snagged %d bytes of data' % data_bytes))
return data_bytes
|
'This routine is called before the fuzzer transmits a test case and spin off a packet capture thread.'
| def pre_send(self, test_number):
| self.log(('initializing capture for test case #%d' % test_number))
self.pcap = pcapy.open_live(self.device, (-1), 1, 100)
self.pcap.setfilter(self.filter)
pcap_log_path = ('%s/%d.pcap' % (self.log_path, test_number))
self.pcap_thread = PcapThread(self, self.pcap, pcap_log_path)
se... |
'If the supplied message falls under the current log level, print the specified message to screen.
@type msg: str
@param msg: Message to log'
| def log(self, msg='', level=1):
| if (self.log_level >= level):
print ('[%s] %s' % (time.strftime('%I:%M.%S'), msg))
|
'Return the raw binary contents of the PCAP saved for the specified test case number.
@type test_number: int
@param test_number: Test number to retrieve PCAP for.'
| def retrieve(self, test_number):
| self.log(('retrieving PCAP for test case #%d' % test_number))
pcap_log_path = ('%s/%d.pcap' % (self.log_path, test_number))
fh = open(pcap_log_path, 'rb')
data = fh.read()
fh.close()
return data
|
'Instantiate a new PyDbg instance and register user and access violation callbacks.'
| def __init__(self, process_monitor, process, pid_to_ignore=None):
| threading.Thread.__init__(self)
self.process_monitor = process_monitor
self.proc_name = process
self.ignore_pid = pid_to_ignore
self.access_violation = False
self.active = True
self.dbg = pydbg.pydbg()
self.pid = None
self.setName(('%d' % time.time()))
self.process_monitor.log(('... |
'Ignore first chance exceptions. Record all unhandled exceptions to the process monitor crash bin and kill
the target process.'
| def dbg_callback_access_violation(self, dbg):
| if dbg.dbg.u.Exception.dwFirstChance:
return pydbg.defines.DBG_EXCEPTION_NOT_HANDLED
self.access_violation = True
self.process_monitor.crash_bin.record_crash(dbg, self.process_monitor.test_number)
self.process_monitor.last_synopsis = self.process_monitor.crash_bin.crash_synopsis()
first_line... |
'The user callback is run roughly every 100 milliseconds (WaitForDebugEvent() timeout from pydbg_core.py). Simply
check if the active flag was lowered and if so detach from the target process. The thread should then exit.'
| def dbg_callback_user(self, dbg):
| if (not self.active):
self.process_monitor.log(('debugger thread-%s detaching' % self.getName()), 5)
dbg.detach()
return pydbg.defines.DBG_CONTINUE
|
'Main thread routine, called on thread.start(). Thread exits when this routine returns.'
| def run(self):
| self.process_monitor.log(('debugger thread-%s looking for process name: %s' % (self.getName(), self.proc_name)))
try:
self.watch()
self.dbg.attach(self.pid)
self.dbg.run()
self.process_monitor.log(('debugger thread-%s exiting' % self.getName()))
except... |
'Continuously loop, watching for the target process. This routine "blocks" until the target process is found.
Update self.pid when found and return.'
| def watch(self):
| while (not self.pid):
for (pid, name) in self.dbg.enumerate_processes():
if (pid == self.ignore_pid):
continue
if (name.lower() == self.proc_name.lower()):
self.pid = pid
break
self.process_monitor.log(('debugger thread-%s fou... |
'@type host: str
@param host: Hostname or IP address
@type port: int
@param port: Port to bind server to
@type crash_filename: str
@param crash_filename: Name of file to (un)serialize crash bin to/from
@type proc: str
@param proc: (Optional, def=None) Proc... | def __init__(self, host, port, crash_filename, proc=None, pid_to_ignore=None, level=1):
| pedrpc.server.__init__(self, host, port)
self.crash_filename = os.path.abspath(crash_filename)
self.proc_name = proc
self.ignore_pid = pid_to_ignore
self.log_level = level
self.stop_commands = []
self.start_commands = []
self.test_number = None
self.debugger_thread = None
self.cr... |
'Returns True. Useful for PED-RPC clients who want to see if the PED-RPC connection is still alive.'
| def alive(self):
| return True
|
'Return the last recorded crash synopsis.
@rtype: String
@return: Synopsis of last recorded crash.'
| def get_crash_synopsis(self):
| return self.last_synopsis
|
'Return the crash bin keys, ie: the unique list of exception addresses.
@rtype: List
@return: List of crash bin exception addresses (keys).'
| def get_bin_keys(self):
| return self.crash_bin.bins.keys()
|
'Return the crash entries from the specified bin or False if the bin key is invalid.
@type binary: Integer (DWORD)
@param binary: Crash bin key (ie: exception address)
@rtype: list
@return: List of crashes in specified bin.'
| def get_bin(self, binary):
| if (binary not in self.crash_bin.bins):
return False
return self.crash_bin.bins[binary]
|
'If the supplied message falls under the current log level, print the specified message to screen.
@type msg: str
@param msg: Message to log'
| def log(self, msg='', level=1):
| if (self.log_level >= level):
print ('[%s] %s' % (time.strftime('%I:%M.%S'), msg))
|
'This routine is called after the fuzzer transmits a test case and returns the status of the target.
@rtype: bool
@return: Return True if the target is still active, False otherwise.'
| def post_send(self):
| crashes = 0
av = self.debugger_thread.access_violation
if av:
while self.debugger_thread.isAlive():
time.sleep(1)
self.debugger_thread = None
self.crash_bin.export_file(self.crash_filename)
for (binary, crash_list) in self.crash_bin.bins.iteritems():
crashes += le... |
'This routine is called before the fuzzer transmits a test case and ensure the debugger thread is operational.
@type test_number: Integer
@param test_number: Test number to retrieve PCAP for.'
| def pre_send(self, test_number):
| self.log(('pre_send(%d)' % test_number), 10)
self.test_number = test_number
try:
self.crash_bin.import_file(self.crash_filename)
except:
pass
if ((not self.debugger_thread) or (not self.debugger_thread.isAlive())):
self.log('creating debugger thread', 5)
self.de... |
'Start up the target process by issuing the commands in self.start_commands.'
| def start_target(self):
| self.log('starting target process')
for command in self.start_commands:
subprocess.Popen(command)
self.log('done. target up and running, giving it 5 seconds to settle in.')
time.sleep(5)
return True
|
'Kill the current debugger thread and stop the target process by issuing the commands in self.stop_commands.'
| def stop_target(self):
| time.sleep(1)
self.log('stopping target process')
for command in self.stop_commands:
if (command == 'TERMINATE_PID'):
dbg = pydbg.pydbg()
for (pid, name) in dbg.enumerate_processes():
if (name.lower() == self.proc_name.lower()):
os.sy... |
'@type host: String
@param host: Hostname or IP address to bind server to
@type port: Integer
@param port: Port to bind server to
@type vmrun: String
@param vmrun: Path to VMWare vmrun.exe
@type vmx: String
@param vmx: Path to VMX file
@type snap_name... | def __init__(self, host, port, vmrun, vmx, snap_name=None, log_level=1, interactive=False):
| pedrpc.server.__init__(self, host, port)
self.host = host
self.port = port
self.interactive = interactive
if interactive:
print '[*] Entering interactive mode...'
try:
while 1:
print '[*] Please browse to the folder containing ... |
'Returns True. Useful for PED-RPC clients who want to see if the PED-RPC connection is still alive.'
| def alive(self):
| return True
|
'If the supplied message falls under the current log level, print the specified message to screen.
@type msg: String
@param msg: Message to log'
| def log(self, msg='', level=1):
| if (self.log_level >= level):
print ('[%s] %s' % (time.strftime('%I:%M.%S'), msg))
|
'Execute the specified command, keep trying in the event of a failure.
@type command: String
@param command: VMRun command to execute'
| def vmcommand(self, command):
| while 1:
self.log(('executing: %s' % command), 5)
pipe = os.popen(command)
out = pipe.readlines()
try:
pipe.close()
except IOError:
self.log('IOError trying to close pipe')
if (not out):
break
elif (not out[0]... |
'Controls an Oracle VirtualBox Virtual Machine
@type host: String
@param host: Hostname or IP address to bind server to
@type port: Integer
@param port: Port to bind server to
@type vmrun: String
@param vmrun: Path to VBoxManage
@type vmx: String
@param vmx: ... | def __init__(self, host, port, vmrun, vmx, snap_name=None, log_level=1, interactive=False):
| pedrpc.server.__init__(self, host, port)
self.host = host
self.port = port
self.interactive = interactive
if interactive:
print '[*] Entering interactive mode...'
try:
while 1:
print '[*] Please browse to the folder containing ... |
'Top level container instantiated by s_initialize(). Can hold any block structure or primitive. This can
essentially be thought of as a super-block, root-block, daddy-block or whatever other alias you prefer.
@type name: String
@param name: Name of this request'
| def __init__(self, name):
| self.name = name
self.label = name
self.stack = []
self.block_stack = []
self.closed_blocks = {}
self.callbacks = {}
self.names = {}
self.rendered = ''
self.mutant_index = 0
self.mutant = None
|
'Determine the number of repetitions we will be making.
@rtype: Integer
@return: Number of mutated forms this primitive can take.'
| def num_mutations(self):
| num_mutations = 0
for item in self.stack:
if item.fuzzable:
num_mutations += item.num_mutations()
return num_mutations
|
'The last open block was closed, so pop it off of the block stack.'
| def pop(self):
| if (not self.block_stack):
raise sex.SullyRuntimeError('BLOCK STACK OUT OF SYNC')
self.block_stack.pop()
|
'Push an item into the block structure. If no block is open, the item goes onto the request stack. otherwise,
the item goes onto the last open blocks stack.'
| def push(self, item):
| if (hasattr(item, 'name') and item.name):
if (item.name in self.names.keys()):
raise sex.SullyRuntimeError(('BLOCK NAME ALREADY EXISTS: %s' % item.name))
self.names[item.name] = item
if (not self.block_stack):
self.stack.append(item)
else:
self.block_s... |
'Reset every block and primitives mutant state under this request.'
| def reset(self):
| self.mutant_index = 1
self.closed_blocks = {}
for item in self.stack:
if item.fuzzable:
item.reset()
|
'Recursively walk through and yield every primitive and block on the request stack.
@rtype: Sulley Primitives
@return: Sulley Primitives'
| def walk(self, stack=None):
| if (not stack):
stack = self.stack
for item in stack:
if isinstance(item, block):
for item in self.walk(item.stack):
(yield item)
else:
(yield item)
|
'The basic building block. Can contain primitives, sizers, checksums or other blocks.
@type name: String
@param name: Name of the new block
@type request: s_request
@param request: Request this block belongs to
@type group: String
@param group: (Optional, def=None) Name of group to ... | def __init__(self, name, request, group=None, encoder=None, dep=None, dep_value=None, dep_values=[], dep_compare='=='):
| self.name = name
self.request = request
self.group = group
self.encoder = encoder
self.dep = dep
self.dep_value = dep_value
self.dep_values = dep_values
self.dep_compare = dep_compare
self.stack = []
self.rendered = ''
self.fuzzable = True
self.group_idx = 0
self.fuzz... |
'Determine the number of repetitions we will be making.
@rtype: Integer
@return: Number of mutated forms this primitive can take.'
| def num_mutations(self):
| num_mutations = 0
for item in self.stack:
if item.fuzzable:
num_mutations += item.num_mutations()
if self.group:
num_mutations *= len(self.request.names[self.group].values)
return num_mutations
|
'Push an arbitrary item onto this blocks stack.'
| def push(self, item):
| self.stack.append(item)
|
'Step through every item on this blocks stack and render it. Subsequent blocks recursively render their stacks.'
| def render(self):
| self.request.closed_blocks[self.name] = self
if self.dep:
if (self.dep_compare == '=='):
if (self.dep_values and (self.request.names[self.dep].value not in self.dep_values)):
self.rendered = ''
return
elif ((not self.dep_values) and (self.request.n... |
'Reset the primitives on this blocks stack to the starting mutation state.'
| def reset(self):
| self.fuzz_complete = False
self.group_idx = 0
for item in self.stack:
if item.fuzzable:
item.reset()
|
'Create a checksum block bound to the block with the specified name. You *can not* create a checksm for any
currently open blocks.
@type block_name: String
@param block_name: Name of block to apply sizer to
@type request: s_request
@param request: Request this block belongs to
@type algorithm: String
@param a... | def __init__(self, block_name, request, algorithm='crc32', length=0, endian='<', name=None):
| self.block_name = block_name
self.request = request
self.algorithm = algorithm
self.length = length
self.endian = endian
self.name = name
self.rendered = ''
self.fuzzable = False
if ((not self.length) and self.checksum_lengths.has_key(self.algorithm)):
self.length = self.chec... |
'Calculate and return the checksum (in raw bytes) over the supplied data.
@type data: Raw
@param data: Rendered block data to calculate checksum over.
@rtype: Raw
@return: Checksum.'
| def checksum(self, data):
| if (type(self.algorithm) is str):
if (self.algorithm == 'crc32'):
return struct.pack((self.endian + 'L'), (zlib.crc32(data) & 4294967295L))
elif (self.algorithm == 'adler32'):
return struct.pack((self.endian + 'L'), (zlib.adler32(data) & 4294967295L))
elif (self.algor... |
'Calculate the checksum of the specified block using the specified algorithm.'
| def render(self):
| self.rendered = ''
if (self.block_name in self.request.closed_blocks):
block_data = self.request.closed_blocks[self.block_name].rendered
self.rendered = self.checksum(block_data)
else:
if (not self.request.callbacks.has_key(self.block_name)):
self.request.callbacks[self.b... |
'Repeat the rendered contents of the specified block cycling from min_reps to max_reps counting by step. By
default renders to nothing. This block modifier is useful for fuzzing overflows in table entries. This block
modifier MUST come after the block it is being applied to.
@type block_name: String
@param block_name:... | def __init__(self, block_name, request, min_reps=0, max_reps=None, step=1, variable=None, fuzzable=True, name=None):
| self.block_name = block_name
self.request = request
self.variable = variable
self.min_reps = min_reps
self.max_reps = max_reps
self.step = step
self.fuzzable = fuzzable
self.name = name
self.value = self.original_value = ''
self.rendered = ''
self.fuzz_complete = False
se... |
'Mutate the primitive by stepping through the fuzz library, return False on completion. If variable-bounding is
specified then fuzzing is implicitly disabled. Instead, the render() routine will properly calculate the
correct repitition and return the appropriate data.
@rtype: Boolean
@return: True on success, False ot... | def mutate(self):
| self.request.names[self.block_name].render()
if (self.block_name not in self.request.closed_blocks):
raise sex.SullyRuntimeError(('CAN NOT APPLY REPEATER TO UNCLOSED BLOCK: %s' % self.block_name))
if (self.mutant_index == self.num_mutations()):
self.fuzz_complete = True
... |
'Determine the number of repetitions we will be making.
@rtype: Integer
@return: Number of mutated forms this primitive can take.'
| def num_mutations(self):
| return len(self.fuzz_library)
|
'Nothing fancy on render, simply return the value.'
| def render(self):
| if (self.block_name not in self.request.closed_blocks):
raise sex.SullyRuntimeError(('CAN NOT APPLY REPEATER TO UNCLOSED BLOCK: %s' % self.block_name))
if self.variable:
block = self.request.closed_blocks[self.block_name]
self.value = (block.rendered * self.variable.... |
'Reset the fuzz state of this primitive.'
| def reset(self):
| self.fuzz_complete = False
self.mutant_index = 0
self.value = self.original_value
|
'Create a sizer block bound to the block with the specified name. You *can not* create a sizer for any
currently open blocks.
@type block_name: String
@param block_name: Name of block to apply sizer to
@type request: s_request
@param request: Request this block belongs to
@type length: Integer
@param lengt... | def __init__(self, block_name, request, offset=0, length=4, endian='<', format='binary', inclusive=False, signed=False, math=None, fuzzable=False, name=None):
| self.block_name = block_name
self.request = request
self.offset = offset
self.length = length
self.endian = endian
self.format = format
self.inclusive = inclusive
self.signed = signed
self.math = math
self.fuzzable = fuzzable
self.name = name
self.original_value = 'N/A'
... |
'Exhaust the possible mutations for this primitive.
@rtype: Integer
@return: The number of mutations to reach exhaustion'
| def exhaust(self):
| num = (self.num_mutations() - self.mutant_index)
self.fuzz_complete = True
self.mutant_index = self.num_mutations()
self.bit_field.mutant_index = self.num_mutations()
self.value = self.original_value
return num
|
'Wrap the mutation routine of the internal bit_field primitive.
@rtype: Boolean
@return: True on success, False otherwise.'
| def mutate(self):
| if (self.mutant_index == self.num_mutations()):
self.fuzz_complete = True
self.mutant_index += 1
return self.bit_field.mutate()
|
'Wrap the num_mutations routine of the internal bit_field primitive.
@rtype: Integer
@return: Number of mutated forms this primitive can take.'
| def num_mutations(self):
| return self.bit_field.num_mutations()
|
'Render the sizer.'
| def render(self):
| self.rendered = ''
if (self.fuzzable and self.bit_field.mutant_index and (not self.bit_field.fuzz_complete)):
self.rendered = self.bit_field.render()
elif (self.block_name in self.request.closed_blocks):
if self.inclusive:
self_size = self.length
else:
self_si... |
'Wrap the reset routine of the internal bit_field primitive.'
| def reset(self):
| self.bit_field.reset()
|
'We overload and extend the render routine in order to properly pad and prefix the string.
[dword length][array][pad]'
| def render(self):
| blocks.block.render(self)
if (self.rendered == ''):
self.rendered = '\x00\x00\x00\x00'
else:
self.rendered = ((struct.pack('<L', len(self.rendered)) + self.rendered) + ndr_pad(self.rendered))
return self.rendered
|
'We overload and extend the render routine in order to properly pad and prefix the string.
[dword length][dword offset][dword passed size][string][pad]'
| def render(self):
| blocks.block.render(self)
if (self.rendered == ''):
self.rendered = '\x00\x00\x00\x00'
else:
self.rendered += '\x00'
length = len(self.rendered)
self.rendered = ((((struct.pack('<L', length) + struct.pack('<L', 0)) + struct.pack('<L', length)) + self.rendered) + ndr_pad(self.... |
'We overload and extend the render routine in order to properly pad and prefix the string.
[dword length][dword offset][dword passed size][string][pad]'
| def render(self):
| blocks.block.render(self)
if (self.rendered == ''):
self.rendered = '\x00\x00\x00\x00'
else:
self.rendered = (self.rendered.encode('utf-16le') + '\x00')
length = len(self.rendered)
self.rendered = ((((struct.pack('<L', length) + struct.pack('<L', 0)) + struct.pack('<L', lengt... |
'We overload and extend the render routine in order to properly insert substring lengths.'
| def render(self):
| blocks.block.render(self)
new_str = ''
for part in self.rendered.split('.'):
new_str += (str(len(part)) + part)
self.rendered = (new_str + '\x00')
return self.rendered
|
'We overload and extend the render routine in order to properly pad and prefix the string.
[dword length][array][pad]'
| def render(self):
| blocks.block.render(self)
if (self.rendered == ''):
self.rendered = '\x00\x00\x00\x00'
else:
self.rendered = ((struct.pack('>L', len(self.rendered)) + self.rendered) + xdr_pad(self.rendered))
return self.rendered
|
'Exhaust the possible mutations for this primitive.
@rtype: Integer
@return: The number of mutations to reach exhaustion'
| def exhaust(self):
| num = (self.num_mutations() - self.mutant_index)
self.fuzz_complete = True
self.mutant_index = self.num_mutations()
self.value = self.original_value
return num
|
'Mutate the primitive by stepping through the fuzz library, return False on completion.
@rtype: Boolean
@return: True on success, False otherwise.'
| def mutate(self):
| if (self.mutant_index == self.num_mutations()):
self.fuzz_complete = True
if ((not self.fuzzable) or self.fuzz_complete):
self.value = self.original_value
return False
self.value = self.fuzz_library[self.mutant_index]
self.mutant_index += 1
return True
|
'Calculate and return the total number of mutations for this individual primitive.
@rtype: Integer
@return: Number of mutated forms this primitive can take'
| def num_mutations(self):
| return len(self.fuzz_library)
|
'Nothing fancy on render, simply return the value.'
| def render(self):
| self.rendered = self.value
return self.rendered
|
'Reset this primitive to the starting mutation state.'
| def reset(self):
| self.fuzz_complete = False
self.mutant_index = 0
self.value = self.original_value
|
'Represent a delimiter such as :,,
, ,=,>,< etc... Mutations include repetition, substitution and exclusion.
@type value: Character
@param value: Original value
@type fuzzable: Boolean
@param fuzzable: (Optional, def=True) Enable/disable fuzzing of this primitive
@type name: String
@param name: (Option... | def __init__(self, value, fuzzable=True, name=None):
| self.value = self.original_value = value
self.fuzzable = fuzzable
self.name = name
self.s_type = 'delim'
self.rendered = ''
self.fuzz_complete = False
self.fuzz_library = []
self.mutant_index = 0
if self.value:
self.fuzz_library.append((self.value * 2))
self.fuzz_libr... |
'This primitive represents a list of static values, stepping through each one on mutation. You can tie a block
to a group primitive to specify that the block should cycle through all possible mutations for *each* value
within the group. The group primitive is useful for example for representing a list of valid opcodes.... | def __init__(self, name, values):
| self.name = name
self.values = values
self.fuzzable = True
self.s_type = 'group'
self.value = self.values[0]
self.original_value = self.values[0]
self.rendered = ''
self.fuzz_complete = False
self.mutant_index = 0
if (self.values != []):
for val in self.values:
... |
'Move to the next item in the values list.
@rtype: False
@return: False'
| def mutate(self):
| if (self.mutant_index == self.num_mutations()):
self.fuzz_complete = True
if ((not self.fuzzable) or self.fuzz_complete):
self.value = self.values[0]
return False
self.value = self.values[self.mutant_index]
self.mutant_index += 1
return True
|
'Number of values in this primitive.
@rtype: Integer
@return: Number of values in this primitive.'
| def num_mutations(self):
| return len(self.values)
|
'Generate a random chunk of data while maintaining a copy of the original. A random length range can be specified.
For a static length, set min/max length to be the same.
@type value: Raw
@param value: Original value
@type min_length: Integer
@param min_length: Minimum length of random block
@ty... | def __init__(self, value, min_length, max_length, max_mutations=25, fuzzable=True, step=None, name=None):
| self.value = self.original_value = str(value)
self.min_length = min_length
self.max_length = max_length
self.max_mutations = max_mutations
self.fuzzable = fuzzable
self.step = step
self.name = name
self.s_type = 'random_data'
self.rendered = ''
self.fuzz_complete = False
self... |
'Mutate the primitive value returning False on completion.
@rtype: Boolean
@return: True on success, False otherwise.'
| def mutate(self):
| if (self.mutant_index == self.num_mutations()):
self.fuzz_complete = True
if ((not self.fuzzable) or self.fuzz_complete):
self.value = self.original_value
return False
if (not self.step):
length = random.randint(self.min_length, self.max_length)
else:
length = (se... |
'Calculate and return the total number of mutations for this individual primitive.
@rtype: Integer
@return: Number of mutated forms this primitive can take'
| def num_mutations(self):
| return self.max_mutations
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.