首页
社区
课程
招聘
[求助]如何查看进程对应文件的数字签名?
发表于: 2017-5-19 17:42 4142

[求助]如何查看进程对应文件的数字签名?

2017-5-19 17:42
4142

我们做终端机程序,远程监控时发现有的设备被人家修改了替换了我们的程序。我们的守护进程目前只是简单的查看进程中是否我们的程序在运行,没有的话,会发消息到我们的服务器,报警。但是如果他们修改的名字跟我们的程序名字一样,就不能监控到问题了。

问题:

能否通过数字签名的方式,就是把我们的程序签名,然后守护进程验证?如果可以改如何操作?如果不可以,有没有其他好的办法?


[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 1711
活跃值: (516)
能力值: ( LV12,RANK:200 )
在线值:
发帖
回帖
粉丝
2
用CryptoAPI
https://msdn.microsoft.com/en-us/library/aa380252.aspx
2017-5-19 18:28
0
雪    币: 1
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3

用signtool,简单明了

signtool verify /v /pa "xxx.exe"

2017-5-19 19:35
0
雪    币: 230
活跃值: (137)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
可以对exe进行玩整性检测,md5  码肯定不一样的吧
2017-5-19 20:41
0
雪    币: 583
活跃值: (147)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
Funcer 用signtool,简单明了signtool verify /v /pa "xxx.exe"
目测  题主  需要的是  编程的方式吧。

2017-5-22 19:08
0
雪    币: 8
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
//-------------------------------------------------------------------
//  Copyright  (c)  Microsoft  Corporation.  All  rights  reserved.
//  Example  of  verifying  the  embedded  signature  of  a  PE  file  by  using 
//  the  WinVerifyTrust  function.
#define  _UNICODE  1
#define  UNICODE  1
#include  <tchar.h>
#include  <stdio.h>
#include  <stdlib.h>
#include  <windows.h>
#include  <Softpub.h>
#include  <wincrypt.h>
#include  <wintrust.h>
//  Link  with  the  Wintrust.lib  file.
#pragma  comment  (lib,  "wintrust")
BOOL  VerifyEmbeddedSignature(LPCWSTR  pwszSourceFile)
{
        LONG  lStatus;
        DWORD  dwLastError;
        //  Initialize  the  WINTRUST_FILE_INFO  structure.
        WINTRUST_FILE_INFO  FileData;
        memset(&FileData,  0,  sizeof(FileData));
        FileData.cbStruct  =  sizeof(WINTRUST_FILE_INFO);
        FileData.pcwszFilePath  =  pwszSourceFile;
        FileData.hFile  =  NULL;
        FileData.pgKnownSubject  =  NULL;
        /*
        WVTPolicyGUID  specifies  the  policy  to  apply  on  the  file
        WINTRUST_ACTION_GENERIC_VERIFY_V2  policy  checks:
        1)  The  certificate  used  to  sign  the  file  chains  up  to  a  root 
        certificate  located  in  the  trusted  root  certificate  store.  This 
        implies  that  the  identity  of  the  publisher  has  been  verified  by 
        a  certification  authority.
        2)  In  cases  where  user  interface  is  displayed  (which  this  example
        does  not  do),  WinVerifyTrust  will  check  for  whether  the 
        end  entity  certificate  is  stored  in  the  trusted  publisher  store, 
        implying  that  the  user  trusts  content  from  this  publisher.
        3)  The  end  entity  certificate  has  sufficient  permission  to  sign 
        code,  as  indicated  by  the  presence  of  a  code  signing  EKU  or  no 
        EKU.
        */
        GUID  WVTPolicyGUID  =  WINTRUST_ACTION_GENERIC_VERIFY_V2;
        WINTRUST_DATA  WinTrustData;
        //  Initialize  the  WinVerifyTrust  input  data  structure.
        //  Default  all  fields  to  0.
        memset(&WinTrustData,  0,  sizeof(WinTrustData));
        WinTrustData.cbStruct  =  sizeof(WinTrustData);
        //  Use  default  code  signing  EKU.
        WinTrustData.pPolicyCallbackData  =  NULL;
        //  No  data  to  pass  to  SIP.
        WinTrustData.pSIPClientData  =  NULL;
        //  Disable  WVT  UI.
        WinTrustData.dwUIChoice  =  WTD_UI_NONE;
        //  No  revocation  checking.
        WinTrustData.fdwRevocationChecks  =  WTD_REVOKE_NONE; 
        //  Verify  an  embedded  signature  on  a  file.
        WinTrustData.dwUnionChoice  =  WTD_CHOICE_FILE;
        //  Default  verification.
        WinTrustData.dwStateAction  =  0;
        //  Not  applicable  for  default  verification  of  embedded  signature.
        WinTrustData.hWVTStateData  =  NULL;
        //  Not  used.
        WinTrustData.pwszURLReference  =  NULL;
        //  Default.
        WinTrustData.dwProvFlags  =  WTD_SAFER_FLAG;
        //  This  is  not  applicable  if  there  is  no  UI  because  it  changes 
        //  the  UI  to  accommodate  running  applications  instead  of 
        //  installing  applications.
        WinTrustData.dwUIContext  =  0;
        //  Set  pFile.
        WinTrustData.pFile  =  &FileData;
        //  WinVerifyTrust  verifies  signatures  as  specified  by  the  GUID 
        //  and  Wintrust_Data.
        lStatus  =  WinVerifyTrust(
                NULL,
                &WVTPolicyGUID,
                &WinTrustData);
        switch  (lStatus) 
        {
        case  ERROR_SUCCESS:
                /*
                Signed  file:
                -  Hash  that  represents  the  subject  is  trusted.
                -  Trusted  publisher  without  any  verification  errors.
                -  UI  was  disabled  in  dwUIChoice.  No  publisher  or 
                time  stamp  chain  errors.
                -  UI  was  enabled  in  dwUIChoice  and  the  user  clicked 
                "Yes"  when  asked  to  install  and  run  the  signed 
                subject.
                */
                wprintf_s(L"The  file  \"%s\"  is  signed  and  the  signature  "
                        L"was  verified.\n",
                        pwszSourceFile);
                break;
        case  TRUST_E_NOSIGNATURE:
                //  The  file  was  not  signed  or  had  a  signature 
                //  that  was  not  valid.
                //  Get  the  reason  for  no  signature.
                dwLastError  =  GetLastError();
                if  (TRUST_E_NOSIGNATURE  ==  dwLastError  ||
                        TRUST_E_SUBJECT_FORM_UNKNOWN  ==  dwLastError  ||
                        TRUST_E_PROVIDER_UNKNOWN  ==  dwLastError) 
                {
                        //  The  file  was  not  signed.
                        wprintf_s(L"The  file  \"%s\"  is  not  signed.\n",
                                pwszSourceFile);
                } 
                else 
                {
                        //  The  signature  was  not  valid  or  there  was  an  error 
                        //  opening  the  file.
                        wprintf_s(L"An  unknown  error  occurred  trying  to  "
                                L"verify  the  signature  of  the  \"%s\"  file.\n",
                                pwszSourceFile);
                }
                break;
        case  TRUST_E_EXPLICIT_DISTRUST:
                //  The  hash  that  represents  the  subject  or  the  publisher 
                //  is  not  allowed  by  the  admin  or  user.
                wprintf_s(L"The  signature  is  present,  but  specifically  "
                        L"disallowed.\n");
                break;
        case  TRUST_E_SUBJECT_NOT_TRUSTED:
                //  The  user  clicked  "No"  when  asked  to  install  and  run.
                wprintf_s(L"The  signature  is  present,  but  not  "
                        L"trusted.\n");
                break;
        case  CRYPT_E_SECURITY_SETTINGS:
                /*
                The  hash  that  represents  the  subject  or  the  publisher 
                was  not  explicitly  trusted  by  the  admin  and  the 
                admin  policy  has  disabled  user  trust.  No  signature, 
                publisher  or  time  stamp  errors.
                */
                wprintf_s(L"CRYPT_E_SECURITY_SETTINGS  -  The  hash  "
                        L"representing  the  subject  or  the  publisher  wasn't  "
                        L"explicitly  trusted  by  the  admin  and  admin  policy  "
                        L"has  disabled  user  trust.  No  signature,  publisher  "
                        L"or  timestamp  errors.\n");
                break;
        default:
                //  The  UI  was  disabled  in  dwUIChoice  or  the  admin  policy 
                //  has  disabled  user  trust.  lStatus  contains  the 
                //  publisher  or  time  stamp  chain  error.
                wprintf_s(L"Error  is:  0x%x.\n",
                        lStatus);
                break;
        }
        return  true;
}
int  _tmain(int  argc,  _TCHAR*  argv[])
{
        if(argc  >  1)
        {
                VerifyEmbeddedSignature(argv[1]);
        }
        return  0;
}
2017-5-22 19:16
0
游客
登录 | 注册 方可回帖
返回
//