I wanted beta features. I got a bot farm.
An LSPosed module that switched on Instagram's unreleased features, then grew a certificate-pinning bypass and a command server inside the app, which is how a bot farm starts.
Instagram ships a lot of features long before you can use them. QuickSnap, the Friend Map and Community Notes were already inside the app on my phone, behind feature flags that stay off until Meta turns them on for your account. I didn't feel like waiting for my turn, and with LSPosed, which lets a module hook into an Android app's code while it runs, I didn't have to.
Finding the switch
Every flag in the app goes through one lookup. The app asks its config for a boolean by a 64-bit id, and the answer decides whether a feature exists for you. The id packs the parameter's type, its config and its number into one value. My module hooks that lookup and answers true for the 23 ids I pulled out of the app's code. Restart Instagram, and the hidden features are there.
Finding it again after every update
Switching the flags on was the easy part. Keeping them on was the real project, because Instagram is obfuscated with R8, a tool that shrinks an app and renames its classes to short names that mean nothing, like a, b and, on a creative day, aa. The class that does the lookup gets a new name in almost every update, and a hook that looks for it by name breaks with it.
So the module goes looking for the class itself on every cold start. It parses the strings table of the app's dex file, the file that holds its compiled code, scores the candidates and picks the best one. The answer is cached under a checksum of classes.dex. A new version of Instagram changes the checksum, so the module notices an update before I do.
Switching off pinning while I was there
With the hooks in place, certificate pinning was the obvious next thing to switch off. Pinning means the app trusts only the certificates it expects, so a proxy can't read its traffic even when you install the proxy's certificate on your own phone. Instagram checks certificates in eight separate places, from its own trust manager down to a native verifier. I respect the thoroughness. The module switches off all eight anyway, and then mitmproxy, a proxy that shows every request passing through it, could read the app's traffic.
A server inside Instagram
In that traffic, every request came out of one factory, an object tied to the logged-in session that builds each request. So I hooked the factory and kept a reference to it. Then I opened a TCP socket inside the Instagram process, forwarded it to my computer with adb, Android's debugging bridge, and wrote a small Python client to talk to it.
A like, a follow or a message sent that way rides Instagram's own request pipeline, with its real signature and session. As far as the server can tell, my thumb did it.
GraphQL needed a different trick. Building the app's GraphQL request objects myself from Java crashed the whole process. So the module records each live query by name as the app sends it, and replays it later with new parameters. It can only make calls the app has already made at least once, which turned out to be enough.
The bot farm
Then the Python client learned to drive several phones at once. It got an action queue that waits a random time between actions, and a rate limiter with separate budgets for writes, reads and searches. At that point I looked at what I had, and it was the base of a bot farm. I had started all of this because I wanted QuickSnap. I stopped there, and the source stays private.