|
| 1 | +原文:[Reverse Engineering A Mysterious UDP Stream in My Hotel](http://wiki.gkbrk.com/Hotel_Music.html) |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +Hey everyone, I have been staying at a hotel for a while. It's one of those |
| 6 | +modern ones with smart TVs and other connected goodies. I got curious and |
| 7 | +opened Wireshark, as any tinkerer would do. |
| 8 | + |
| 9 | +I was very surprised to see a huge amount of UDP traffic on port 2046. I |
| 10 | +looked it up but the results were far from useful. This wasn't a standard |
| 11 | +port, so I would have to figure it out manually. |
| 12 | + |
| 13 | +At first, I suspected that the data might be a television stream for the TVs, |
| 14 | +but the packet length seemed too small, even for a single video frame. |
| 15 | + |
| 16 | +### Grabbing the data |
| 17 | + |
| 18 | +The UDP packets weren't sent to my IP and I wasn't doing ARP spoofing, so |
| 19 | +these packets were sent to everyone. Upon closer inspection, I found out that |
| 20 | +these were **Multicast** packets. This basically means that the packets are |
| 21 | +sent once and received by multiple devices simultaneously. Another thing I |
| 22 | +noticed was the fact that all of those packets were the same length (634 |
| 23 | +bytes). |
| 24 | + |
| 25 | +I decided to write a Python script to save and analyze this data. First of |
| 26 | +all, here's the code I used to receive Multicast packets. In the following |
| 27 | +code, _234.0.0.2_ is the IP I got from Wireshark. |
| 28 | + |
| 29 | +```python |
| 30 | + |
| 31 | + import socket |
| 32 | + import struct |
| 33 | + |
| 34 | + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) |
| 35 | + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 36 | + s.bind(('', 2046)) |
| 37 | + |
| 38 | + mreq = struct.pack("4sl", socket.inet_aton("234.0.0.2"), socket.INADDR_ANY) |
| 39 | + s.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) |
| 40 | + |
| 41 | + while True: |
| 42 | + data = s.recv(2048) |
| 43 | + print(data) |
| 44 | + |
| 45 | +``` |
| 46 | + |
| 47 | +On top of this, I also used |
| 48 | +[binascii](https://docs.python.org/3.5/library/binascii.html) to convert this |
| 49 | +to hex in order make reading the bytes easier. After watching thousands of |
| 50 | +these packets scroll through the console, I noticed that the first ~15 bytes |
| 51 | +were the same. These bytes probably indicate the protocol and the |
| 52 | +packet/command ID but I only received the same one so I couldn't investigate |
| 53 | +those. |
| 54 | + |
| 55 | +### Audio is so LAME |
| 56 | + |
| 57 | +It also took me an embarrassingly long time to see the string |
| 58 | +`LAME3.91UUUUUUU` at the end of the packets. I suspected this was MPEG |
| 59 | +compressed audio data, but saving one packet as test.mp3 failed to played with |
| 60 | +mplayer and the _file_ utility only identified this as `test.mp3: data`. There |
| 61 | +was obviously data in this packet and _file_ should know when it sees MPEG |
| 62 | +Audio data, so I decided to write another Python script to save the packet |
| 63 | +data with offsets. This way it would save the file `test1` skipping 1 byte |
| 64 | +from the packet, `test2` skipping 2 bytes and so on. Here's the code I used |
| 65 | +and the result. |
| 66 | + |
| 67 | +```python |
| 68 | + |
| 69 | + data = s.recv(2048) |
| 70 | + for i in range(25): |
| 71 | + open("test{}".format(i), "wb+").write(data[i:]) |
| 72 | + |
| 73 | +``` |
| 74 | + |
| 75 | +After this, I ran `file test*` and voilà! Now we know we have to skip 8 bytes |
| 76 | +to get to the MPEG Audio data. |
| 77 | + |
| 78 | +```python |
| 79 | + |
| 80 | + $ file test* |
| 81 | + test0: data |
| 82 | + test1: UNIF v-16624417 format NES ROM image |
| 83 | + test10: UNIF v-763093498 format NES ROM image |
| 84 | + test11: UNIF v-1093499874 format NES ROM image |
| 85 | + test12: data |
| 86 | + test13: TTComp archive, binary, 4K dictionary |
| 87 | + test14: data |
| 88 | + test15: data |
| 89 | + test16: UNIF v-1939734368 format NES ROM image |
| 90 | + test17: UNIF v-1198759424 format NES ROM image |
| 91 | + test18: UNIF v-256340894 format NES ROM image |
| 92 | + test19: UNIF v-839862132 format NES ROM image |
| 93 | + test2: UNIF v-67173804 format NES ROM image |
| 94 | + test20: data |
| 95 | + test21: data |
| 96 | + test22: data |
| 97 | + test23: DOS executable (COM, 0x8C-variant) |
| 98 | + test24: COM executable for DOS |
| 99 | + test3: UNIF v-1325662462 format NES ROM image |
| 100 | + test4: data |
| 101 | + test5: data |
| 102 | + test6: data |
| 103 | + test7: data |
| 104 | + test8: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo |
| 105 | + test9: UNIF v-2078407168 format NES ROM image |
| 106 | + |
| 107 | +``` |
| 108 | + |
| 109 | +```python |
| 110 | + |
| 111 | + while True: |
| 112 | + data = s.recv(2048) |
| 113 | + sys.stdout.buffer.write(data[8:]) |
| 114 | + |
| 115 | +``` |
| 116 | + |
| 117 | +Now all we need to do is continuously read packets, skip the first 8 bytes, |
| 118 | +write them to a file and it should play perfectly. |
| 119 | + |
| 120 | +But what was this audio? Was this a sneakily placed bug that listened to me? |
| 121 | +Was it something related to the smart TVs in my room? Something related to the |
| 122 | +hotel systems? Only one way to find out. |
| 123 | + |
| 124 | +```python |
| 125 | + |
| 126 | + $ python3 listen_2046.py > test.mp3 |
| 127 | + * wait a little to get a recording * |
| 128 | + ^C |
| 129 | + |
| 130 | + $ mplayer test.mp3 |
| 131 | + MPlayer (C) 2000-2016 MPlayer Team |
| 132 | + 224 audio & 451 video codecs |
| 133 | + |
| 134 | + Playing test.mp3. |
| 135 | + libavformat version 57.25.100 (external) |
| 136 | + Audio only file format detected. |
| 137 | + ===== |
| 138 | + Starting playback... |
| 139 | + A: 3.9 (03.8) of 13.0 (13.0) 0.7% |
| 140 | + |
| 141 | +``` |
| 142 | + |
| 143 | +### The Revelation/Disappointment |
| 144 | + |
| 145 | +What the hell? I can't believe I spent time for this. It's just elevator |
| 146 | +music. It is played in the hotel corridors around the elevators. Oh well, at |
| 147 | +least I can listen to it from my room now. |
| 148 | + |
| 149 | + |
0 commit comments