Repurposing an old Android phone as a web server
lbrito1.github.io
lbrito1.github.io
Apparently some manufacturers put the phone's NFC coil inside the battery instead of on the phone's back housing, so there could be a fourth pin for that. Or perhaps the battery contains its own microprocessor that answers a DRM challenge from the phone specifically for the purpose of blocking out third party battery manufacturers. Etc. etc.
Still there is the problem that the phone might have peak power usage above what its charger can provide, so you'd have to use a wall adapter with a higher amperage rating.
Ah yes, good old anticompetitive practices. Sleep well, FTC.
Now you have to have an extra decision circuit that judges whether or not the wall is "good enough to boot the phone" and then ask if it's good enough to run it as well. Last thing you want is wall power to dip randomly and you can't switch fast enough and simply shutting off.
I understand why you would pick the battery as the requirement. You know the exact behavior of when the phone is safely bootable vs not w/ a predictable DC signal.
You can throttle the CPU. In fact you should, especially if you expose it to the public, to prevent it from overheating.
To rephrase your question:
Could we build a new phone that runs off a 80..120 W charger without battery? Absolutely yes.
Will it help older phones that were not designed to use such a charger? No, most likely that charger will change nothing.
I got a few cheap power point timers, and set them to only charge for 1 hour twice a day, and we didn't have a battery failure in the 3 years after that while I was still there.
(Totally agree with the rest of your comment too...)
I forget when, but in last ~3-5yrs, I've noticed iOS seems to handle this. If you leave a device plugged in for a long period you eventually getting a notification saying it's not gonna charge as much, and it caps the max battery to 80%.
Just wondering if your story is before or after that feature.
edit: I googled, it was iOS13, so 2019 - https://support.apple.com/en-ca/HT210512
Then again, why would they? The faster the battery goes the sooner the end user will have to either replace the battery (which is almost impossible with phones these days) or ditch the old phone and get a new one.
Uptime has been really good, only downtime I had was when my wife disconnected the phone a couple of times and forgot to plug it back. Even when I moved a couple of months ago, the battery held, and downtime was basically just the time between disconnecting old wifi-reconnecting new wifi in new place.
---
1. https://wiki.termux.com/wiki/Main_Page#:~:text=do%20not%20in...
[1] https://www.xda-developers.com/termux-terminal-linux-google-...
That sounds fine/good for like 98% of extensions. But the other 2%... extensions like GreaseMonkey/VioletMonkey/TamperMonkey, or one could imagine something like IFTTT or PushBullet, where the extension might perhaps want some intrinsic extensibility to itself: those are all now verboten. There's not really any discussion or push/pull on the new security regimes. Computers just get more and more clamped down.
I'm interested to see how Termux goes forward. In the past they seemed to have some "in-APK packaging" notions for how to deal with Android 10+. I haven't stumbled upon a good description of what this is or how it would work, and I'm not really sure whether these ideas are still active or whether F-Droid and using ever aging SDKs is the way forward.
There are also other APIs that are absolutely verboten by Google Play but will work fine if the app is installed through alternative app stores.
More recent versions will just kill the application if they get used, and Termux folks refuse to accept that they have to go through JNI for specific OS features, so they won't be around for much longer, other than on rooted devices.
Or they might eventually accept how things are done on Android.
The official APIs are Java based, ISO C and ISO C++ standard libraries, and the NDK libraries that ship on device.
Series 30, Series 60, brew, J2ME, Psion OS, Pocket PC,....
They were never general purpose computers.
Personally I think it's hard to justify phones as something different than general purpose computers. A device that can load fairly arbitrary apps is already almost by definition a general purpose computers, it's just a matter of what has been built and/or what is allowed to be shipped, and what system resources are available (few, in many of your examples, often owing to it being the aughts). Now that the system resources are clearly no longer a differentiator, it's almost all just corporate-politics & the war-against-general-purpose-computing vested-interests enforcing the distinction.
Not everything with a CPU needs to run yet another UNIX clone.
There are plenty of computers and maker boards for that purpose.
Given that the way you say "things are done on Android" is that tools like termux don't exist, you're effectively saying they should just give up and kill the project. I understand that this is consistent with your view of the OS, but can you understand why nobody involved is interested?
I use termux to host a jupyterlab instance and bring along a tiny folding bluetooth keyboard. Even in airplane mode I can connect to the locally hosted jupyterlab instance. Notebooks are kept in git and synced up to my private repo when I'm back on grid.
There are simpler solutions for writing, but this allows me to keep a single workflow across home/travel contexts. Being able to run graphs, basic code and computation as needed is also a plus.
There was definitely some squinting at the screen involved, heh.
Couldn’t you buy a laptop with what they’d charge you for a day of work? A quick simulation here is showing me US$ 140/h for a 4 core 16GB of Ram machine, no mention of video card.
I love the digital nomad lifestyle, but at that price it’s more of a gimmick than a real choice
$140 gets you a t3.xlarge 4 core 16gb ram instance (on linux) for a whole month.
Check out the hourly price of Workspace:
https://aws.amazon.com/workspaces/pricing/?pg=workspaces&sec...
I pay for this workspace: $9.75/month-Hourly-Windows licensed-Performance-2vCPU,8GB Memory,80GB Root,50GB User
Since I'm only doing layout on an as-needed basis while hiking, rather than doing it full time, I tend to spend around $45 or less a month.
If you ever need to upgrade, you have to install from somewhere else, like F-droid
Here's the dynamic DNS plugin: https://github.com/mholt/caddy-dynamicdns -- it will just update the A records for your domain directly with your DNS provider, no need for a third-party service.
The device connect remotely to a server that you control and give access back to you.
Or setup wireguard and forward PUBLICIP:PORT to PHONE_WG_IP:PORT
I actually moved away from DDNS after a while because I moved and my new ISP had CGNAT. I posted about it here https://lbrito1.github.io/blog/2020/07/replacing_google_anal...
The part about them immediately receiving 'attack packets' made me realise that I am quite ignorant about the realities of web security. It is eye opening to me that a lot of web traffic is malicious.
Are there any 'security hardening your server 101 for n00bs' resources? It should be useful for any of these 'phone servers' as well (preferably tool agnostic)
I ran a web forum for years, either on PhPbb, or YAF.net. Never got compromised. Constant, round-the-clock attacks though.
I think the ultimate saving grace is that the site didn't contain anything of interest - it wasn't selling anything, so no stored credit cards. No digital goods to steal, no public forum topics which relate to videogames, politics, etc. It was a small forum for friends of mine, so there was no obvious community anyone wanted to ruin.
The worst we got, was some spam bots once in a while would breach the captcha, and start posting ads. Easily fixed. Not a hack, per se, but neither benign. I don't think we ever attracted the attention of a human hacker, and that's likely why we never got breached.
You could read about them as they were published/fixed.
What makes you 100% sure you would have figured out?
I've never felt comfortable with that argument
Yes, if you are a big corporation, and you have many employees with eyes on the code, there's no obscurity when an employee goes rogue, you are wide open.
But if you are the only person with access to the code, obscurity works
I only think it can work for very small teams with high trust
The truth is that hiding source code is the security barrier for most proprietary software and nothing else.
you should work from the assumption that ALL network traffic is malicious.
At least some traffic is expected to be valid, but the majority will not if internet facing.
Google “Linux hardening for beginners hacker news” there are articles with easy steps and thoughtful comments from time to time.
I'm not sure why you're saying that like it's ridiculous, it's just plainly true.
If you assume that it is all malicious, (and much/most of it is), you stand a better chance of fending an attack.
My personal recommendations, ordered by importance, sort of, maybe:
- Minimize attack service: don't install it if you don't need it
- Assume you'll be compromised at some point. NSA servers get hacked. FSB servers get hacked. You're not better than them. Think of what you'll do when you get hacked: do you need to rotate keys, change passwords, delete tokens? It's better to have a plan, even if it's a vague idea, just in case.
- Think about who might hack you, and how. Are you an activist? You may have opponents that want to attack you directly. Are you just some guy with a blog? Focus on defending against your most probable attackers, like botnets and automated scripts. You can make grand plans for when the NSA tries to break into your secure server network, but in practice you should probably be fine if you just defend against botnets. You can find entire threat analysis guides on the internet but a quick think about "who will attack me why and how will they do it" will probably do.
- You probably won't get hacked. Don't become too paranoid; just taking the bare basic steps to prevent getting hacked will make you more secure than millions or even billions of hosts on the web.
- Install software in a way that automatic security updates will take care of common vulnerabilities (i.e. prefer apt-install over ./configure && make && sudo make install or curl | bash).
- Check how quickly your upstream sources (Termux, in this case) are issuing patches. I haven't checked Termux' security stats myself, but I'd personally try a Debian chroot over a Termux environment just because Debian has more funds available to provide timely updates.
- Principle of least privilege: barely anything needs root anymore. Ignore outdated guides and use separate users (or even random user IDs with systemd), it'll probably work. If your server provider gives you a root account, create a normal account, give it sudo permissions, and disable remote root login; root should only be for system maintenance and repair!
- Read the manual for suspicious config you copy/paste. Sometimes config is just data (hostnames etc.) but sometimes config disables or overrides default config; for those cases, think "why is this not on by default"
- When in doubt, update. Auto-update if you have to. I've run sudo apt update && sudo apt upgrade -y" in a cron job for years but there are better options for most server OS's. On Ubuntu (and probably Debian) run sudo dpkg-reconfigure unattended-upgrades to configure automatic security updates
- If you do install stuff manually (downloading a binary, curl2bash, etc.) then find out how to update such software and think of ways to automate the process
- Listen to warning messages. For example, many old Ubuntu guides will have you add PPAs in a manner that will give the security keys of a PPA the ability to sign packages from the main system repos. You'll get warnings if you use this method on a modern system and you should probably heed those.
- Reboot your server after important kernel updates. If you can afford the downtime, reboot after every update just to be sure; if you can't, check if any important patches were released during the past few days. You can often monitor the reboot status file (/var/run/reboot-required, for example) to see if a reboot is necessary.
- Make sure your services come back up after a reboot. One of my servers has a nasty firewall configuration bug somewhere that I haven't been able to track down that causes the firewall to refuse to start on boot. Better to find out that your server isn't reboot safe during a planned maintenance window than when you need the service and it suddenly stops working!
- An important file doesn't exist unless it's at three places, at least two which are in a different geographical location. Make backups!
- Test if you can recover from backups. An untested backup is a non-functional backup.
- Back up recovery/security keys to a safe location. Your fancy, unbreakable hard drive encryption is useless if you forget your password!
- When using Docker, make sure to update regularly. It's very easy to deploy a docker application and forget to update it for years!
- Even if nothing is going on, log in every now and then and check how your server is doing.
- Keep an eye on exploit/security lists for software that you expose publicly, especially if you're not updating them automatically. There are websites that will list all important new vulnerabilities for only certain projects (I use the RSS feed provided by the Dutch government, but others likely exist).
- When you see your server might be vulnerable, don't panic. Vulnerability descriptions often start with "an unauthenticated user may execute code and take over the system and turn the sky red and..." and end with "if the administrator has enabled the enable_apple_II_compatibility setting". For example, the Samba/SMB bug that allowed code execution on NAS devices only applied when the optional AppleTalk extension was enabled, which was commonly disabled by default.
- Did I mention updating? You'd better update! Did you update? Good, then you're probably fine!
- Install a firewall. The Internet may tell you that you need to learn nftables but in practice tools like `ufw` will protect you just fine. Work in whitelist mode for incoming traffic. Work in whitelist mode for outgoing traffic if you want to spend an hour every week debugging why your server went down again.
- Pick good passwords, or even better, don't use passwords at all. Use key based authentication for SSH, use WebAuthn/U2F/whatever for admin panels, make it as hard as possible to brute force your way in. Don't reuse passwords! You don't want to get hacked because your password showed up.
- Keep an eye on risky software. For example, WordPress itself is quite secure, but many of its plugins have been plagued with vulnerabilities.
- Make maintenance/updating your services easy. Sometimes that means you need to spend more time setting everything up. Sometimes that means configuring your system in a suboptimal way, or even disabling other security features. Locking everything down can make it impossible to properly update your software and software you don't update is just waiting to get exploited by a bot.
- Not a security measure per se, but useful to reduce log spam: change the SSH port from 22 to literally anything else.
- When serving anything UDP (DNS/SSDP/whatever) make sure to check if there's a DDOS potential and see if you can mitigate it. If you can't, see if you can whitelist destination/source IPs in your firewall.
- HTTPS is free and quite easy. Why not enable it? If you turn it on, you can use "outdated" security mechanisms like HTTP Basic Auth without hesitation!
- Make sure to migrate in time when a software package gets out of date. Ubuntu 18.04 will receive updates for years to come, but you should probably plan to migrate two years before the end date. The longer you wait, the more difficult migration will be, the longer you'll put it off and the more likely you'll run vulnerable, outdated software.
- Hack yourself. Run port scans against your own servers; you might just find that you forgot that Docker will bypass your firewall. That's how I found out! I've accidentally had stuff running publicly that should've been private for months because I didn't port scan after installing new software. Other tools include stuff like wordpress security scanners, OWASP ZAP, etc.
- Sometimes you'll find yourself in a tricky situation: one of your services is vulnerable but no update is out for your platform yet. Consider temporarily disabling the service if it's not _that_ important or restrict your firewall to accept only certain IP addresses if you can't live without it.
- If you're only going to use the service yourself, you might not need to expose it to the internet. Maybe you can use a VPN to only allow trusted devices to connect. Maybe you can use Tor to make a service available (from behind NAT, even!). Never fully disable authentication and such on trusted networks unless you don't care about getting hacked, though.
- If you feel like the software you're running may be a common target, read your web server logs. See if you're getting flooded with weird requests and Google the URLs to see if you might be vulnerable.
- Periodically check if software you've installed is no longer necessary. Removing unnecessary attack surface not only makes your server more secure, it'll also help you keep down the amount of maintenance you need to do!
- Install security updates. Really, that's maybe the most important part, after picking good passwords. An updated server is a happy server. In most cases, an updated server is an unhackable server!
- Don't fall for emails like "I found a vulnerability in your server, do you provide a bug bounty".
- If you write your own software, regularly update dependencies and run vulnerability scanners (preferably automated). Stuff like https://owasp.org/www-project-dependency-check/ isn't hard to integrate into your workflow and might warn you of vulnerable libraries you didn't even know you used!
- Terms to throw into Google if you're interested: WAF (Web Application Firewall), Fail2ban, Tarpit (networking), cgroups, systemd hardening, snort, suricata
Finally, for your personal devices: use a password manager with a Really Good master password and enable 2FA. For most services a good password is a password you don't know. Use software that's as convenient to use as possible without sacrificing security (i.e. use a password manager that integrates with your phone's/browser's autofill). Stuff like WebAuthn/U2F/FIDO2 can make 2FA very usable without having to copy a bunch of numbers every time you log in and they're available on more devices than you might think. You can go ultra secure (I, for one, enabled 2FA on SSH at some point) but the harder you make it for yourself, the less likely it is that you'll find yourself using your fancy security.
Some people will probably disagree with me on some points. Some of them are overkill, some of them are not strict enough. There's no one true answer for any of this, because every server is different and has different security requirements.
In case you feel overwhelmed: what I just typed out isn't followed by (way too) many companies. If you work outside a tech company I doubt the IT departments/people even know what company secrets are on what server. Companies will silently or unknowingly run vulnerable software for years without getting hacked! Your home server may be more secure than a critical application server that some Fortune 500 company relies on, simply because you can run updates and they're stuck with some outdated OS/software/hardware/network/configuration that they can't move away from without spending millions!
You'll want to be basic security knowledge for whatever services you are using, but being safe from these kinds of attacks really only requires the absolute minimum.
Connecting fail2ban notifications to your telegram gives you a new perspective on how bad it really is :)
https://rodolphoarruda.pro.br/ideias/#202206MESH (Portuguese)
also mentioned at https://news.ycombinator.com/item?id=27576120#27578301
and related https://news.ycombinator.com/item?id=31325191#31325561 (laptop)
Also, an alternative to termux, https://github.com/CypherpunkArmory/UserLAnd found https://news.ycombinator.com/item?id=30119029
¹ This is probably why you should not cut off the battery plastic sealing like some DIY guides tell you to do, it's probably there for a reason.
Wait, what? What is the purpose of that advice?
Some good phones will even notice that they are plugged in all the time and drop the charge level to 80%, where most batteries are happiest to stay for long periods of time.
Once you shiv systemd, some pretty elaborate scripts can run in an Android chroot just like they would on bare-metal ARM. Just think of your old Android as an off-brand rPi with case, built-in touchscreen LCD, and way, way fewer GPIO pins. No surprise the server will need a new UPS battery.
NextCloudDroid: https://github.com/DesktopECHO/nextcloudpi Pi-hole for Android: https://github.com/DesktopECHO/Pi-hole-for-Android
I have a bunch of old Android phones kicking around that I'd like repurpose for random IoT/monitoring things but I don't trust them to stay "on" all the time. And Raspberry Pis are pretty cheap, so...
Then my cyberpunk dreams can be made manifest!
- Lineageos supported
- mainline linux 5.17 supported (except for the camera for now)
Your suggested alternative increases e-waste unless one specifically hunts for secondhand chips.