No description
Find a file
2024-01-28 14:14:17 +01:00
diagrams add drawio diagram 2024-01-27 14:55:50 +01:00
pics update readme 2024-01-26 17:54:50 +01:00
tests move ticket to session 2024-01-27 13:43:01 +01:00
types add stream_head_t from pdf 2024-01-27 16:23:22 +01:00
.gitignore js craziness 2024-01-25 00:11:58 +01:00
.mocharc.json add SendUsrChk and test it 2024-01-25 10:09:41 +01:00
.prettierrc.yaml add max line length config 2024-01-20 18:44:05 +01:00
a.js input as a stream-ish 2024-01-28 14:14:17 +01:00
datatypes.ts move data types 2024-01-26 17:47:37 +01:00
dissector.lua add cmdtype and encrypted 2024-01-26 00:41:04 +01:00
frida-hooks.js small cleanup 2024-01-26 17:47:41 +01:00
func_replacements.js refactor a bit more 2024-01-26 17:36:06 +01:00
handlers.ts emit connection event 2024-01-27 21:27:12 +01:00
hexdump.js refactor code 2024-01-26 17:21:38 +01:00
impl.ts move ticket to session 2024-01-27 13:43:01 +01:00
loader3.py load bundle 2024-01-18 12:34:39 +01:00
Makefile small cleanup 2024-01-26 17:47:41 +01:00
package-lock.json start encoding a frame to video 2024-01-27 22:55:31 +01:00
package.json start encoding a frame to video 2024-01-27 22:55:31 +01:00
proto add braindumps 2024-01-26 17:49:36 +01:00
README.md add audio support 2024-01-27 16:24:35 +01:00
server.ts emit connection event 2024-01-27 21:27:12 +01:00
shim.ts refactor code 2024-01-26 17:21:38 +01:00
tsconfig.json upd config 2024-01-25 00:18:18 +01:00
utils.js fix printf to include trailing content 2024-01-26 17:25:17 +01:00

Re-implementation of the "ilnk" protocol used on some cheap (<$5) IP cameras (sometimes branded as 'X5' or 'A9').

Per pictures the main chip is TXW817 (chinese, eng, google translate)

The interesting implementation is in libvdp.so, part of the apk bundle.

Protocol reversing was done with a combination of static analysis of the shared object with Ghidra and dynamic analysis with Frida.

The headers reversed with Ghidra are at types/all.h. They are almost not used by this minimal implementation though.

The hooks used with frida are at frida-hooks.js, but it's mostly a playground - some useful functions got deleted once I understood the protocol.

There's also a pretty crappy Wireshark dissector at dissector.lua. You can install it with make install-wireshark-dissector.

Running

To execute the server, run make run; JPEG files and audio.pcm will be created in a folder named captures.

There's no live-stream server built into this project yet.

Protocol

The protocol is weirdly complex, though very little communication is necessary to use the device

The base structure of a packet is:

The payload is command-dependent; most commands have only a literal payload, but the Drw (0xf1d0) command has a framing scheme:

By using the second byte in the payload as a discriminant, we can split the payload into two types of subcommands:

Control packets:

The payload on control packets is "encrypted" when the length is > 5.

Data packets:

Data packets further discriminate based on the first 4 bytes into: Audio Data (0x55aa15a8), Video data.

Session

To establish a session, a few control packets are sent.

---
title: Establish session
---

sequenceDiagram
	autonumber
    App->>+Cam: [C] LanSearch
    Cam->>-App: [C] PunchPkt (SerialNo)
    App->>+Cam: [C] P2PRdy
    Cam->>-App: [C] P2PRdy
    App->>+Cam: [C] ConnectUser
    Cam->>-App: [C] ConnectUserAck (Ticket)
   
   loop Every 400-500ms
        Cam-->>+App: [C] P2PAlive
        App-->>-Cam: [C] P2PAliveAck
    end

To start a stream, a single control packet is sent.

The received stream is broken up into 1028 byte payloads, along with a sequence number.

Stitching the payloads together yields JPEG frames for video, and 8KHz A-law PCM for audio.

---
title: Stream audio/video
---

sequenceDiagram
    App->>Cam: [C] StreamStart (with Ticket)
   
   loop
        Cam-->>+App: [D] Audio/Video Payload
        App-->>-Cam: [C] DrwAck
    end

Take APK from emulator/sacrificial device

adb shell pm list packages | grep ysx
adb shell pm path com.ysxlite.cam
adb shell pm path com.ysxlite.cam | while read -r line ; do adb pull $(echo $line | cut -d: -f2-) ;  done

Push to sacrificial device

adb install-multiple *apk

Frida install Android

docs