Strangers trying to connect to server

Hi,
I just installed emoncms on a VPS and out of interest I looked at the log file just to see that there are many attempts from ip’s to connect to my server. Mostly from China and Brazil. Is this normal and how do I make sure that they are not successful?

Connect how? Via SSH or via the web interface?

Through the web interface I think. Always four attempts like these

2021-12-15 08:40:19.119|ERROR|index.php|Invalid API key | 131.100.148.7
2021-12-15 08:40:19.484|ERROR|index.php|Invalid API key | 131.100.148.7
2021-12-15 08:40:19.846|ERROR|index.php|Invalid API key | 131.100.148.7
2021-12-15 08:40:20.200|ERROR|index.php|Invalid API key | 131.100.148.7

This is from the log file. And this

2021-12-15 02:33:29.718|ERROR|index.php|Invalid API key | 171.221.235.43
2021-12-15 02:33:30.143|ERROR|index.php|Invalid API key | 171.221.235.43
2021-12-15 02:33:31.055|ERROR|index.php|Invalid API key | 171.221.235.43
2021-12-15 02:33:36.039|ERROR|index.php|Invalid API key | 171.221.235.43

Brazil Brasilia Linkwap Internet Fibra Optica for the first example, China Chengdu Chinanet Sichuan Province Network for the second.

This is why you (or anyone) should always ensure your API Key never appears on the forum, always replace it with “MY API KEY” or something like that.

Unfortunately, you’ve got to expect low life from anywhere in the world to try to take advantage of anything they possibly can.

1 Like

Hi Robert, that is the two that I also traced. I just wonder what could they possibly gain by connecting as device to Emoncms?
What are the real dangers from these, I want to call them something worse than low life’s, to the system?

Hey @mariusl

It’s pretty normal. The websites I run all get attacked like this all the time.

There is something vaguely interesting about your case. The log entry you are seeing is from this line of code:

So the good news is that they are being denied access and you are returning a 401.

What’s slightly odd is that to get to that bit of code it needs an $apikey to be set and you can see a bit further up in that file that would mean they would need to be sending that in the query string or other parameters.

As @Robert.Wall says, it’s possible they are following links that included an API key at some point which has been rotated so it’s no longer working. It’s unusual for bad people to send things that are specific to a particular application, such as an apikey, but it does happen.

So, take the error log entry as a good sign, they are being bounced. It would be worse if they were just getting in and doing stuff of course.

You may simply want to alter your API key every so often just for peace of mind. That’s quite common practice with things you care about. We certainly do that on our systems if there are signs it might be compromised - but I don’t see that here.

David

Yes that is odd… It is quite unusual for what must be mostly automated attack attempts to try anything that actually relates to the emoncms, usually you see lots of attempts at random script names that might in another application yield something they are after but doesn’t actually exist in emoncms… Or login attempts with common usernames and passwords…

Are you logs full of this @mariusl ?

Also somewhat surprised that you’re getting this on a new install. Maybe it’s a hosting provider that gets a lot of attack attempts? I’ve noticed some servers can end up getting a lot more interest than others…

Do you really mean

or could that code see anything as a bad APIkey and report a 401 error?

I run a website for a friend. It could easily be a WordPress site but it isn’t, it’s handwritten. That gets requests for WordPress files which hold WordPress login credentials - which of course don’t exist. :grinning_face_with_smiling_eyes:

Thanks for questioning @Robert.Wall, please always do that.

In this if block you can see it’s setting $apikey in a couple of scenarios where it finds an apikey being provided in the GET / POST (typically in the querystring, but knowing PHP slightly, it could be in other ways too). Without it finding those then $apikey will stay false and you can’t get into the block of code that logs the “Invalid API key” error.

Oh yes, those are fun. We especially enjoy seeing the ones from the penetration testers we hire. As you can imagine, the Log4Shell ones are causing the most interest this week.

Of course, without this snip to know where $apikey came from, I was hoping that would be the case, but I’ve come across instances where things like that have been assumed, but it turned out not to be like that.

[N.B. I’m a paid up, card-carrying cynic. :wink: ]

1 Like

There is quite a bit of that going on but nothing for the the last 24 hours

I have a NAS drive that is constantly under attack. There are bots on the web that look for common things connected and makes attempt to hack through know vulnerabilities. I have had seen it also in a couple of joomla sites I used to run, I bought a firewalla https://firewalla.com blue model and that reports and blocks attempts to get at whatever you have on your lan. And on a side quest and not for the faint of heart I have installed PFSense router with Snort (Great name) but I have yet to drop the firewalla as I don’t know what I am doing with Snort and no time to read the manual!

@dnwigley just use country filtering . some of my servers were being being hammered 1- 2 million attempts a day from all over the world country and it went to practically nill . snort not too hard to setup - just install your snort key - check which definitions you want . after you download those then just select what to watch for bots, compromised, virus, spyware etc . then once you start filling in with reports just select which ones to ignore and which to block. - pfsense is better but if you are not so familiar OPNsense would be easier just reflash your pfsense hardware with opnsense it setups up country blocking and IDS ( snort like) for you, much much easier then Pfsense does… or if you are a little more adventurous openwrt and openwrt you can flash to many off the self routers - I just finished building an opewrt router for a ~ 200Mbps connection that share cost with my neighbour . openwrt router with built in NordVPN and VPN pass through ports on the router ( as I do not know what stuff my neighbour does this way i am protected a little bit from their blow back)