Giter Club home page Giter Club logo

nobex's Introduction

nOBEX

Introduction

nOBEX allows emulating the PBAP, MAP, and HFP profiles to test vehicle infotainment systems and similar devices using these profiles. nOBEX provides PBAP and MAP clients to clone the genuine virtual filesystems for these profiles from a real phones. This means downloading the entire phone book and all text messages. Raw vcards, XML listings, and MAP BMSG structures are stored, and can be modified as desired for negative testing. nOBEX can then act as a PBAP and MAP server, allowing vehicles and other devices to connect to it and retrieve phone book and message information. Vcards, BMSGs, and XML listings are sent exactly as saved, allowing malformed user modified data to go through. Since most vehicle head units require HFP support before they attempt using PBAP and MAP, nOBEX also provides rudimentary support for HFP. It will send back user customizable preset responses to AT commands coming from the vehicle's head unit. This allows mimicking a real cell phone.

nOBEX is built on top of the PyOBEX project by David Boddie. This tool would not have been possible without David's great efforts in making OBEX approachable and easy to work with. nOBEX extends PyOBEX by adding support for large multi-part OBEX messages, HFP emulation, PBAP and MAP servers, a MAP client, and an improved PBAP client.

nOBEX (and PyOBEX) use the BlueZ Bluetooth stack to advertise over the Service Discovery Protocol (SDP) and establish RFCOMM connections. nOBEX/PyOBEX contain standalone implementations of the OBEX specification for client and server roles. Both Python 2 and 3 are supported.

In client mode, nOBEX uses BlueZ to query services offered by the server. If it detects that the requested service is available, it connect to the server over RFCOMM on the port specified over SDP. OBEX requests are constructed and sent to the server in accordance with the profile in use. Responses are interpreted and saved to disk. Client modes for PBAP and MAP can be used to clone a real phone.

In server mode, nOBEX advertises the available services over SDP. When a client makes an RFCOMM connection on the advertised port, the server will accept and handle OBEX requests. OBEX responses to requests will be sent using the data on disk. The PBAP and MAP servers serve file/folder structures matching those generated by the respective clients.

Installation Instructions

The following setup instructions were tested on Fedora 24, 27, and 29. Other recent distributions may also work, but experiences may vary. You may need to install legacy bluez tools (including sdptool) if your distribution does not bundle sdptool. Also be aware that OBEX servers tend to not work inside virtual machines with shared Bluetooth adapters. Either run Linux natively, or have a dedicated USB Bluetooth adapter used only by the VM.

Try probing advertised local services on SDP:

sudo sdptool browse local

If you are running a recent distribution, it will probably fail due to some breaking API changes in BlueZ 5. You can fix it by running bluetoothd in compat mode. Do this by editing the systemd service for bluetoothd.

sudo vi /usr/lib/systemd/system/bluetooth.service

Add --compat to the ExecStart line:

ExecStart=/usr/libexec/bluetooth/bluetoothd --compat

Now restart bluetoothd:

sudo service bluetooth stop
sudo systemctl daemon-reload
sudo service bluetooth start
sudo hciconfig -a hci0 reset

Test browsing local SDP services again (it should work this time):

sudo sdptool browse local

Get nOBEX and install it:

git clone https://github.com/nccgroup/nOBEX.git
cd nOBEX
sudo python3 setup.py install

Usage Instructions

PBAP

Find the MAC address of a phone whose phone book you wish to clone:

hcitool scan

Clone the PBAP contents of an existing phone (use your correct MAC and a preferably empty or nonexistent destination directory of your choice):

python3 examples/pbapclient.py 5C:51:88:8A:EC:5B ~/pbap_root/

Alternatively, use the PBAP sample data tree located in the examples/pbap_root folder.

Modify the vcards and listing XMLs in the your PBAP dump directory as desired. Now run a PBAP server using the cloned phone book:

sudo python3 examples/multiserver.py --pbap ~/pbap_root/

You'll also need to pair your PBAP client with the computer (PBAP server).

MAP

Pull the message data off your phone to establish a test MAP tree:

python3 examples/mapclient.py 5C:51:88:8A:EC:5B ~/map_root/

Alternatively, if your phone doesn't support MAP properly, use the MAP sample data tree located in the examples/map_root folder.

Modify the sample data as desired. Then run the server, indicating where it should look for the root of the MAP tree.

sudo python3 examples/multiserver.py --map ~/map_root/

HFP HF

The HFP client (hands free, car kit emulator) provides an AT command CLI to talk to your HFAG (phone/modem). I call it the "HFP client" despite it being an RFCOMM server because it is a "client" for the HFAG (phone/modem). You use the HF emulator ("client") to send AT commands to the HFAG, despite the fact that the "server" (HFAG) is the one that initiates the RFCOMM connection.

To run the HF emulator:

sudo python3 examples/hfpclient.py

You may need to start the HF emulator to advertise that you are an HF over SDP before you pair your phone. When the HF emulator is running, your phone will initiate an AT command RFCOMM connection with the emulator script. To expedite this process, you can click on your paired computer in your phone's Bluetooth settings to trigger a connection/reconnection.

Once the HFAG (phone/modem) initiates a connection, you usually have a limited window (30 seconds to a minute) to configure the HFP session. Before you can send useful AT commands (like initiating phone calls), you have to send a sequence of AT commands within the limited window, else the HFAG might disconnect from you. The following initial AT command sequence should work for most phones:

AT+BRSF=39
AT+CIND=?
AT+CIND?
AT+CMER=3,0,0,1
AT+CHLD=?
AT+CCWA=1
AT+CLIP=1
AT+NREC=0

HFP HFAG

The HFP server (audio gateway) is fairly basic, sending back preconfigured replies to select commands. The server is set up to support common HFP commands out of the box, but every vehicle will likely require a few additional commands and/or changes to responses. Custom responses can be configured through a text file with a format of command and response pairs on each line, command and response being separated by a tab. Sample config files can be found in the examples/bbeast folder.

Unlike the other servers, the nOBEX HFP AG implementation doesn't actually accept RFCOMM connections. The HFP standard is ambiguous on how connections should be established, and thus both the HF and AG are allowed to both accept and initiate connections. Different head units behave differently when it comes to connection establishment practices. However, most HF devices tend to accept being connected to by the AG if the AG does not accept connections on its own port. Thus, the nOBEX HFP AG "server" just searches through paired devices for ones that support the HF service, and nOBEX then connects to the HF device.

Be aware that the HFP AG code will try connecting to any device listed under /var/lib/bluetooth/*/* that claims to support the HFP HF role. Thus, you should delete any erroneous pairings in that directory before trying to use the HFP server.

To run a standalone HFP AG (config file is optional):

sudo python3 examples/multiserver.py --hfp [config_file]

The HFP server (HFAG) also supports interactive operation where you can edit auto-responses at runtime or manually send AT responses. The HFP server listens on port 7137 of localhost for commands. You can connect to it using netcat as shown below:

nc localhost 7137

There are only two simple commands for this interface:

  • send <atresp> - send atresp as an AT response
  • ursp <atcmd> <atresp> - update/set the auto-response for atcmd to atresp

The following example commands will simulate an incoming phone call:

ursp AT+CLCC +CLCC: 1,1,4,0,0,"1234567890",129
send RING

FTP

The FTP (File Transfer Profile) client allows you to browse files on an OBEX FTP server, such as another computer running nOBEX, or an Android phone running the Bluetooth File Transfer app. There is an FTP client sample program located in the examples directory.

python3 examples/ftpclient.py SERVER_MAC_ADDRESS [save_directory]

Running the example FTP client with only a Bluetooth MAC address as the argument will print out a recursive directory listing of all files accessible over OBEX FTP on the server. If the optional save_directory argument is provided, the script will download every file that is accessible on the server and save it to the specified save directory on your computer.

The FTP server allows a client to browse files on your computer (server) inside a specified folder.

sudo python3 examples/multiserver.py --ftp PATH_TO_FTP_FOLDER

OPP

The OPP (Object Push Profile) client allows pushing a file on your computer to an OBEX OPP server.

python3 examples/pushclient.py SERVER_MAC_ADDRESS FILE_TO_PUSH

The OPP server allows a client to push files to your computer (server) inside a specified folder.

sudo python3 examples/multiserver.py --opp PATH_TO_OPP_FOLDER

Combining servers

The multiserver.py scripts allows running any combination of HFP, MAP, PBAP, FTP, and OPP servers simultaneously. Just combine the arguments from the examples shown above. To run HFP, MAP, and PBAP simultaneously:

python3 examples/multiserver.py --map ~/map_root/ --pbap ~/pbap_root/ --hfp [config_file]

The combination of HFP and PBAP has been tested successfully on a 2012 Ford Focus.

Applications

The primary purpose of nOBEX is to perform negative testing and fuzzing of PBAP and MAP clients on automotive head units. The HFP support and PBAP/MAP client support are intended to facilitate this goal. Manual fuzzing can be performed by running a server with hand-modified XML listings, vcards, and BMSGs. OBEX is a rich fuzzing target with many nested TLV structures that can span multi-part messages. PBAP and MAP greatly increase the attack surface with vcard, BMSG, and XML parsers.

nOBEX does not have integrated support for automated fuzzing, but since it is written in Python, it is easy to extend. More powerful fuzzing capabilities can be built by pairing it with a mutation engine and instrumenting the target device.

Beyond fuzzing MAP and PBAP on automotive head units, nOBEX can also be used for normal positive testing of PBAP, MAP, and other OBEX profiles (such as FTP) for both client and server roles. The PBAP and MAP servers were tested with the OBEX Commander app for Android, in which many crashes could be triggered by faulty OBEX communication and malformed profile specific data. Furthermore, the HFP support can be used to manually fuzz AT commands.

nobex's People

Contributors

dboddie avatar eliasj avatar notmikeb avatar sultanqasim avatar user65k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nobex's Issues

OSError: [Errno 93] Protocol not supported

Hi everyone,

I recently bought a new car audio system with BT and after trying nOBEX it returns the following error:

Traceback (most recent call last):
  File "examples/multiserver.py", line 31, in serve
    server.serve(socket)
  File "/home/src/nOBEX/examples/servers/hfp.py", line 153, in serve
    connection = self._connect_hfp(address, port)
  File "/home/src/nOBEX2/examples/servers/hfp.py", line 120, in _connect_hfp
    asock.connect(bytes(address, encoding="UTF-8"))
OSError: [Errno 93] Protocol not supported

is not the 1st time I tried nOBEX (with different audio systems) but is the 1st time I see the error...

I'm using the latest nOBEX version.

Thanks

sdptool add returned 255

Hi,

I'm using this library on ubuntu 18.04. I tried pbapclient.py and mapclient.py and they work well.
I tried hfpclient.py but I'm having this error
"sdptool add returned 255" on file bluez_helper.py line 92
when this line on hfpclient.py is called
bluez_helper.advertise_service('hf', port)

UnknownResponse for vcard listing on Samsung

I am trying to run your solution on Ubuntu 16.04. When I run the pbapclient-download.py to download contacts from my phone (I tried Galaxy S7 and Galaxy S6) I am getting the following error:

File "examples/pbapclient-download.py", line 84, in dump_dir
hdrs, cards = c.get(src_path, header_list=[headers.Type(b'x-bt/vcard-listing')])
TypeError: 'UnknownResponse' object is not iterable

And this is the full traces of what I am getting:

Traceback (most recent call last):
File "examples/pbapclient-download.py", line 150, in
sys.exit(main())
File "examples/pbapclient-download.py", line 127, in main
dump_dir(c, prefix+"telecom/pb", dest_dir+prefix+"telecom/pb")
File "examples/pbapclient-download.py", line 84, in dump_dir
hdrs, cards = c.get(src_path, header_list=[headers.Type(b'x-bt/vcard-listing')])
TypeError: 'UnknownResponse' object is not iterable

Can you please help?

not working on Android phones

Hi, I have not been having any success with the pbapclient against Android phones. It works fine against all iphones i have tried.
I did a hcidump and see that the phone replies to the obex request of type "x-bt/vcard-listing" and name "telecom/pb" with Not Acceptable. This causes the python script to throw a TypeError.
I don't have a SIM in the phone but tried it with the SIM option just to be safe. I was wondering if you had tested this against an Android phone with any success.
Thanks

IRDA/Serial support?

As ridiculous as it is, is it possible to get the tool to work with Irda or serial?

The nOBEX server address is represented to 00:00:00:00:00:00.

I executed nOBEX multiserver, but it cannot be executed for normal MAC address
The log follows below:

sudo python3 examples/multiserver.py --pbap examples/pbap_root
obexd: no process found
Starting server for 00:00:00:00:00:00 on port 19

How can I execute multiserver with normal MAC address?

Windows

Hi,

is there any way to make this work on windows?
I'm having this error:

module 'socket' has no attribute 'BDADDR_ANY'

I read that it is due to socket library which doesn't have bluetooth support on windows.

Thank you

pbapclient.py doesn't work in my case

Hello! thank you for making this codes.

I tested 5 devices (android 3, iphone 2). however when i used pbapclient.py, i had problem.

When i tested with iphone, *.vcf file was created well. but every vcf files didn't contained contents
However when i tested in android, i got this error.

Traceback (most recent call last):
  File "examples/pbapclient.py", line 134, in <module>
    sys.exit(main(sys.argv))
  File "examples/pbapclient.py", line 111, in main
    dump_dir(c, prefix+"telecom/pb", dest_dir+prefix+"telecom/pb")
  File "examples/pbapclient.py", line 60, in dump_dir
    hdrs, cards = c.get(src_path, header_list=[headers.Type(b'x-bt/vcard-listing')])
  File "/usr/local/lib/python3.6/dist-packages/nOBEX/client.py", line 296, in get
    raise OBEXError(response)
nOBEX.common.OBEXError: UnknownResponse(code=0xC6, data=b'\xcb\x00\x00\x00\x01'

To solve this error, I added print code for debug. the error is as below.

[DEBUG][request] Connect(data=(16, 0, 65535))
[DEBUG][request raw] b'\x80\x00\x1a\x10\x00\xff\xffF\x00\x13ya5\xf0\xf0\xc5\x11\xd8\tf\x08\x00 \x0c\x9af'
[DEBUG][request] Get(data=())
[DEBUG][request raw] b'\x83\x007\xcb\x00\x00\x00\x01\x01\x00\x19\x00t\x00e\x00l\x00e\x00c\x00o\x00m\x00/\x00p\x00b\x00\x00B\x00\x16x-bt/vcard-listing\x00'
[DEBUG][response] UnknownResponse(code=0xC6, data=b'\xcb\x00\x00\x00\x01'

i guess second response has problem. but i don't know detailed structure about "PBAP protocol" and code. plz tell me how to solve this problem. I want to run this code at iphone and android.

python3 examples/pbapclient.py E0:1F:88:28:36:9E ~/pbap_root/ : - while executing this command i am getting this error please help.

Traceback (most recent call last):
File "/home/shankar/nOBEX/examples/pbapclient.py", line 133, in
sys.exit(main(sys.argv))
File "/home/shankar/nOBEX/examples/pbapclient.py", line 107, in main
c.connect()
File "/home/shankar/nOBEX/examples/clients/pbap.py", line 23, in connect
super(PBAPClient, self).connect(header_list = [headers.Target(uuid)])
File "/usr/local/lib/python3.10/dist-packages/nOBEX/client.py", line 152, in connect
response = self._send_headers(request, header_list, max_length)
File "/usr/local/lib/python3.10/dist-packages/nOBEX/client.py", line 87, in _send_headers
self.socket.sendall(request.encode())
ConnectionResetError: [Errno 104] Connection reset by peer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.