s_bit_field(0b0110, 4, fuzzable = False, name = "Version")s_bit_field(0b00000000, 8, name = "Traffic_Class")s_bit_field(0b00000000000000000000, 20, name = "Flow_Label")s_bit_field(0b0000000000100000, 16, name = "Payload_Length")s_bit_field(0x06, 8, name = "Next_Header")s_bit_field(0xff, 8, name = "Hop_Limit")s_binary("0x2a071180000200000000000000bb0001", name = "Source_Address")s_binary("0x2a071180000200000000000000bb0002", name = "Destination_Address")
To quote from my answer there:
> I ran into the same problem. AFAIK there is no such functionality yet.
>
>A lot of protocols align bit fields on byte boundaries. If you have, say, a 1-bit field, followed by a 3-bit field, followed by a 4-bit field, your easy solution may be to create a byte field and fuzz all combinations. Thankfully there are only 256 combos for a single byte.
This workaround has been fine for me so far, but it looks trickier in your case, since you would need to conflate the first 4-bit, 8-bit, and 20-bit fields to get back on the byte boundary.
Would you open an issue for this feature request and link to this thread? It is something I would like to see, but it will be a big change.
The change would likely center around IFuzzable.render(). Right now it basically returns a bytes string. See `sessions.py` Session.transmit() line 731:https://github.com/jtpereyda/boofuzz/blob/ce5aabfb122caa7a700ea12e9e9a76d57d05dcce/boofuzz/sessions.py#L731
This call to node.render() calls render on the Request object, which starts a recursive call to all of the Request's blocks:https://github.com/jtpereyda/boofuzz/blob/ce5aabfb122caa7a700ea12e9e9a76d57d05dcce/boofuzz/blocks/request.py#L133
Some options for implementation:
1. Have IFuzzable.render() return a bit string.
2. Create a new object (I'll call it RenderedData, but hopefully it will have a better name). It would need to:
- Store a bit array (there is a bitarray package, but it looks like it's not currently maintained).
- Override __add__ and __radd__, and support adding bytes objects as well. In this case, the bytes objects would be translated to bits and appended/prepended. That way, adding the results of IFuzzable.render() works whether render() returns a bytes or a RenderedData.
- This will mean touching the recursive-calling blocks, which include at least: Request, Block, Checksum, and Size. In Request, this would mean changing line 130 to:
self._rendered = RenderedData()
The addition on line 133 should then work automatically.
- Finally, at some point it must be converted back to bytes for sending to a connection.
Option 1 requires changing every implementation of IFuzzable.render(), and locks us in to a slightly clunky interface.
Option 2 is a bit more conceptually involved, but I think would be cleaner in the end. The bitarray package would almost meet all these requirements, but I don't think it supports adding bytes and bitarrays together by default.
Neither is super-clean, but that's all I have for now.
By the way, if you do this, make sure to use a nice IDE like PyCharm if you're not already. :)
--
You received this message because you are subscribed to the Google Groups "boofuzz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boofuzz+u...@googlegroups.com.
To post to this group, send email to boo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/boofuzz/104753c7-ae8f-4a1c-8705-fe97a0cf43d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Actually the bitstring package seems to work well
>>> from bitstring import BitArray
>>> b = BitArray(bin='1111')
>>> b2 = 'ABCD'
>>> b + BitArray(bytes=b2)
BitArray('0xf41424344')
So you can just modify all code spots that use .render() to use this strategy of concatenation. I don't know, maybe there's something cleaner that can be done.