bahamas10 / unifi-proxy

a hack to allow direct connections to unifi protect on a different layer 3 network
60 stars 8 forks source link

Android mobile app #1

Open rick51231 opened 2 years ago

rick51231 commented 2 years ago

This bridge work fine with iOS app, but android requires that packet src ip should be equal to unifi ip.

Workaround for me is to use nemesis ( https://github.com/libnet/nemesis )

//Save raw packet at start
fs.writeFileSync('unifi-server.packet', message);

socket.on('message', function (msg, rinfo) {
// ...
exec("nemesis udp -c 1 -x 10001 -y " + rinfo.port + " -P unifi-server.packet -S <controller ip> -D " + rinfo.address + " "+(rinfo.address.indexOf('172.19.101')==-1 ? '-d ens192' : '')); //-d used in case of multiple network interfaces

This code work fine with both apps via wifi. It is also possible to connect remotely via vpn (WireGuard for me), but only from android and you should be connected via wifi (e.g. from another smartphone).

copart commented 2 years ago

@rick51231 Any chance you can include a diff?

It appears you modified server.js

However, unsure what

// ...

Is meant to represent. What was commented out?

shin-kamui commented 2 years ago

Thank you for this tip @rick51231 . I was able to get it working after a few minutes using nemesis on my android clients. Silly that ubiquiti doesn't just add a direct ip field and use certificate pinning to secure it.

rick51231 commented 2 years ago

@copart Sorry, did not see you message. I've made a pull request with nemesis code in #3

@sntiforo I've made some reverse engineering of android app and it's easy to fix direct connection ability, but they have multidex in a app and idk how to recompile it back from decompiled one.

copart commented 2 years ago

@rick51231 Thanks for the fix, it worked!

However, I really hate that Unifi does not have a way to just direct connect, it knows the IP of my cloud key!!! Crazy.