def s_get(name=None): ''' Return the request with the specified name or the current request if name is not specified. Use this to switch from global function style request manipulation to direct object manipulation. Example:: req = s_get("HTTP BASIC") print req.num_mutations() The selected request is also set as the default current. (ie: s_switch(name) is implied). @type name: String @param name: (Optional, def=None) Name of request to return or current request if name is None. @rtype: blocks.request @return: The requested request. ''' if not name: return blocks.CURRENT # ensure this gotten request is the new current. s_switch(name) if not blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS NOT FOUND: %s" % name) return blocks.REQUESTS[name]
def s_size (block_name, length=4, endian="<", format="binary", inclusive=False, signed=False, math=None, fuzzable=False, name=None): ''' Create a sizer block bound to the block with the specified name. You *can not* create a sizer for any currently open blocks. @see: Aliases: s_sizer() @type block_name: String @param block_name: Name of block to apply sizer to @type length: Integer @param length: (Optional, def=4) Length of sizer @type endian: Character @param endian: (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >) @type format: String @param format: (Optional, def=binary) Output format, "binary" or "ascii" @type inclusive: Boolean @param inclusive: (Optional, def=False) Should the sizer count its own length? @type signed: Boolean @param signed: (Optional, def=False) Make size signed vs. unsigned (applicable only with format="ascii") @type math: Function @param math: (Optional, def=None) Apply the mathematical operations defined in this function to the size @type fuzzable: Boolean @param fuzzable: (Optional, def=False) Enable/disable fuzzing of this sizer @type name: String @param name: Name of this sizer field ''' # you can't add a size for a block currently in the stack. if block_name in blocks.CURRENT.block_stack: raise sex.error("CAN NOT ADD A SIZE FOR A BLOCK CURRENTLY IN THE STACK") size = blocks.size(block_name, blocks.CURRENT, length, endian, format, inclusive, signed, math, fuzzable, name) blocks.CURRENT.push(size)
def s_checksum(block_name, algorithm="crc32", length=0, endian="<", name=None): ''' Create a checksum block bound to the block with the specified name. You *can not* create a checksum for any currently open blocks. @type block_name: String @param block_name: Name of block to apply sizer to @type algorithm: String @param algorithm: (Optional, def=crc32) Checksum algorithm to use. (crc32, adler32, md5, sha1) @type length: Integer @param length: (Optional, def=0) Length of checksum, specify 0 to auto-calculate @type endian: Character @param endian: (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >) @type name: String @param name: Name of this checksum field ''' # you can't add a checksum for a block currently in the stack. if block_name in blocks.CURRENT.block_stack: raise sex.error( "CAN N0T ADD A CHECKSUM FOR A BLOCK CURRENTLY IN THE STACK") checksum = blocks.checksum(block_name, blocks.CURRENT, algorithm, length, endian, name) blocks.CURRENT.push(checksum)
def s_get (name=None): ''' Return the request with the specified name or the current request if name is not specified. Use this to switch from global function style request manipulation to direct object manipulation. Example:: req = s_get("HTTP BASIC") print req.num_mutations() The selected request is also set as the default current. (ie: s_switch(name) is implied). @type name: String @param name: (Optional, def=None) Name of request to return or current request if name is None. @rtype: blocks.request @return: The requested request. ''' if not name: return blocks.CURRENT # ensure this gotten request is the new current. s_switch(name) if not blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS NOT FOUND: %s" % name) return blocks.REQUESTS[name]
def __init__ (self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options if not self.value: raise sex.error("MISSING LEGO.tag DEFAULT VALUE") self.push(primitives.string(self.value))
def __init__(self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options if not self.value: raise sex.error("MISSING LEGO.tag DEFAULT VALUE") self.push(primitives.string(self.value))
def __init__ (self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options if not self.value: raise sex.error("MISSING LEGO.ber_integer DEFAULT VALUE") self.push(primitives.dword(self.value, endian=">"))
def __init__(self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options if not self.value: raise sex.error("MISSING LEGO.ber_integer DEFAULT VALUE") self.push(primitives.dword(self.value, endian=">"))
def s_switch(name): ''' Change the currect request to the one specified by "name". @type name: String @param name: Name of request ''' if not blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS NOT FOUND: %s" % name) blocks.CURRENT = blocks.REQUESTS[name]
def s_switch (name): ''' Change the currect request to the one specified by "name". @type name: String @param name: Name of request ''' if not blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS NOT FOUND: %s" % name) blocks.CURRENT = blocks.REQUESTS[name]
def s_initialize(name): ''' Initialize a new block request. All blocks / primitives generated after this call apply to the named request. Use s_switch() to jump between factories. @type name: String @param name: Name of request ''' if blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS ALREADY EXISTS: %s" % name) blocks.REQUESTS[name] = blocks.request(name) blocks.CURRENT = blocks.REQUESTS[name]
def s_update (name, value): ''' Update the value of the named primitive in the currently open request. @type name: String @param name: Name of object whose value we wish to update @type value: Mixed @param value: Updated value ''' if not blocks.CURRENT.names.has_key(name): raise sex.error("NO OBJECT WITH NAME '%s' FOUND IN CURRENT REQUEST" % name) blocks.CURRENT.names[name].value = value
def s_initialize (name): ''' Initialize a new block request. All blocks / primitives generated after this call apply to the named request. Use s_switch() to jump between factories. @type name: String @param name: Name of request ''' if blocks.REQUESTS.has_key(name): raise sex.error("blocks.REQUESTS ALREADY EXISTS: %s" % name) blocks.REQUESTS[name] = blocks.request(name) blocks.CURRENT = blocks.REQUESTS[name]
def __init__ (self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options self.prefix = options.get("prefix", "\x04") if not self.value: raise sex.error("MISSING LEGO.ber_string DEFAULT VALUE") str_block = blocks.block(name + "_STR", request) str_block.push(primitives.string(self.value)) self.push(blocks.size(name + "_STR", request, endian=">", fuzzable=True)) self.push(str_block)
def s_update(name, value): ''' Update the value of the named primitive in the currently open request. @type name: String @param name: Name of object whose value we wish to update @type value: Mixed @param value: Updated value ''' if not blocks.CURRENT.names.has_key(name): raise sex.error("NO OBJECT WITH NAME '%s' FOUND IN CURRENT REQUEST" % name) blocks.CURRENT.names[name].value = value
def s_lego (lego_type, value=None, options={}): ''' Legos are pre-built blocks... XXX finish this doc ''' # as legos are blocks they must have a name. # generate a unique name for this lego. name = "LEGO_%08x" % len(blocks.CURRENT.names) if not legos.BIN.has_key(lego_type): raise sex.error("INVALID LEGO TYPE SPECIFIED: %s" % lego_type) lego = legos.BIN[lego_type](name, blocks.CURRENT, value, options) # push the lego onto the stack and immediately pop to close the block. blocks.CURRENT.push(lego) blocks.CURRENT.pop()
def s_lego(lego_type, value=None, options={}): ''' Legos are pre-built blocks... XXX finish this doc ''' # as legos are blocks they must have a name. # generate a unique name for this lego. name = "LEGO_%08x" % len(blocks.CURRENT.names) if not legos.BIN.has_key(lego_type): raise sex.error("INVALID LEGO TYPE SPECIFIED: %s" % lego_type) lego = legos.BIN[lego_type](name, blocks.CURRENT, value, options) # push the lego onto the stack and immediately pop to close the block. blocks.CURRENT.push(lego) blocks.CURRENT.pop()
def s_size(block_name, length=4, endian="<", format="binary", inclusive=False, signed=False, math=None, fuzzable=False, name=None): ''' Create a sizer block bound to the block with the specified name. You *can not* create a sizer for any currently open blocks. @see: Aliases: s_sizer() @type block_name: String @param block_name: Name of block to apply sizer to @type length: Integer @param length: (Optional, def=4) Length of sizer @type endian: Character @param endian: (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >) @type format: String @param format: (Optional, def=binary) Output format, "binary" or "ascii" @type inclusive: Boolean @param inclusive: (Optional, def=False) Should the sizer count its own length? @type signed: Boolean @param signed: (Optional, def=False) Make size signed vs. unsigned (applicable only with format="ascii") @type math: Function @param math: (Optional, def=None) Apply the mathematical operations defined in this function to the size @type fuzzable: Boolean @param fuzzable: (Optional, def=False) Enable/disable fuzzing of this sizer @type name: String @param name: Name of this sizer field ''' # you can't add a size for a block currently in the stack. if block_name in blocks.CURRENT.block_stack: raise sex.error( "CAN NOT ADD A SIZE FOR A BLOCK CURRENTLY IN THE STACK") size = blocks.size(block_name, blocks.CURRENT, length, endian, format, inclusive, signed, math, fuzzable, name) blocks.CURRENT.push(size)
def __init__(self, name, request, value, options={}): blocks.block.__init__(self, name, request, None, None, None, None) self.value = value self.options = options if not self.value: raise sex.error("MISSING LEGO.tag DEFAULT VALUE") ip_arr = value.split(".") ctr = 0 for ip_val in ip_arr: if ctr == 0: self.push(primitives.string(ip_val)) self.push(primitives.delim(".")) else: self.push(primitives.static(ip_val)) if ctr < 3: self.push(primitives.delim(".")) ctr += 1
def s_checksum (block_name, algorithm="crc32", length=0, endian="<", name=None): ''' Create a checksum block bound to the block with the specified name. You *can not* create a checksum for any currently open blocks. @type block_name: String @param block_name: Name of block to apply sizer to @type algorithm: String @param algorithm: (Optional, def=crc32) Checksum algorithm to use. (crc32, adler32, md5, sha1) @type length: Integer @param length: (Optional, def=0) Length of checksum, specify 0 to auto-calculate @type endian: Character @param endian: (Optional, def=LITTLE_ENDIAN) Endianess of the bit field (LITTLE_ENDIAN: <, BIG_ENDIAN: >) @type name: String @param name: Name of this checksum field ''' # you can't add a checksum for a block currently in the stack. if block_name in blocks.CURRENT.block_stack: raise sex.error("CAN N0T ADD A CHECKSUM FOR A BLOCK CURRENTLY IN THE STACK") checksum = blocks.checksum(block_name, blocks.CURRENT, algorithm, length, endian, name) blocks.CURRENT.push(checksum)