29

I want to know whether there is any class file available for to know the magento version. If the site has been hacked how to to reveal the version?

I know there's a way as follows.

Mage::getVersion();

But if both the frontend and backend of the magento site is not working, how can we check by going through class files? Which class need to refer?

2
  • 6
    A consideration for down-voters: Magento SE is intended for developers and users alike. This question is clearly in the area of the latter.
    – benmarks
    Jan 2, 2014 at 11:44
  • Magento also leaks information in its base skin installs. By looking at the license boilerplate, you can pin it down pretty quickly. May 12, 2015 at 19:49

5 Answers 5

37

The Mage::getVersion() method is defined here

#File: app/Mage.php
public static function getVersion()
{
    $i = self::getVersionInfo();
    return trim("{$i['major']}.{$i['minor']}.{$i['revision']}" . ($i['patch'] != '' ? ".{$i['patch']}" : "")
                    . "-{$i['stability']}{$i['number']}", '.-');
}

Jumping to the getVersionInfo referenced above, we find the following

#File: app/Mage.php
public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '7',
        'revision'  => '0',
        'patch'     => '2',
        'stability' => '',
        'number'    => '',
    );
}

So, Magento uses the array returned by the getVersionInfo method to come up with a version number. We can do so manually (with our minds), and come up with the version 1.7.0.2 for the method listed above. If we found

public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '5',
        'revision'  => '0',
        'patch'     => '0',
        'stability' => 'beta',
        'number'    => '1',
    );
}

We'd know the version was the 1st beta of 1.5.0.0.

That said, if the site's been hacked, all bets are off — as hackers have likely modified multiple class files and create a version of Magento that doesn't exist.

5
  • So if the site has been hacked and we don't have backup as well, there's no any proper way to get exact version? (Assume hackers have been modified above functions as well)
    – Sukeshini
    Jan 1, 2014 at 6:00
  • 4
    The Magento Application Version number is only stored in app/Mage.php where Alan Storm notes. You open it up in a text editor and look if front/back are defunct. You may look up module versioning in the core_resource table, these numbers are imported from the module/etc/config.xml files for each module. If the Mage.php file is missing or modified, there's no other place that I know of it being stored. Jan 1, 2014 at 6:56
  • @Fiasco Labs: Thanks for the response. +1
    – Sukeshini
    Jan 1, 2014 at 7:20
  • @Alan Storm: Thanks for the nice and detailed explanation. I went through the files as per you have mentioned.
    – Sukeshini
    Jan 1, 2014 at 7:21
  • 2
    Keep in mind that a failed/botched upgrade installation may incorrectly display the version in Mage.php. A recent site I worked on that was hacked was reporting 1.7.0.2 but when actually looking at the files it was clear this site was still on 1.6.
    – pspahn
    May 12, 2015 at 15:43
6

if hacked then you need to restore backup, and then you can run this command from magento root folder to check version quickly:

echo "Version: $(php -r "require 'app/Mage.php'; echo Mage::getVersion();")"

Version: 1.9.2.3

or even quicker:

grep -A 10 "function getVersionInfo" app/Mage.php 

public static function getVersionInfo()
{
    return array(
        'major'     => '1',
        'minor'     => '9',
        'revision'  => '2',
        'patch'     => '3',
        'stability' => '',
        'number'    => '',
    );
}
5

We can find the magento which version is using now easily.

Just open your root folder /app/Mage.php

Near 168 line, you can find following code

public static function getVersionInfo()

{

    return array(

        'major'     => '1',

        'minor'     => '9',

        'revision'  => '0',

        'patch'     => '1',

        'stability' => '',

        'number'    => '',

    );

} 

It means that we are currently using 1.9.0.1 version.

1

An easy way is rename app/etc/local.xml to app/etc/local.xml.bkp the browser will show the installation screen, at footer from this screen show the version of installation, in my case it was the solution.

1

Disabling compilation from System-> Tools-> Compilation resolved it for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.