Hacking - I think I have been hacked: Difference between revisions From Online Manual

Jump to: navigation, search
m (wikilink, not URL)
m (Removed contractions and modified sentence construction.)
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== I think I have been hacked, I'm not sure, how do I check? ==
__NOTOC__== I Think I Have Been Hacked. How Do I Check? ==
This is a difficult question, since it depends on the type of the hack. As an indication, you can open up a few of the Source files (the files located in ./Sources) and see if there is any trace of [http://php.net/manual/en/function.base64-decode.php base64_decode]. If there is, there are chances that your forum has been hacked, and there are a few utilities and steps that help users to recover their SMF installation. This code is usually put on the first line of code. So, if the first line isn't "<?php" and absolutely nothing else, you've almost certainly been hacked.
If any of your php files start with anything other than '''<?php''' all by itself on the line, or if an expert advises that any of your executable files have been infected with malicious code, you should be very suspicious. If your site is unexpectedly sending users to another website or causing unexpected pop ups, if users report that your site causes malware warning or if any of your files has a more recent modified date than you expect it to have, consult an expert quickly.


Another way of checking, although it's far less thorough, is to look at the datestamps on your files. If you haven't installed any mods/themes, recently, yet some of your files show as being edited, recently, chances are that they've been modified by someone who shouldn't be able to.
== I Am Sure I Have Been Hacked, What Do I Do Now? ==
First of all, keep calm. When the forum has been hacked, there are a few simple steps for the administrator to do. Most infections can be eliminated in just a few minutes.


== I am sure I have been hacked...what do I do now? ==
* If you can do it quickly and easily, '''Shut down your website temporarily''' to stop any bad things happening while you are fixing the problem. See  [[#Shutting_down_your_site|instructions below]] for tips on how to do this.  If you cannot shut down your site, skip this step and move on to getting rid of the problem.
First of all, keep calm. When the forum has been hacked, there are a few simple steps for the administrator to do.
* [[Backup]] your database and your files (even the infected ones)


One of the most critical steps is to make backups of the whole SMF system, including the database. You want the database in case something goes wrong.  You want all the SMF files (even the infected ones) so that your host and/or the SMF team can help figure out how you got hacked.  And you want backups of all your attachments and avatars and any other files in special directories in case they get messed up or deleted while you are working to delete the infected files.
* '''Check your desktop computer for malware'''
A virus on your PC might have given the hacker your password, or uploaded a file to your website.


*Tell your host that you've been hacked.
* '''Change all your passwords'''
Notify your host so that they can make sure no other servers have been affected. When you report the hack to your host, ask them to check their logs to see who might have had access to your server and, also, get them to check your file permissions. With some hosts, incorrect file permissions can leave files open for easier hacking.
You do not know yet if any of them have been stolen.  That includes all SMF admins, ftp accounts, telnet/ssh users, hosting control panel, database, and even email. If you cannot log into your SMF admin account, see below for how to fix the problem. If you do not know how to change your database password or any other passwords associated with your hosting account, get help from your host.


*File a security report with SMF.
* '''[[Backup]] your database and your files''' (even the infected ones) and store it in a safe place.
This is important. You need to have a copy of your database in case something goes wrong.  You need a backup of your attachment directory, since you cannot get those files back if you accidentally delete them. If you have any other custom file directoris, such as gallery or document storage, you must protect them too. You need to have copies of all the SMF files, so that you or someone else can figure out how you were hacked in the first place. Copy the backup files to a safe place. If you are using FTP to copy the backup files, make sure that you use binary mode.


If your forum was breached via a security weakness within SMF, or an SMF mod and not via a weakness in a non-SMF script, please report it to the SMF developers, so that the issue can be investigated and, if confirmed, patched. Please report Security issues [http://www.simplemachines.org/about/security.php here].
* '''Tell your host''' that you have been hacked.
Please give detailed information, such as webserver logs and/or FTP logs, so the SMF team can help discover the source of the problem.  Usually, you can find these logs in your host's control panel, or in a directory called /logs in your account.
Let them know about the problem.  Ask them to check log files to find out where the attack may have come from. Find out what they recommend to eliminate the infection. Ask them if the malware has left any shell processes running.


* Replace all your SMF files with uninfected files.
* '''File a security report''' with SMF.
**You can use a recent backup of your files, or you can use a fresh set of SMF files. But first, you want to make sure you can get rid of any file that might be dangerous to your users or your site.
If you think the hacker got in by exploiting SMF, please report it right away at [http://www.simplemachines.org/about/security.php security reports]. Please be prepared to share information about your files and your account logs, so that the developers can determine whether a vulnerability in SMF was the cause, and how to fix SMF if it needs it.  
** Carefully check Settings.php, Settings_bak.php, and the attachments directory.  Make sure the php files do not have any bad code in them. Remove any extra php or js files from your attachments directory, and check its index.php for bad code.
** If you have any custom directories (like a gallery mod directory), remove any executable code files -- they can be re-installed later.
** Besides your Settings.php and Settings_bak.php files, and your attachments (and any other directories with files you can't get back), delete everything to do with your SMF installation.  This will get rid of any files that might have been infected.
** If you are unable to delete any of the files, get help from your host.
** If you are using your own backed-up files, restore your backup now (see [[Backup#Restoring_your_forum_files|restoring your forum files]]) for more information
** If you are using a fresh set of files, upload them now (see [[How to upload a fresh set of files]] for more information).
** Once that is done, you'll have a fresh set of files.
== I have cleared my hacked SMF installation, how can I prevent this from happening again? ==
One measure that you can take, is to apply some or all of these [http://wiki.simplemachines.org/smf/Security_Tips security tips]. These tips help you to protect your forum from any further attacks.


* '''Delete all files'''  except for your attachments and custom avatars directories (be very cautious because infected files might be in there).  Make sure your backup files are stored somewhere safe and that they do not get deleted. Ask for help if you are unsure.  In addition to your SMF files, you should delete any "extra" php files, and you may need to delete .htaccess files, php.ini files, or other configuration files.  Talk to your host about this. If you cannot delete a file, talk to your host about how to fix the problem.


* '''Replace all your SMF files''' with uninfected files.
** It is safest to use a fresh set of SMF files rather than a recent file backup.  Only use '''[[Backup#Restoring_your_forum_files|your file backup]]''' if you are 100% certain that it was not infected.
** To get a fresh set of files for the same version of SMF you are already using,  '''[[How to upload a fresh set of files|follow these instructions]]'''.
** If you have any custom directories (like a gallery mod directory), double check them now.
** Get a copy of Settings.php from your recent file backup, edit it to correct the password you just changed, and place a copy in your SMF directory.
** Check your SMF file permissions.  Make sure that they are secure.  Ask your host if you are not sure.
** Patch or upgrade SMF to the most recent and most secure version.
** Re-install your mods.  Use [[Repair settings.php|repair_settings]] if you run into any trouble.
** Back up your files again.


* '''Change all your passwords again.''' Now that the infection has been removed, changing all of your passwords again is recommended in case they were stolen again before you finished eliminating the infection.
* '''Get your website running again'''.
== I Have Cleaned My Hacked SMF Installation. How Can I Prevent This from Happening Again? ==
Keep your SMF software up-to-date by downloading new versions whenever security fixes are available.
Apply some of the  [http://wiki.simplemachines.org/smf/Security_Tips security tips], which can help you to protect your forum from any further attacks.
==Tools You Can Use==
===If Your Admin Password No Longer Works===
See [[I_accidentally_lost_my_admin_account!_What_can_I_do#Resetting_an_admin_users_password|Resetting an admin user's password]] to find out how to set your password back to something you can use.  Login, change the password again, and double-check the email address.  Make sure that you had already changed your database password and the email password.  If the admin account no longer has administrator powers, or if the account has been deleted, read through [[I accidentally lost my admin account! What can I do]] for more helpful tips.
===Shutting Down Your Linux/Apache Site===
If you can alter your .htaccess file and if your site uses the Apache web server with mod_rewrite installed, you can shut down your site using these two files.  First, make a copy of your .htaccess file and save it in a safe place.  Then replace it with the one below and create a file called maintenance.html in the same directory. If your site does not use the Apache web server, then this method will not work.  If you cannot find your .htaccess file, or if this change to your .htaccess file does not shut your site down, get support from your host.
'''.htaccess'''
{{code|1=# Enables runtime rewriting engine
RewriteEngine on
# Show maintenance page to visitors
#RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111 # except if they come from this IP (commented out)
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ /maintenance.html [R=503,L]}}
'''maintenance.html'''
{{code|1=<html>
<head><title>This site is undergoing maintenance</title></head>
<body>This site is undergoing maintenance</body>
</html>}}
===Shutting Down Your Windows Site===
If you are using the IIS webserver and have the [http://www.iis.net/configreference/system.webserver/security/ipsecurity ipsecurity restriction for IP Address and Domain Names] installed and enabled, save a copy of web.config, replace it with the one below and restart your IIS web server.
{{code|1=<nowiki><?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <identity impersonate="false" />
    </system.web>
    <system.webServer>
        <security>
            <ipSecurity allowUnlisted="false">
                <clear/>
<!--                <add ipAddress="111.111.111.111" allowed="true" /> --> <!-- Adding your own IP address would allow you to use the website, but might be dangerous to you... -->
            </ipSecurity>
        </security>
    </system.webServer>
</configuration></nowiki>}}
[[Category:FAQ]]
[[Category:FAQ]]

Revision as of 09:07, 11 September 2015

I Think I Have Been Hacked. How Do I Check?

If any of your php files start with anything other than <?php all by itself on the line, or if an expert advises that any of your executable files have been infected with malicious code, you should be very suspicious. If your site is unexpectedly sending users to another website or causing unexpected pop ups, if users report that your site causes malware warning or if any of your files has a more recent modified date than you expect it to have, consult an expert quickly.

I Am Sure I Have Been Hacked, What Do I Do Now?

First of all, keep calm. When the forum has been hacked, there are a few simple steps for the administrator to do. Most infections can be eliminated in just a few minutes.

  • If you can do it quickly and easily, Shut down your website temporarily to stop any bad things happening while you are fixing the problem. See instructions below for tips on how to do this. If you cannot shut down your site, skip this step and move on to getting rid of the problem.
  • Check your desktop computer for malware

A virus on your PC might have given the hacker your password, or uploaded a file to your website.

  • Change all your passwords

You do not know yet if any of them have been stolen. That includes all SMF admins, ftp accounts, telnet/ssh users, hosting control panel, database, and even email. If you cannot log into your SMF admin account, see below for how to fix the problem. If you do not know how to change your database password or any other passwords associated with your hosting account, get help from your host.

  • Backup your database and your files (even the infected ones) and store it in a safe place.

This is important. You need to have a copy of your database in case something goes wrong. You need a backup of your attachment directory, since you cannot get those files back if you accidentally delete them. If you have any other custom file directoris, such as gallery or document storage, you must protect them too. You need to have copies of all the SMF files, so that you or someone else can figure out how you were hacked in the first place. Copy the backup files to a safe place. If you are using FTP to copy the backup files, make sure that you use binary mode.

  • Tell your host that you have been hacked.

Let them know about the problem. Ask them to check log files to find out where the attack may have come from. Find out what they recommend to eliminate the infection. Ask them if the malware has left any shell processes running.

  • File a security report with SMF.

If you think the hacker got in by exploiting SMF, please report it right away at security reports. Please be prepared to share information about your files and your account logs, so that the developers can determine whether a vulnerability in SMF was the cause, and how to fix SMF if it needs it.

  • Delete all files except for your attachments and custom avatars directories (be very cautious because infected files might be in there). Make sure your backup files are stored somewhere safe and that they do not get deleted. Ask for help if you are unsure. In addition to your SMF files, you should delete any "extra" php files, and you may need to delete .htaccess files, php.ini files, or other configuration files. Talk to your host about this. If you cannot delete a file, talk to your host about how to fix the problem.
  • Replace all your SMF files with uninfected files.
    • It is safest to use a fresh set of SMF files rather than a recent file backup. Only use your file backup if you are 100% certain that it was not infected.
    • To get a fresh set of files for the same version of SMF you are already using, follow these instructions.
    • If you have any custom directories (like a gallery mod directory), double check them now.
    • Get a copy of Settings.php from your recent file backup, edit it to correct the password you just changed, and place a copy in your SMF directory.
    • Check your SMF file permissions. Make sure that they are secure. Ask your host if you are not sure.
    • Patch or upgrade SMF to the most recent and most secure version.
    • Re-install your mods. Use repair_settings if you run into any trouble.
    • Back up your files again.
  • Change all your passwords again. Now that the infection has been removed, changing all of your passwords again is recommended in case they were stolen again before you finished eliminating the infection.
  • Get your website running again.

I Have Cleaned My Hacked SMF Installation. How Can I Prevent This from Happening Again?

Keep your SMF software up-to-date by downloading new versions whenever security fixes are available. Apply some of the security tips, which can help you to protect your forum from any further attacks.

Tools You Can Use

If Your Admin Password No Longer Works

See Resetting an admin user's password to find out how to set your password back to something you can use. Login, change the password again, and double-check the email address. Make sure that you had already changed your database password and the email password. If the admin account no longer has administrator powers, or if the account has been deleted, read through I accidentally lost my admin account! What can I do for more helpful tips.

Shutting Down Your Linux/Apache Site

If you can alter your .htaccess file and if your site uses the Apache web server with mod_rewrite installed, you can shut down your site using these two files. First, make a copy of your .htaccess file and save it in a safe place. Then replace it with the one below and create a file called maintenance.html in the same directory. If your site does not use the Apache web server, then this method will not work. If you cannot find your .htaccess file, or if this change to your .htaccess file does not shut your site down, get support from your host.

.htaccess

# Enables runtime rewriting engine
RewriteEngine on

# Show maintenance page to visitors
#RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111 # except if they come from this IP (commented out)
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ /maintenance.html [R=503,L]

maintenance.html

<html>
<head><title>This site is undergoing maintenance</title></head>
<body>This site is undergoing maintenance</body>
</html>

Shutting Down Your Windows Site

If you are using the IIS webserver and have the ipsecurity restriction for IP Address and Domain Names installed and enabled, save a copy of web.config, replace it with the one below and restart your IIS web server.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <identity impersonate="false" />
    </system.web>
    <system.webServer>
        <security>
            <ipSecurity allowUnlisted="false">
                <clear/>
<!--                <add ipAddress="111.111.111.111" allowed="true" /> --> <!-- Adding your own IP address would allow you to use the website, but might be dangerous to you... -->
            </ipSecurity>
        </security>
    </system.webServer>
</configuration>


Advertisement: