Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

I'm being hacked

I am currently experiencing a hack where files on my server are being modified. The application is built with PHP and MySQL.

The files were uploaded or modified, but the access logs appeared normal. There were no POST requests, and there were no signs of injection or XSS in the GET requests.

Initially, I was using a server on CloudWays. They analyzed the SSH access logs and found no unauthorized access. I then contacted Sucuri on CloudWays' recommendation, but they were unable to solve the problem.

Afterwards, I moved the server to AWS and set the file owner to root. SSH access was restricted to the AWS console, and I configured the server to only allow Cloudflare IPs on ports 80 and 443.

Considering the vulnerabilities of PHP applications, I blocked shell_exec, system, etc. using disable_functions in php.ini.

I also installed tamper-proof software to prevent files from being uploaded, modified, deleted, or having their ownership changed.

However, today I found that a PHP file owned by root was modified. Additionally, PHP and .sh files in the backup folder outside the home directory were also changed.

There were no suspicious activities in the access or SSH logs.
My PC has not been hacked, and my AWS key or login information has not been leaked.

A hacker contacted me, claiming that the attack occurs at the top of the middleware, making it impossible to defend against and leaving no logs. Is such a vulnerability possible?

Can anyone please suggest a solution to solve this problem?

«13

Comments

  • entrailzentrailz Member, Host Rep

    Honestly the information provided is too vague. I'd be happy to audit your php code to see if there is any glaring issues, but it's very hard to advise otherwise.

  • suutsuut Member

    What PHP program?

    Thanked by 1sultan365
  • @entrailz said:
    Honestly the information provided is too vague. I'd be happy to audit your php code to see if there is any glaring issues, but it's very hard to advise otherwise.

    What I'm curious about is, is there a vulnerability in the PHP application that allows this behavior?

    • Modify ROOT owner's PHP file
    • Modify files in var/log
  • @suut said:
    What PHP program?

    This is a self-developed program. It has had security updates every year and works with PHP 8.1.

  • edited June 2024

    @sultan365 said:

    @suut said:
    What PHP program?

    This is a self-developed program. It has had security updates every year and works with PHP 8.1.

    How should we know if your custom application has vulnerabilities? PHP itself is probably not rootable by default, so what kind of information are you looking for exactly?

    Thanked by 2sultan365 yoursunny
  • @totally_not_banned said:

    @sultan365 said:

    @suut said:
    What PHP program?

    This is a self-developed program. It has had security updates every year and works with PHP 8.1.

    How should we know if your custom application has vulnerabilities?

    The developer has continuously patched it, and Sucuri has also reviewed it.

  • entrailzentrailz Member, Host Rep

    @sultan365 said:

    @entrailz said:
    Honestly the information provided is too vague. I'd be happy to audit your php code to see if there is any glaring issues, but it's very hard to advise otherwise.

    What I'm curious about is, is there a vulnerability in the PHP application that allows this behavior?

    • Modify ROOT owner's PHP file
    • Modify files in var/log

    Very easy to pivot from php access to full root access

    Thanked by 2sultan365 MrH
  • edited June 2024

    @sultan365 said:

    @totally_not_banned said:

    @sultan365 said:

    @suut said:
    What PHP program?

    This is a self-developed program. It has had security updates every year and works with PHP 8.1.

    How should we know if your custom application has vulnerabilities?

    The developer has continuously patched it, and Sucuri has also reviewed it.

    OK and we are which of those two exactly? We have no clue what you are running there...

  • sultan365sultan365 Member
    edited June 2024

    Very easy to pivot from php access to full root access

    Is it possible to pivot even if I block functions like shell_exec, exec, system, fopen, etc?

  • entrailzentrailz Member, Host Rep

    @sultan365 said:

    Very easy to pivot from php access to full root access

    Is it possible to block functions such as shell_exec, exec, system, fopen, etc.?

    Even if these functions are blocked, they can be bypassed, or other ways to get full access. For example, running on aws they could request the metadata url to attempt to escalate their privileges.

    There are so many variables at play.

    Thanked by 1sultan365
  • edited June 2024

    @sultan365 said:

    Very easy to pivot from php access to full root access

    Is it possible to block functions such as shell_exec, exec, system, fopen, etc.?

    Yes, im pretty sure you can disable those in your php config. If your application has exploitable holes this is only duct tape though and would be (when doubling as a fix) considered bad practice as you are not really fixing anything and chances of missing some dangerous function are astronomical (hint: even database functions can often be used for code execution).

    Thanked by 1sultan365
  • @sultan365 said:
    A hacker contacted me, claiming that the attack occurs at the top of the middleware, making it impossible to defend against and leaving no logs. Is such a vulnerability possible?

    Very possible. Did they mention which plugin or library is being exploited? It sounds like mass scanning/automated box popping if you're moving your site between providers and still getting hacked, so you're probably not alone with this.

    Update all your libraries and keep an eye on their respective security advisories because it's likely someone will identify/patch the issue if it's a mass exploitation scenario.

    You'll also want to make sure you have clean backups and a strategy to redeploy your site rapidly in case it gets defaced/wiped. Do a full OS reinstall and then restore from backup to make sure they haven't left any persistent access.

    Also, stop using Root now you know they can pop your site. Make them work to escalate privileges from the Web Server user, and, again, update all your OS packages to make it harder.

    Maybe also try running a popular Privilege Escalation checking script on your server and fix any issues you find to reduce the chances of a breakout...and, probably most importantly, make sure the [potentially] compromised server is isolated from the rest of your network, (disable VPNs etc), to ensure a bad situation doesn't escalate

    Thanked by 1sultan365
  • @sultan365 said:
    What I'm curious about is, is there a vulnerability in the PHP application that allows this behavior?

    • Modify ROOT owner's PHP file
    • Modify files in var/log

    If your application has any bugs then hacker can upload shell and using that they can do whatever they want. For example changing file permission or do whatever. They can also open a new port and add unauthorized access.
    Two things can be happened
    1. Bugs in your php code which allows attacker to exploit the application. It can be sqli, file upload or rce or anything
    2. Your server security is compromised since you're using aws i believe their network is okay. So it can be any application or anything running inside the server. Check process and open port to get better idea.

    You can jail your php code inside home directory. This way even if attacker get access they'll not be able to modify anything outside home. Dont forget to run your webserver as non root user. Otherwise if they get access to files via php code issue they'll be able to change files permission so file permission will be not effective.

    It's difficult to find out the bugs but you can use a few tricks. for example you can put custom log or mailing code to notify you inside these files which is getting modified by the hacker frequently. For example you have abc.php file you can mail the dump of $_request, $_server and ip which try to access it. You can also create bash script to check wheather a file is modified or not and set mail notification there.

    Thanked by 1sultan365
  • Thank you everyone for your kind responses.

    I was shocked that I could pivot root privileges from PHP.
    I was even more relieved because there were no problems with imunify360.

    Ultimately, the conclusion is that the source code must be reviewed.

    • Is there a way I can prevent the access log from being modified?
    • I think I can find a hole in the attack if the log is not modified. Am I right?

    If there is a good solution, please advise.

  • Also, did you patch these critical vulnerabilities from April, (the one affecting Windows hosts looks particularly bad): https://socradar.io/critical-php-vulnerabilities/

    Thanked by 1sultan365
  • @sultan365 said:

    • Is there a way I can prevent the access log from being modified?

    Setup some kind of external logging.

    • I think I can find a hole in the attack if the log is not modified. Am I right?

    At least it's worth a try.

    Thanked by 1sultan365
  • entrailzentrailz Member, Host Rep

    @sultan365 said:
    Thank you everyone for your kind responses.

    I was shocked that I could pivot root privileges from PHP.
    I was even more relieved because there were no problems with imunify360.

    Ultimately, the conclusion is that the source code must be reviewed.

    • Is there a way I can prevent the access log from being modified?
    • I think I can find a hole in the attack if the log is not modified. Am I right?

    If there is a good solution, please advise.

    A rudimentary way of checking is to run a constant tail -f on access logs etc, have this open in a terminal at all times.

    Thanked by 2sultan365 MrH
  • FatGrizzlyFatGrizzly Member, Host Rep

    all above points ^

    Try something like Imunify360, might help.(not guaranteed.)

    Thanked by 1sultan365
  • You could also try deploying this to your server, it'll cut out some automated attacks: https://www.crowdsec.net/

    Same with ModSecurity for your Web Server, but much better. Harder to setup but stops most automated nonsense: https://www.modsecurity.org/

    And as it's likely you're getting caught by automated scanning, try running a web application vulnerability scanner on your site and see what it finds. It's unlikely you're being victimised, so something like this will probably be OK: https://pentest-tools.com/website-vulnerability-scanning/website-scanner

  • If there is a vulnerability in the current PHP application and it is possible to steal root privileges, could you tell me how to isolate it in public_html?

    I want to prevent the log file from being modified.

  • yoursunnyyoursunny Member, IPv6 Advocate

    Mentally strong people run application on immutable storage.
    Vulnerability? Reboot the server and the changes are reverted.

  • LeviLevi Member

    “Php file owned by root…” - that is all you need to say.

  • sultan365sultan365 Member
    edited June 2024

    @Levi said:
    “Php file owned by root…” - that is all you need to say.

    The reason for changing the ownership of public_html files to root was to block file modification.
    Even if chown is root, it doesn't mean you can hijack root privileges, right?

  • lukast__lukast__ Member, Megathread Squad

    @Levi said:
    “Php file owned by root…” - that is all you need to say.

    USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         296  0.0  2.7 128412 24632 ?        Ss   Jun03   0:03 php-fpm: master process
    root         332  0.0  1.5 128580 14040 ?        S    Jun03   0:01 php-fpm: pool www
    root         333  0.0  1.5 128936 13696 ?        S    Jun03   0:00 php-fpm: pool www
    root         334  0.0  1.4 128616 13080 ?        S    Jun03   0:00 php-fpm: pool www
    root         335  0.0  1.5 128936 14000 ?        S    Jun03   0:02 php-fpm: pool www
    root         336  0.0  1.5 128928 13680 ?        S    Jun03   0:00 php-fpm: pool www
    root         337  0.0  1.6 128916 15056 ?        S    Jun03   0:00 php-fpm: pool www
    root         338  0.0  1.4 128616 13360 ?        S    Jun03   0:00 php-fpm: pool www
    root         339  0.0  1.6 128580 14912 ?        S    Jun03   0:02 php-fpm: pool www
    
    root@[...]:~# stat [...]/index.php
      File: [...]/index.php
      Size: 23747           Blocks: 48         IO Block: 4096   regular file
    Device: 254,1   Inode: 1704288     Links: 1
    Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
    

    (Of course in a container (without docker))

    Thanked by 1sultan365
  • If you have a custom developed PHP application, it is highly recommended to add an additional layer of security by implementing verification and validation of GET and POST variables.
    This approach will significantly enhance the overall security of your PHP application. By validating user input, you can mitigate the risk of various security vulnerabilities, such as SQL injection, cross-site scripting (XSS), and other malicious attacks. Failure to properly sanitize and validate user input can lead to serious security breaches, compromising the integrity and confidentiality of your application and its data

    Thanked by 1sultan365
  • i would still assume that the server is compromised even if there's no alarms going off, better to be safe then sorry.

  • @WebProject said:
    If you have a custom developed PHP application, it is highly recommended to add an additional layer of security by implementing verification and validation of GET and POST variables.
    This approach will significantly enhance the overall security of your PHP application. By validating user input, you can mitigate the risk of various security vulnerabilities, such as SQL injection, cross-site scripting (XSS), and other malicious attacks. Failure to properly sanitize and validate user input can lead to serious security breaches, compromising the integrity and confidentiality of your application and its data

    I used Cloudflare Enterprise, and Nginx also filtered out all methods other than POST and GET, but the hacker seems to have bypassed this.

  • FatGrizzlyFatGrizzly Member, Host Rep

    @sultan365 said: I used Cloudflare Enterprise

    Are you sure that the attacker is not bypassing CF?

  • FatGrizzlyFatGrizzly Member, Host Rep

    and since you mentioned CF Enterprise,

    Its about time that you get professional security auditors/researchers involved, looks like something very critical/production is being attacked.

Sign In or Register to comment.