Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't concat str to bytes #1819

Open
zmw12306 opened this issue Sep 27, 2024 · 3 comments
Open

TypeError: can't concat str to bytes #1819

zmw12306 opened this issue Sep 27, 2024 · 3 comments
Assignees
Labels
medium Medium priority item

Comments

@zmw12306
Copy link

Configuration

impacket version: Impacket v0.12.0
Python version: Python 3.10.12
Target OS: Linux ubuntu

Debug Output With Command String

Raw IP packet: b'o\x05\x05\x05\x05\x05\x05\x05\x05\x01\x05s\x05\x05\x05\x05q\x03\x05\x05\x05\x05p\x01\x05\x05'
Traceback (most recent call last):
File "/home/youwei/XDiff/Impacket/IP.py", line 22, in
ip_packet = decoder.decode(Ip_packet)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/ImpactDecoder.py", line 191, in decode
ip6_packet = IP6.IP6(buffer)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/IP6.py", line 32, in init
self.load_header(buffer)
File "/home/youwei/.local/share/pipx/venvs/impacket/lib/python3.10/site-packages/impacket/ImpactPacket.py", line 435, in load_header
aBuffer += '\x00'
TypeError: can't concat str to bytes


### PCAP  
Raw IP packet: b'o\x05\x05\x05\x05\x05\x05\x05\x05\x01\x05s\x05\x05\x05\x05q\x03\x05\x05\x05\x05p\x01\x05\x05'

@anadrianmanrique anadrianmanrique added the in review This issue or pull request is being analyzed label Oct 3, 2024
@alexisbalbachan
Copy link
Contributor

Hi, could you provide some context on how you got that raw ip packet?
IPv6 headers should have a fixed size of 40 bytes while that packet is 26 bytes.

@zmw12306
Copy link
Author

The code is designed to handle cases where the packet length (packetlen) does not match the expected fixed size (hdr_len). When the provided aBuffer is shorter than hdr_len, the code attempts to pad aBuffer with additional bytes by appending '\x00'. This padding is meant as an error handling step to ensure aBuffer reaches the required length. However, this approach is causing a crash because aBuffer is a byte string, and appending '\x00' (a regular string) results in a TypeError, as you can't concatenate a string to a byte object.

To fix this, we need to change '\x00' to b'\x00' so that aBuffer is padded with bytes instead of a regular string. Here's how the modified code would look:

if len(aBuffer) < hdr_len:
    diff = hdr_len - len(aBuffer)
    for _ in range(diff):
        aBuffer += b'\x00'

@alexisbalbachan
Copy link
Contributor

Nice catch! I'm creating a PR with this fix.

@anadrianmanrique anadrianmanrique added medium Medium priority item and removed in review This issue or pull request is being analyzed labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Medium priority item
Projects
None yet
Development

No branches or pull requests

3 participants