Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vtxmg's avatar
Level 2

Hacked

One of my friend developed website using laravel and it is hacked.. http://vacancynepal.com/

please visit it and if possible tell me what are the reasons behind it, whether the fault of hosting or coding itself.

0 likes
33 replies
Zurik.Ludg's avatar

It's not possible to tell since it already has been defaced. You probably would like to investigate from the logs and check if it's a web application attack or a network attack. Try the web logs and see if there's any suspicious request being made.

1 like
Snapey's avatar

The site has not been securely deployed

try this http://vacancynepal.com/.env

I'm constantly banging on about this. You do not just dump your Laravel project in public web space ... some things MUST be private

21 likes
SaeedPrez's avatar

Wow, this is a huge problem because of amateur developers in combination with shitty/amateur web hosts who set the FTP root to the document root. I'm actually surprised we haven't seen more of this as Laravel is growing in popularity..

Nice catch @Snapey ...

EDit

You gotta love the local env on production ☺

APP_ENV=local
APP_DEBUG=true
6 likes
DirkZz's avatar

Holy fuck why would you make your .env file publicly available, i just tried a search on google for the filetype .env and people are doing this by the massess.

@JeffreyWay perhaps its an idea to make a video about security and explain a few no-no's like this?

2 likes
Snapey's avatar

Its really scary when you see stripe, paypal and mailchimp credentials amongst other things.

I was thinking that we needed a PR on the .htaccess file to specifically exclude .env, but in the majority of cases .htaccess is in the public folder.

Perhaps there should be one (a .htaccess) in the laravel root folder also that denies access to everything?

1 like
Snapey's avatar

I also noticed that there are some that are other php frameworks so this is not exclusively a Laravel problem

DirkZz's avatar

@Snapey Good idea, it will look silly to the majority of people but there is also a huge group out there that would benefit from this.

SaeedPrez's avatar

I think that would be a good idea!

I can't help myself, I'm still searching and emailing people :D

Hello,

I don't know who installed your Laravel application, but I want to let you know that your website has been installed in an extremely insecure way with your passwords out in the open for anyone to see..

URL

I suggest you find someone more knowledgeable to fix the security issues around your website and also change the passwords.

I found your website invulnerability through a simple Google search and I wanted to let you know before it falls into harmful hands. 


​Best regards,​

Edit: I'm seeing a lot of these websites don't even change the environment and also they don't have a database password :(

Would be nice with a crawler to do this automatically,..

2 likes
zachleigh's avatar

Just went through like 20 result pages of people who left .env exposed. Shocking. One could do a massive amount of damage with all that info....

zachleigh's avatar

I saw everything under the sun. Even Stripe info. Thats a huge problem. I wonder if any of them also have something like phpmyadmin hanging out in the open...

Snapey's avatar

I noticed several with directory listings if you access the base domain.

Sometimes I think the improved frameworks make the entry level for 'web developer' too low.

Most of the sites are run by businesses that presumably thought they had found someone to do a nice looking job for them and are blissfully ignorant that there is an issue.

3 likes
SaeedPrez's avatar

@Snapey

You're so on the point, I would say at least 80% of people on Laracasts don't know the first thing about programming or PHP (or at least they didn't know when they started with Laravel) and they would never have gotten into web development if it wasn't because of the low entry level.

1 like
Zurik.Ludg's avatar

Correct me If I'm wrong as I'd just started learning the Laravel Framework, the 'attack' happens because the author's friend failed to understand on how to correctly deploy the web application am i right, he was supposed to set the public folder as the Document Root?

SaeedPrez's avatar

@Zurik.Ludg that is correct. The public folder is supposed to be the only folder the public has access to because of security reasons.

DirkZz's avatar

@Zurik.Ludg that is correct, and if for some reason it isnt possible to change the root to "/public" you can also create a symlink from "/public_html" to "/public".

When that isn't possible either then I personally would find another host, but as a last resort you can also deny access to all sensitive files in the .htaccess file.

jlrdw's avatar

Don't forget the dot env file is optional, If and only if laravel has to be installed under webroot the configuration values can be put into the configuration files. That would make it harder to hack.

@Snapey has to remind people of the env file problen weekly it seems like. It's getting old. First page of documentation should have a big red warning about that env file. Really getting old.

jlrdw's avatar

@Hujjat to properly install, or if it has to go in webroot DO NOT USE THAT DANGEROUS dot env file, hard code in the configuration.

Taylor should change it to a env.php file for better security.

2 likes
Famine's avatar

I put a fake .env file in my public directory to throw off attackers. Genius or what? :D

8 likes
kobear's avatar

@Famine BRILLIANT! I would go further and actually create a route for '.env' that captures their IP address and spams them ;)

1 like
RushVan's avatar

Just adding 2cents but wouldn't using Forge help the folks struggling with proper deployment of a Laravel app?

2 likes
insanesvk's avatar

@RushVan yep, it would. Although many people just go for some cheap web hosting options with no knowledge of security, or common sense.

joaomantovani's avatar

Another option is to put your laravel folder into the root of the shared server. after that, go to your public_html and do a symlink from the shared server public_html to your laravel public folder.

Mittensoff's avatar

@Famine

It made me laugh. Make sure to put some complex password so it it's even more believable.

phpMick's avatar

Couple of question then:

Why doesn't this get caught by the router? I tried this http://vacancynepal.com/.env on my application and it redirects to home.

I guess this is caught here:

Route::any('{query}',
    function() { return redirect('/home'); })
    ->where('query', '.*');

Why does it matter if you leave APP_ENV=local in? If you aren't using App::environment();?

Mick

Snapey's avatar

@phpMick because what happens is people upload their entire project into public_html and then realise that they cannot access their site as site.com/ but instead they need to use site.com/public.

The thought is then ok, so I just need a htaccess file in the root folder that directs to /public/index.php

The problem is that most .htaccess scripts only redirect missing files so when you hit /home the web server thinks , oh, there is no 'home' file or folder so I will rewrite this request as if the user asked for index.php

This only works where there is no file. If the file exists, for instance .env then the rewrite module thinks it has nothing to do and serves up the .env file.

1 like
vtxmg's avatar
Level 2

@Snapey Its a huge mistake done by the developer himself, I got it. But how can hacker change files even when they got the database credentials? First they have to get into the hosting account, isn't it?

uxappilipinas's avatar

@vtxmg well, shared-hosting is one. They use cluster db. Back in the days of pentesting. During reconnaisance, if I find the target to be using a shared hosting, and its' db credentials viewable by public; we would find a more vulnerable target within the cluster, dump a script, then access the target's db through the cluster's connection. That way, localhost is still localhost. Sometimes, it is worth the work and sweat to jump shells.

Next

Please or to participate in this conversation.