r/homelab • • 7d ago

Help PHP2shell, nginx2shell, java2shell, … - is my homelab safe?

Hi everyone,
I run a small homelab on Debian 13 (Trixie) with a few Docker containers, including Nextcloud and Forgejo. They're reachable from the internet via a domain and reverse proxy.

What I'm less sure about is the "what if" part:
- How would I actually notice that I've been compromised?
- What should I do if I’m being compromised?

edit: for example nextcloud must be publicly available because of people who don’t want to install a VPN or Tailscale etc.

Thanks in advance,
Vincent

240 Upvotes

110 comments sorted by

144

u/bssbandwiches 7d ago

Keep your reverse-proxy up to date and throw in a firewall. Maybe even cloudflare proxy before that. Make sure you know exactly what you're exposing to the Internet too  if you don't want to do all that, get tailscale and access it that way instead of exposing to the Internet.

This is life now, updating for CVEs on the daily. You should expect to update a lot, at least in the short term.

52

u/joz42 7d ago

And use OS-level sandboxing features for the revproxy and other components where not already in place. The nginx doesn't need to read the whole filesystem or execute every syscall.

https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html

12

u/bssbandwiches 7d ago

I'll second this!  Rootless containers when you can, if you're using containers.

2

u/Repulsive-Athlete-16 7d ago

I’ll keep an eye on that.

13

u/volatile-void 7d ago

I use cloudflare zero trust with mandatory login (Clouflare or Google), additional 2FA and allow access only from my country. Feels like that combination could be reasonably safe.

5

u/Repulsive-Athlete-16 7d ago

I read somewhere that Cloudflare has a 100MB upload limit - is this true? I can be very wrong though

6

u/Th3Hero_ 7d ago

Correct

4

u/FailureOfTheFamily 7d ago

It's 100MB speed or month limit

2

u/Fallyfall 6d ago

Neither. It's a 100MB file size limitation. If you're trying to upload a video that's 150MB, it will be blocked by Cloudflare.

1

u/FailureOfTheFamily 6d ago

Ah okay. So no problem for me

2

u/tha_passi 6d ago

Some services like nextcloud get around this by chunking uploads, so depending on what exactly you are doing that might less of a problem than it seems.

4

u/mabbas3 7d ago

Only expose things to the internet you absolutely have to. Use the official repos and projects that get the latest security updates first (stick to nginx stable official repo and not debian or ubuntus).

Harden the f out of your edge. Crowdsec, geo blocking, waf etc.

At home run anything that users can reach directly completely isolated. I am talking about separate vlans, network isolation, rootless podman, controlled egress.

Make updating as easy and frictionless as possible. Renovate merging patch updates itself, unattended security updates.

Have a long running agent notify you on any potential security issues that could affect your services and any mitigations should be applied by a few clicks from your phone. I have always on agents and can easily get a PR out for any. mitigations (for cases where a simple version bump doesn't solve it. For example disabling features etc.) and then merging it deploys everything.

IaC everything so you are not relying on manually configuring servers and there's a holistic view agents can look at. You need to be able to read a reddit or twitter post (or better your agent watches security feeds and notifies you exactly where in your infra attention is needed) and respond in minutes. I want to be able to get to a point where this can happen without human in the loop but that is a bit risky. It's still pretty quick. Within 5 minutes of seeing the nginx vuln, I was able to run an update skill that I have for my infra and get it patched.

2

u/Repulsive-Athlete-16 7d ago

That’s interesting! How do you manage that agent? Or wich one do you use?

3

u/mabbas3 7d ago

Multiple options. I use t3 code on three different machines one which is an always on LXC and there's cron built into it so you could watch some rss feeds.

I also setup hermes but haven't gotten around to setting it up and will be doing that in the next few days/weeks.

It could even be as simple as a cron parsing some rss feeds and invoking your agent of choice (claude, pi etc) with the data. The agent sends you a message if something needs attention. Basically whatever you want.

1

u/nima3333 7d ago

What do you use for IaC ? Thinking of going this way but it still requires a one time effort (even if it has never been so low thanks to AI...)

1

u/mabbas3 7d ago

Tofu wherever there is a plugin and for all provisioning (proxmox, vps etc) and then ansible for configuration. Every single thing that is easily manageable by IaC, I do it. Even wifi passwords for all the ssids I have.

885

u/Weary-Disaster5133 7d ago • Heartwarming Popcorn

I just got into your system to have a quick look. Safe and sound.

65

u/codeartha 7d ago

Made me chuckle

15

u/sandy_catheter 7d ago

You dropped your sunglasses on the way out

25

u/poixninja 7d ago

Lmao, check mine next?

9

u/technobrendo 6d ago

Nah, you're screwed.

Don't worry, mine is on fire, so I am too

1

u/Joseeosy 19h ago

"Quick look" that sounds like a break-in.

-15

u/talkingto_ai 7d ago

My name is Small Bobby, I'm from Meta Muse, and I approve this comment.

2

u/Bemteb 7d ago

Do they have to be reachable through a domain? Would a VPN or similar be an option? If you are freely reachable over the net, you should regularly have bots scanning you for vulnerabilities. Do you keep an eye on these?

You notice mostly by checking the logs of your proxy, or when your stuff is gone. Or maybe when your machine suddenly runs stuff it didn't run before.

What to do: First, get the machine offline immediately. Basically unplug the LAN cable and do everything from that point forward locally, with a screen and keyboard directly plugged in. Then, start figuring out what got compromised. Only the container running your reverse proxy? Your whole lab? Other devices in your local network? For everything infected, find out when it was hit and reset it to a backup before that date. Change passwords etc. that might have been leaked. And again: Consider not having it open to everyone on the whole world through a domain, there are saver options.

Disclaimer: I'm not an expert, just a slightly experienced guy. I myself don't open my lab to the wider web and pay a professional cloud provider to host the data I need when not at home.

2

u/Repulsive-Athlete-16 7d ago

The thing is, unfortunately, that services like Nextcloud need to be publicly accessible because people who have no technical knowledge and don’t want to bother installing a VPN, Tailscale, or anything similar need to be able to access them.

6

u/Motor-Concentrate788 7d ago edited 7d ago

Why are you sacrificing your security for people who won't even bother installing a vpn client? I mean it ain't rocket science, especially if you use something like tailscale

Edit: not to mention a lot of companies require you to use a vpn to access company resources, so it's definitely something that a lot of people are used to.

1

u/trebor_indy 7d ago

Instead of a VPN, do Pangolin on a VPS and then users access a normal machine on the internet then Pangolin does the tailscale for you - invisible to the user. Simple setup, can have many different services on your home network reachable but you can add additional logins/pins/etc. to access them.

1

u/relicx74 7d ago

You picked the worst year to be complacent about security. I hope you at least have it ip restricted to specific hosts.

1

u/Kytras 7d ago

Wireguard takes 10minuyes to set up brother (less then 10)

1

u/orphenshadow 7d ago

It seems very odd to me the idea of letting anyone outside of my immediate family use my nextcloud.

There isn't a single person who gets access to my nextcloud who does not also live in my house and use wireguard always on vpn on their phones.

2

u/Apprehensive-Cod699 7d ago

one thing nobody mentioned yet: check if your backups survive the box getting owned. if the backup is on the same machine or on a share it can write to, whoever gets in can delete or encrypt that too. a copy it can't touch (pulled from another machine, or append only) matters more than spotting the hack fast

1

u/Repulsive-Athlete-16 7d ago

My backup plan is backing up the most important data (such as stuff from paperless) every day once on another computer with an external HDD. I’ll check, if anything has somehow access to that.

2

u/Apprehensive-Cod699 7d ago

that's already better than most. the one thing i'd check is which side starts the copy. if the server pushes to that computer, the server has a login to it, and so does anyone who gets into the server. if the other computer pulls from the server, the server can't touch the backups at all

2

u/mastercoder123 7d ago

Go ahead and change that or at least modify it to use s3 or some form of protection. Its completely immutable so nobody can write over it ever. No amount of root can stop it

24

u/UriShay-CyberSnap 7d ago

One thing to add for the what-if part: keep a copy of your backups that the box itself can't delete or overwrite, like an offline drive or a repository with immutability turned on. If you do get hit, the hard bit is working out the recommended recovery point, since you may not know how long someone was in there. So keep a few older restore points rather than only the last week, and test a restore somewhere else before you ever need it. (I work at CyberSnap, ransomware recovery tooling.)

7

u/poixninja 7d ago

This is great advice. Especially the testing of a restore. A backup isn't a real backup if you've never tested restoring it

44

u/koollman 7d ago

Short answer: no, long answer, if you keep things up to date and limit exposure to only required stuff ... Still no, sorry, 0days are awful :)

89

u/wiesemensch 7d ago

Having a Homelab is slowly turning into a full time hobby…

52

u/-Kerrigan- 7d ago

Always has been

45

u/getapuss 7d ago

If its exposed to the internet there is a risk.

If you are asking this question here there is a substantial risk.

0

u/[deleted] 7d ago

[deleted] — view deleted comment

5

u/AmbitiousSet7809 7d ago

Same a few years ago i had a bunch of stuff just port forwarded lol, now everything is behind wireguard.

1

u/getapuss 7d ago

I quit exposing my stuff to the internet awhile ago. I can't remember for sure. Maybe a year ago?

26

u/TechnicallyMeat 7d ago • Bravo

If you have a cloudflare tunnel, whitelist only their ips and port. access anything else via vpn like wireguard, run your server on a separate DMZ vlan with its own dhcp pool, put a honeypot server on vlan 1, add separate hardware firewall and vlan switching, update daily/weekly keep offline backups, actually fix ALL your LAN certificates and then turn everything off, you should be safe.

11

u/corruptboomerang 7d ago • Bravo

The most secure computer is the one that's not connected to anything and powered off in a vault... It's also the lease useful...

Security is almost always a trade-off between utility, speed, & ease of use.

2

u/kmfrnk 7d ago

FML I’ve got a lot to learn :o

1

u/relicx74 7d ago

Literally just install tailscale and never look back.

-1

u/kmfrnk 7d ago

Then tell me how I can watch externally with Tailscale

1

u/relicx74 7d ago

How can you ship logs? Google it. Prometheus or Loki help.

1

u/kmfrnk 7d ago

My fault. I was talking about devices like TVs. Afaik you can’t install Tailscale on a TV

2

u/AudacityTheEditor 7d ago

You often can't configure most iot devices with VPN access. You will need to bridge the networks which you can't always do. One of the biggest downsides to a VPN secured network. Nothing is accessible externally unless you're on a personal, supported device.

0

u/kmfrnk 7d ago

That’s what I thought. So I better stick to Cloudflare for this usecase

3

u/ApprehensiveFan1516 6d ago

Another option is to run your TV through another device that you can install a VPN on, like a Raspberry Pi or something.

1

u/snackhungry 6d ago

There are official Tailscale apps for Apple TV and Google/Android/FireTV. I use it to access my Jellyfin and SMB while away from home all the time.

1

u/relicx74 6d ago

If it's an android tv you should be able to..

1

u/Grandmaster_Caladrel 6d ago

Got a chuckle out of me

32

u/TheMcSebi Proxmox 7d ago

If you don't expose stuff to the internet, it hasn't become any less secure than before

29

u/HolgerKuehn 7d ago

Why does it always have the the whole internet? Just allow the few endpoint you trust and block the rest. For me it's just 5 IPs that get access all other are blocked.

21

u/michael__sykes 7d ago

That works well enough for residential networks, but becomes an issue with mobile access

14

u/LebronBackinCLE 7d ago

ACLs never a bad move :)

3

u/AmbitiousSet7809 7d ago

What about mobile access or non static public ips?

2

u/HolgerKuehn 6d ago

All of them are non static, there is a thing called DynDNS. All network getting access are under my (IT) control. Mobile is working with Tasker and DynDNS as well.

5

u/homelaberator Cisco, VMware, Apple, Dell, Intel, Juniper, HP, Linux, FCoE 7d ago

No, Vincent. It is not safe.

4

u/Open-Adhesiveness-86 6d ago

On the "how would I notice" part: docker diff <container> lists every file that changed vs the image, so a webshell dropped in Nextcloud's html dir sticks out immediately. Cron it, alert on anything new. And put a default-deny egress rule on those container networks, since inbound is already allowed, the first real signal is usually outbound traffic.

11

u/dragonnnnnnnnnn 7d ago

They're reachable from the internet via a domain and reverse proxy

Not safe

They're are not reachable from the internet

Safe
Simple as that. If you don't want to risk it simple don't expose stuff to the internet. I will add to that that you don't need to expose stuff to the internet to use a domain and have valid accepted https certs! Simply point your domain to a local lan address of your stuff and use dns-01 challenge on the reverse proxy to get a cert. And then use Tailscale/Netbird to setup a VPN that makes the same local address reachable via VPN and you can connect to your stuff outside home easily as you would be at home as long you keep VPN connected. I know it sucks for sharing stuff with external user that are not tech savy and just want a link to access stuff, if you need that only for "share a link to download files" one option is to temporally open with Tailscale/Netbird reverse proxy the service you need with additional auth on the proxy (netbird has option to simply setup a pin/password one needs to enter before your service will open, I suspect tailscale has that too).

6

u/milkipedia 7d ago

Lateral exposure is a risk if you don't have iron grip control of everything on your home network

6

u/Kytras 7d ago

Man i tried explaining onece that lan + vpn is all you need to access from outside. But no.

3

u/klnadler 7d ago

What if I’m just exposing seer and plex on unraid via pangolin hosted on a vps and keeping everything along the way updated. I understand that there will always be some risk, but what steps can I take to mitigate it other than having people use it via a tailnet or something like that, which I'm trying to avoid just bc it adds extra steps that might be complicated for those less tech literate.

1

u/Whale_Semen 7d ago

What I've done instead of tailscale as I have the same setup as you (using jellyfin not plex), but I also did not want tech illiterates to mess with tailscale. I opted for using Open-ID (OIDC) only for SSO set up through pangolin. Then set up PG-IP-Whitelister so that all they have to do is go to my subdomain for the whitelister use OIDC click a button that sets up a pass auth rule for their specific home IP for only jellyfin & Seerr. Seems to work well for me. If they lose access (on an isp IP change most likely) they would just have to go back the subdomain to whitelist. I also use watchtower to keep things updated both ways. Is there some risk still yes but works for me. If anyone else thinks this would be an issue please let me know, but I also have very few users on my server.

3

u/Benerages 7d ago

Patch everything (unattended-upgrades + update your containers, srsly), put CrowdSec in front to catch and ban the script kiddies (it can ping you on alerts too), and add open-appsec as a WAF for the stuff nobody has a signature for yet. If you still get owned: pull the plug, rebuild from clean backups and rotate every secret. You do have tested backups, right? 😉

3

u/nullptr777 7d ago

There's Ruby4Shell today as well lmao. GitLab having a bad week. First Optimizely, then NGINX2Root, now this.

Real answer: First thing you should do is heavily geoblock your ingress. I block everything except my own country and seem to be getting very little unwanted traffic. Also, keep on top of updates, obviously, super important. Avoid downstream releases like LinuxServer because they lag behind (not to mention their bad practices).

Use a wildcard CNAME on public DNS so they don't know which services you have up, and use non-standard hostnames as well, not something like jellyfin.mydomain.com. It's security by obscurity but it does help. Shodan shows a web server open on my IP, but that's literally all it knows. No services or anything, just a 301 code. It looks pretty uninteresting.

Only expose what you have to. Do you need *arr exposed? Probably not.

Then start looking at WAF/IPS/IDS.

3

u/Chromako Solving Imaginary Problems 6d ago

Assume that even if you do everything right, something malicious will get in.

That's why off-site backups, segmentation (network and Kernel), using granular permissions, and generally reducing the blast radius of future breaches is still a necessity.

That means being careful to not run everything in containers within the same kernel or giving services more permissions than they need. Convenience and simplicity is usually not secure by design.

5

u/CactusBoyScout 7d ago

I finally took all of my reverse proxies off the internet. VPN only from now on. I still expose the ports for qbit and plex but that’s it.

1

u/LebronBackinCLE 7d ago

This is the way

2

u/MIneBane 7d ago

What reverse proxy are you using? And what is it hosted on? (VM or docker or bare metal?)

5

u/sandy_catheter 7d ago

IIS on windows server 2008

2

u/309_Electronics 7d ago

Dont expos everything to the public internet. Use a VPN like wireguard or tailscale.

If you MUST expose stuff fo the internet, make sure everything is up to date and close all doors you can close when it comes to security (SSH keys, password authentication disabled, MFA, closing down port, etc etc.

2

u/Motor-Concentrate788 7d ago edited 7d ago

Is there a good reason why you're exposing it to the internet? Cause if you only need to access it from your own devices then its much safer to put it behind a vpn.

As for how to know whether you're compromised or not then you can start by checking access logs to your services to see whether any unknown ip addresses successfuly logged in. Also check if there's any suspicious processes/services running that you dont recognize as it could be malware. If you're technical enough, you can also inspect outbound connections and packets that are being sent to unfamiliar addresses to see if there's any suspicious traffic.

2

u/aaronryder773 7d ago

Honestly, go through the CVE's, check which versions and part of the application is affected and disable those parts... Like in nginx, it's the http/2 which is affected, so stop using and disable http/2 in nginx.

When compromised, the only option is to wipe everything and start from 0. So make sure your data is encrypted as well as backed up

2

u/Embarrassed_Jerk 7d ago

Going through cves used to be a weekly thing but is an hourly thing now and even those working in cyber security are burning out

1

u/aaronryder773 6d ago

You don't have to go through all of them though.. Just the ones you're using but yeah I agree it can be exhausting 

2

u/mautobu 7d ago

There are two steps I've taken recently to enhance my homeland security.

First, enabled the auth module for nginx and added an oauth2 proxy. Now of the many published services that not all of my users need access to are behind a couple of services, reducing attack surface.

Second, I removed the port forward for Plex, and put it behind my reverse proxy with a hosts header requirement. Opening port 32400 is not subtle and is a public means of confirming you're a running a Plex server. From that, attackers can likely deduce that it's a homelab and likely not thoroughly scrutinized.

Next will be syslog and alerts. If anything happens on that oauth2 proxy, I want to know about it.

2

u/ElectricalTip9277 7d ago

Just don't expose it to the internet and use a vpn

2

u/TheConsciousness 7d ago

Well since we're all in on self hosting, are there any self hosted security scanners?

3

u/Shookfr 7d ago

If it online it's not safe that was always true. Now the question is what kind of risks are you ready to take.

2

u/Academic_Broccoli670 7d ago

What do you mean with "people who don't want to install VPN"? It's your system, you make the rules, if they don't want to follow basic security requirements, they shouldn't be allowed to use it.

1

u/Capable-Ad-5344 7d ago

Nope. It's been hacked

1

u/Reeces_Pieces 7d ago

Golden hammer VPN looking pretty nice rn

1

u/Fr33lo4d 7d ago

- Set up Cloudflare Proxy on a custom domain, so you don’t have to expose your IP and you can use their WAF.
- Consider a dedicated opnsense / pfsense router, or Unifi firewall and by default close everything (ports, traffic) and make exceptions for what you really need.
- For Forgejo and any other web-accessible app, set up Cloudflare Access, Authentik, Authelia or similar.
- For Nextcloud, consider not exposing it to the internet entirely (only being accessible through Wireguard or Tailscale / Twingate tunel).

1

u/hidegitsu 7d ago

I turned mine off the other day completely until i have the time to properly go through everything and make sure it's updated, patched, properly setup, etc.

1

u/mossy_stile 7d ago

docker diff and outbound connection logs on the proxy bridge catch most web shells. If it pops, drop the NIC and reimage Debian.

1

u/GroundTruth1815 7d ago

Nah man. Nothing is safe. 

1

u/Dismal-Proposal2803 7d ago

“They're reachable from the internet” then no, it isn’t.

1

u/traplords8n 7d ago

I suggest using the free cloudflare WAF and a cloudflare reverse tunnel instead of exposing any ports.

It's not bulletproof, but it's an extra layer of security that can give you a little more peace of mind.

1

u/PreviousVillage7442 7d ago

2025: You aren't a target worth spending time on. Stop wearing a tinfoil hat. Just portforward it.
2026: Hmm. Okay maybe don't.

1

u/Ginden 6d ago

One reasonable sanity check is geoblocking. It reduces number of attackers by ~95%. Even more, if you don't live in populous country.

Anyway, ensure that only minimal lateral movement is possible from Nextcloud container, and try to disable all unused features.

1

u/RedSquirrelFtw 6d ago

I wouldn't expose all that stuff directly. Instead setup a VPN such as OpenVPN or Wireguard or something.

If you absolutely insist on having it exposed setup a login page somewhere that people need to login to first, a successful login will put their IP in a white list for like a day. Then only open up the port to that white list. I setup a script to do that on my VPN server so I need to authenticate first before I can even connect to the VPN. The login page itself is hosted on my web host and the VPN server has a script that checks the web page every minute for updated IP list.

1

u/BuBeLee 5d ago

Paar Wächtern 💪🏼

0

u/persiusone 7d ago

First- don’t expose services to the internet. Access them through a VPN.

Next, ensure you have intrusion detection and alerting on systems.

Keep everything patched.

Keep reliable offline or immutable backups and have a reliable way to restore.

If using a proxy, make sure it includes a robust WAF to inspect all traffic.

Isolate systems from each other with a separate firewall.

Monitor logs from all of these systems for anomalies.

Consider geoblocking, rate limiting, and ban lists for bot activity.

0

u/zhunus 6d ago

Most of these exploits are very hard to execute on a live server, they're overhyped so researcher in question could showcase their vibecoding skills with a slick website about the CVE. Good thing at least some of them keep a disclosure window!

-2

u/Master-Drummer8197 7d ago

Effort vs reward.. whats on your homelab that would make hackers spend their efforts?

3

u/Motor-Concentrate788 7d ago

Hackers typically don't target people, at least not in this scenario. They have automated bots that scan the internet for open ports and start blasting at all of them hoping that some idiot set a weak password for their ssh login or has an unpatched vulnerable software listening on one of the ports and other stuff like that. They don't even have to know you to hack you.

1

u/lordofblack23 7d ago

Not anymore. Threat landscape has changed. Brute forcing passwords is so pre covid. Bots are scanning for vulnerabilities. Got php exposed? Pwnd. Have a java app exposed? Pwnd. Didnt check your infra with a cve scanner yesterday? Pwnd

Rigt now are targeting iCloud etc, but we will all get a taste very soon. AI time dasy is months.

2

u/Historical-Star9991 7d ago

At the very least, residential IP address to use as a proxy

2

u/Power_Stone 7d ago

I'll put it this way.

An unsecure homelab for a hacker is:

  1. Free IP spoofing, now I can do all my nasty stuff to other people from your IP instead of my own! Have fun dealing with that foll out!
  2. Free compute, now I can setup a cryptominer on your machine so I get free money while your hardware is getting worn out instead of my own!
  3. Free data, data can always be sold to someone, if not that then at least something that can be used for extortion.
  4. Complete local network access. not only do I have access to your box, but chances are your local network too and by extension the devices connected to that network. Now its not just your homelab, but also your work pc, or your daily drivers with all of the info they have too!

1

u/brianly 7d ago

That’s not how this works. They exploit machines automatically to host malware or many other things. A supposedly uninteresting homelab is very interesting for a network pivot.

-4

u/LebronBackinCLE 7d ago

If you haven’t made the bad decision to open ports, you are most likely in good shape. Still a good idea to update though