seemoo-lab / internalblue

Bluetooth experimentation framework for Broadcom and Cypress chips.
693 stars 86 forks source link

core.py - Python3 problem #18

Closed bobwilmes closed 4 years ago

bobwilmes commented 4 years ago

I am getting a python error (TypeError: can't concat str to bytes) at line 1196 in core..py. Can you please help me fix ? I am running a Nexus5 (Android 6.0.1) pairded to an iPhone X internal blue core error

bobwilmes@bobwilmes:~$ adb devices

bobwilmes@bobwilmes:~$ cd internalblue bobwilmes@bobwilmes:~/internalblue$ ls android_bluetooth_stack dummymemdump.bin examples internalblue internalblue_thesis_dennis_mantz.pdf ios-internalblued linux_bluez macos-framework mypy.ini README.md setup.py tests bobwilmes@bobwilmes:~/internalblue$ ls examples/nexus5 BLE_Reception_PoC.py CVE_2018_5383_Invalid_Curve_Attack_PoC.py KNOB_PoC.py LMP_MAC_Address_Filter.py NiNo_PoC.py bobwilmes@bobwilmes:~/internalblue$ sudo python3 examples/nexus5 [sudo] password for bobwilmes: /usr/bin/python3: can't find 'main' module in 'examples/nexus5' bobwilmes@bobwilmes:~/internalblue$ sudo python3 examples/nexus5/KNOB_PoC.py [] Found multiple adb devices [] Connected to 0759f01913d7c4c2 [] Chip identifier: 0x6109 (003.001.009) [] Using fw_0x6109.py [] Loaded firmware information for BCM4335C0. [] Try to enable debugging on H4 (warning if not supported)... [] Installing patch which ensures that send_LMP_encryptoin_key_size_req is always len=1! [] patchRom: Choosing next free slot: 113 Traceback (most recent call last): File "examples/nexus5/KNOB_PoC.py", line 42, in internalblue.writeMem(0x203797, '\x01') # global key entropy File "/usr/local/lib/python3.6/dist-packages/internalblue/core.py", line 1196, in writeMem p32(write_addr) + data[byte_counter : byte_counter + blocksize], TypeError: can't concat str to bytes bobwilmes@bobwilmes:~/internalblue$

fmagin commented 4 years ago

That script was simply outdated and not properly ported to Python 3 yet. Could you please test if https://github.com/seemoo-lab/internalblue/tree/fix_examples works for you?

bobwilmes commented 4 years ago

Hi Florian, I cloned the repository and re-ran the test. The problem is line 1196 in the core.py module in the internalblue/internalblue/core.py

Python reports: [*] patchRom: Reusing slot for address 0x5aed0: 113 Traceback (most recent call last): File "examples/nexus5/KNOB_PoC.py", line 42, in internalblue.writeMem(0x203797, '\x01') # global key entropy File "/usr/local/lib/python3.6/dist-packages/internalblue/core.py", line 1196, in writeMem p32(write_addr) + data[byte_counter : byte_counter + blocksize], TypeError: can't concat str to bytes

Can you fix this in core.py ? I don't know enough Python but it appears to be the string concat doesn't work under Python3

Regards, Bob Wilmes Omaha, Nebraska, USA

On Wed, Mar 25, 2020 at 4:28 PM Florian Magin notifications@github.com wrote:

That script was simply outdated and not properly ported to Python 3 yet. Could you please test if https://github.com/seemoo-lab/internalblue/tree/fix_examples works for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seemoo-lab/internalblue/issues/18#issuecomment-604097147, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUICS6QF6OTMPOIRGRMXQDRJJZO3ANCNFSM4LTWBFNQ .

-- Bob Wilmes bobwilmes@gmail.com

bobwilmes commented 4 years ago

Hi Florian, i did some research and there appear to be three lines in core.py that have the same string concatenation problem.

Line 318, 867 and 1169

Regards , Bob Wilmes

Sent from my iPhone

On Mar 25, 2020, at 4:28 PM, Florian Magin notifications@github.com wrote:

 That script was simply outdated and not properly ported to Python 3 yet. Could you please test if https://github.com/seemoo-lab/internalblue/tree/fix_examples works for you?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

fmagin commented 4 years ago

You aren't running the updated version of the script. The problem is the line

internalblue.writeMem(0x203797, '\x01')

Which passes a str to writeMem, but in Python 3 the argument to writeMem must be bytes. The fix is simply to change it to

internalblue.writeMem(0x203797, b'\x01')

That is changed in the branch https://github.com/seemoo-lab/internalblue/blob/fix_examples/examples/nexus5/KNOB_PoC.py#L40 already but your stack trace shows that you aren't running the updated version.

bobwilmes commented 4 years ago

Thank you Florian - this fixed it!

Regards, Bob WIlmes

On Thu, Mar 26, 2020 at 1:36 AM Florian Magin notifications@github.com wrote:

You aren't running the updated version of the script. The problem is the line

internalblue.writeMem(0x203797, '\x01')

Which passes a 'str' to writeMem, but in Python 3 the argument to writeMem must be bytes. The fix is simply to change it to

internalblue.writeMem(0x203797, b'\x01')

That is changed in the branch https://github.com/seemoo-lab/internalblue/blob/fix_examples/examples/nexus5/KNOB_PoC.py#L40 already but your stack trace shows that you aren't running the updated version.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/seemoo-lab/internalblue/issues/18#issuecomment-604256666, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUICS62LJ57HE34IH43ZCTRJLZXFANCNFSM4LTWBFNQ .

-- Bob Wilmes bobwilmes@gmail.com

fmagin commented 4 years ago

Thanks for the report!