Monday, January 23, 2017

How to detect windows os is 32 bit or 64 bit using c++?

This is one of the questions asked by budding programmers in many technical forums. Not just for legit purpose, even malware authors used these strategies in their programs to find out whether 32 bit or 64 bit. In this post we going to discuss various ways to determine whether it is 32 bit or 64 bit.

The popular answers are
"The function to call is IsWow64Process. It tells your 32-bit application if it is running on a 64 bit Windows."
According to Microsoft, IsWow64process( ) is to determine the specific process is running under WOW64.
Syntax: 
BOOL WINAPI IsWow64Process(
  _In_  HANDLE hProcess,
  _Out_ PBOOL  Wow64Process
);

Sample program given by Microsoft:
#include <windows.h>
#include <tchar.h>

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            //handle error
        }
    }
    return bIsWow64;
}

int main( void )
{
    if(IsWow64())
        _tprintf(TEXT("The process is running under WOW64.\n"));
    else
        _tprintf(TEXT("The process is not running under WOW64.\n"));

    return 0;
}


There is another way to do this via program:
bool getWindowsBit(bool & isWindows64bit)
{
#if _WIN64

    isWindows64bit =  true;
    return true;

#elif _WIN32

    BOOL isWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    LPFN_ISWOW64PROCESS fnIsWow64Process  = (LPFN_ISWOW64PROCESS) 
GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(), &isWow64))
            return false;

        if(isWow64)
            isWindows64bit =  true;
        else
            isWindows64bit =  false;

        return true;
    }
    else
        return false;

#else

    assert(0);
    return false;

#endif
}

 GetSystemWow64Directory Method:
In this method, the function returns the path of system directory if it is 64 bit os.
Otherwise, it is understood that 32 bit os.

Syntax:
UINT WINAPI GetSystemWow64Directory(
  _Out_ LPTSTR lpBuffer,
  _In_  UINT   uSize
);
Novel Method used by malware:
A recent malware called Shamoon malware, it is disk wiper malware, targets the
power sector in gulf region.
This malware using a novel technique to find the os is 32 bit or 64 bit.
It was quoted from the security researcher's analysis:
"To identify 64Bit OS, first you open "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" using RegOpenKey API. Then by calling RegQueryValue API you read "PROCESSOR_ARCHITECTURE" value inside. Now using wcscmp function, you once compare it to "amd64" once and with another wcscmp call, you compare it against "AMD64" string. So for this purpose you store "amd64" and "AMD64" strings separately in the code, encrypt them separately with separate keys, decrypt each one individually in runtime and use all these information and around 7 function and API calls to identify 64 bit OS. Because as old C++ saying goes, "never trust wcsicmp as case-insensitive string compare, it doesn't work". Here is the genius code snippet:
char Detect64BitOSNovelMethod()
{
  char v0; // bl@1
  unsigned int v1; // esi@3
  DWORD Type; // [sp+4h] [bp-DCh]@2
  DWORD cbData; // [sp+8h] [bp-D8h]@2
  HKEY phkResult; // [sp+Ch] [bp-D4h]@1
  BYTE Data; // [sp+10h] [bp-D0h]@2
  __int16 v7[52]; // [sp+74h] [bp-6Ch]@4
 
  v0 = 0;
  if ( !RegOpenKeyExW(HKEY_LOCAL_MACHINE, EnvironmentRegPath, 0, 0x20019u, &phkResult) )
  {
    Type = 0;
    cbData = 100;
    if ( !RegQueryValueExW(phkResult, PROCESSOR_ARCHITECTURE_STR, 0, &Type, &Data, &cbData) )
    {
      v1 = cbData;
      if ( cbData > 0 )
      {
        memcpy_0(v7, &Data, cbData);
        v7[v1 >> 1] = 0;
        if ( !wcscmp((const unsigned __int16 *)AMD64_STR, (const unsigned __int16 *)v7)
          || !wcscmp((const unsigned __int16 *)amd64_lower_str, (const unsigned __int16 *)v7) )
        {
          v0 = 1;
        }
      }
    }
    RegCloseKey(phkResult);
  }
  return v0;
}

 Plenty of techniques are available and still we need to explore more on this. 
Post created by newWorld

Saturday, January 14, 2017

Jordan inspirational

Michael Jordan was born in 1963, in the slums of Brooklyn, New York.

He had four  siblings and his father's earnings were not sufficient to provide for the whole family.

He grew up in a poor neighbourhood. Exposed to mindless violence and heavy discrimination in the slums, he saw for himself only a hopeless future.

His father saw in Michael, a lost soul and decided to do something.

He gave Michael, who was 13 years old, a piece of used clothing and asked: "What do you think the value of this outfit would be?"

Jordan replied,"Maybe one dollar."

His father asked, "Can you sell it for two dollars? If you can sell it, it would mean that you are a big help to your family."

Jordan nodded his head, "I'll try, but no guarantee that I'll be successful."

Jordan carefully washed the cloth clean. Because they didn't have an iron, to smoothen the cloth, he levelled it with a clothes brush on a flat board, then kept it in the sun to dry. The next day, he brought the clothes to a crowded underground station. After offering it for more than six hours. Jordan finally managed to sell it for $2. He took the two dollar bill and ran home.

After that, everyday he looked for used clothing, washed and ironed it, and sold it in the crowd.

More than ten days later, his father again gave him a piece of used clothing, "Can you think of a way you can sell this for 20 bucks?"

Aghast, Jordan said, "How is it possible? This outfit can only fetch two dollars at the most."

His father replied, "Why don't you try it first? There might be a way."

After breaking his head for a few hours, finally, Jordan got an idea.

He asked for cousin's helpto paint a picture of Donald Duck and Mickey Mouse on the garment. Then he tried to sell it in the school where the children of the rich study.

Soon a housekeeper, who was there to pick his master, bought that outfit for his master. The master was a little boy of only 10 years. He loved it so much and he gave a five dollar tip. 25 dollars was a huge amount for Jordan, the equivalent of a month's salary of his father.

When he got home, his father gave him yet another piece of used clothing, "Are you able to resell it at a price of 200 dollars?" Jordan's eyes lit up.

This time, Jordan accepted the clothes without the slightest doubt. Two months later a popular movie actress from the movie "Charlie's Angels", Farah Fawcett came to New York for her Movie promos. After the press conference, Jordan made his way through the security forces to reach the side of Farah Fawcett and requested her autograph on the piece of clothing. When Fawcett saw this innocent child asking for her autograph, she gladly signed it.

Jordan was shouting very excitedly, "This is a jersey signed by Miss Farah Fawcett, the selling price is 200 dollars!" He auctioned off the clothes, to a businessman for a price of 1,200 dollars!

Upon returning home, his father broke into TEARS and said, "I am amazed that you did it My child! You're really great! "

That night, Jordan slept alongside his father. His father said, "Son, in your experience selling these three pieces of clothing, what did you learn about success?"

Jordan replied, "Where there's a will, there's a way."

His father nodded his head, then shook his head, "What you say is not entirely wrong! But that was not my intention. I just wanted to show you that a piece of used clothing which is worth only a dollar can also be increased in value, Then how about us - living & thinking humans? We may be darker and poorer, but what if we CAN increase our VALUE."

This thought enlightened young Jordan. Even a piece of used clothing could be made dignified, then why not me? There is absolutely no reason to underestimate myself.

From then on, Michael Jordan felt that his future would be beautiful and full of hope.

He went on to become the greatest basketball player of all times.

How can I increase my own value? I am finding it a very interesting thought. I am sure, you too, will.

Do have a splendid year 2017.

Monday, January 9, 2017

Who Will Cry When You Die?

*Who Will Cry When You Die?"           ராபின் ஷர்மா எழுதிய புத்தகம்...*

*அதாவது நீங்கள் இறந்த பின் யார் அழ போகிறார்கள்? என்ற தலைப்பில் எழுதப்பட்ட இப்புத்தகத்தில்...*
*“நீ பிறந்த போது, நீ* *அழுதாய்...உலகம் சிரித்தது..*.
*நீ இறக்கும் போது,    பலர் அழுதால் தான் உன் ஆத்மா சாந்தியடையும்" என ஆரம்பிக்கும் ராபின் ஷர்மா, இந்த புத்தகத்தில் கூறும் அற்புத கருத்துக்களை காண்போம்...*

*1. உங்கள் வாழ்க்கையில் நீங்கள் சந்திக்)கும் ஒவ்வொரு நபரும் உங்களுக்கு ஏதோ ஒன்றை சொல்லி தருகின்றார். எனவே நீங்கள் சந்திக்கும் எல்லோரிடமும் கருணையுடன் இருங்கள்..*.

*2. உங்களுக்கு எந்த விஷயத்தில் திறமை உள்ளதோ அதிலேயே கவனத்தையும், நேரத்தையும் அதிகம் செலுத்துங்கள். மற்ற விஷயங்களுக்காக அதிக நேரம் செலவழிக்காதீர்கள்.*

*3. அடிக்கடி கவலை படாதீர்கள். தேவை எனில் கவலை படுவதற்கென ஒவ்வொரு நாளும் மாலை நேரம் முப்பது நிமிடம் ஒதுக்குங்கள். அந்த நேரம் அனைத்து கவலையும் குறித்து சிந்தியுங்கள்.*

*4. அதிகாலையில் எழ பழகுங்கள்*.
*வாழ்வில் வென்ற பலரும் அதிகாலையில் எழுபவர்களே.*

*5. தினமும் நிறைய சிரிக்க பழகுங்கள்.*
*அது நல்ல ஆரோக்கியத்தையும் நண்பர்களையும் பெற்று தரும்.*

*6. நிறைய நல்ல புத்தகம் படியுங்கள்.*
*எங்கு சென்றாலும், பிரயாணத்தின் போதும் ஒரு புத்தகத்துடன் செல்லுங்கள். காத்திருக்கும் நேரத்தில் வாசியுங்கள்.*

*7. உங்கள் பிரச்சனைகளை ஒரு தாளில் பட்டியலிடுங்கள். இவ்வாறு பட்டியலிடும்போதே உங்கள் மன பாரம் கணிசமாக குறையும். அதற்கான தீர்வு இதன் மூலம் கிடைக்கவும் வாய்ப்பு உண்டு.*

*8. உங்கள் குழந்தைகளை உங்களுக்கு கிடைத்த மிக சிறந்த பரிசாக ( Gift ) நினையுங்கள். அவர்களுக்கு நீங்கள் தர கூடிய சிறந்த பரிசு அவர்களுடன் நீங்கள் செலவிடும் நேரமே.*

*9. தனக்கு வேண்டியதை கேட்பவன் சில நிமிடங்கள் முட்டாளாய் தெரிவான். தனக்கு வேண்டியதை கேட்காதவன் வாழ் நாள் முழுவதும் முட்டாளாய் இருக்க நேரிடும்*.

*10. எந்த ஒரு புது பழக்கமும் உங்களுக்குள் முழுதும் உள் வாங்கி, அது உங்கள் வாடிக்கையாக மாற 21 நாட்களாவது ஆகும். ஆகவே தேவையான விஷயங்களை திரும்ப திரும்ப செய்யுங்கள்.*

*11. தினமும் நல்ல இசையை கேளுங்கள். துள்ளலான நம்பிக்கை தரும் இசை, புன்னகையையும் உற்சாகத்தையும் தரும்.*

*12. புது மனிதர்களிடமும் தயங்காது பேசுங்கள். அவர்களிடமிருந்து கூட உங்களை ஒத்த சிந்தனையும், நல்ல நட்பும் கிடைக்கலாம்.*

*13. பணம் உள்ளவர்கள் பணக்காரர்கள் அல்ல. மூன்று சிறந்த நண்பர்களாவது கொண்டவனே பணக்காரன்*.

*14. எதிலும் தனித்துவமாக இருங்கள். பிறர் செய்வதையே வித்தியாசமாக, நேர்த்தியாக செய்யுங்கள்.*

*15. நீங்கள் படிக்க துவங்கும் எல்லா புத்தகமும் முழுவதுமாய் படித்து முடிக்க வேண்டியவை அல்ல. முதல் அரை மணியில் உங்களை கவரா விட்டால் அதனை மேலும் படித்து நேரத்தை வீணாக்காதீர்கள்*.

*16. உங்கள் தொலை/கை பேசி உங்கள் வசதிக்காக தான். அது அடிக்கும் ஒவ்வொரு முறையும் நீங்கள் எடுத்து பேச வேண்டும் என்பதில்லை. முக்கியமான வேளைகளில் நடுவே இருக்கும் போது தொலை பேசி மணி அடித்தாலும் எடுத்து பேசாதீர்கள்.*

*17. உங்கள் குடும்பத்தின் முக்கிய நிகழ்வுகளை அவசியம் புகைப்படம் எடுங்கள். பிற்காலத்தில் அந்த இனிய நாட்களுக்கு நீங்கள் சென்று வர அவை உதவும்.*

*18. அலுவலகம் முடிந்து கிளம்பும் போது சில நிமிடங்கள் வீட்டிற்கு சென்றதும் மனைவி/ குழந்தைக்கு என்ன செய்ய வேண்டுமென யோசியுங்கள்.*

*19. நீங்கள் எவ்வளவு வெற்றி அடைந்தாலும் எளிமையான (humble) மனிதராயிருங்கள்.* *வெற்றிகரமான பல மனிதர்கள் எளிமையானவர்களே!*
*"ஆணவம் ஆயுளை குறைக்கும்...*"

*மேற்கண்ட* *கருத்துக்களை பின் பற்றி,*
*ஆனந்தமாக வாழுங்கள்* *நண்பர் ஒருவர் எனக்கு அனுப்பியதை நமது குழுவிற்கு* *அனுப்பியுள்ளேன்.....!!!!*

Key To Success:

Success is ultimate happiness for achiever, but people who trying to achieve success still don't know what is the key to success? If we turn the pages in the historical records of achievers, we see a key rule in all achievers life. The key is persistence. From Prophet Muhammad to Mahatma Gandhi, Edison to Bill Gates, the common part is persistence. Living with a faith or belief is part of normal human being life, persistence differentiate the achievers from normal being.


Whatever you are stood for something and want to crack the concept of success, you always need to keep yourself in persistence mood which will revisit you to the hard core feeling that you are one step from the success. Greatest inventions came through from normal people who have the persistence in their mind. Thomas Alva Edison also lead a normal life but end up us greatest inventor of all time. Whenever he fails in an experiment, he iterate the experiment with changes in the mixture or elements until get a successful result.

Take a sample case:
If you are in a journey to learn some concepts. It might be a programming language, art works, sports and martial arts. In this case, I am taking martial arts as case study. We know Bruce Lee very well. He learn each move in wing chun till he perfect and mastering in it. Practice a kick 1000 times to master in it. Same philosophy which we discussing now. Persistence!!!
One time it might go wrong but 1000th time, it will give the fruit of success. Only people with persistence will taste that fruit.

Moral: Keep practising and stay persistent.

Post made by
newWorld

Operating system - Part 1:

 In our blog, we published several articles on OS concepts which mostly on the perspective for malware analysis/security research. In few in...