Как выгрузить DLL из чужого процесса?

Тема в разделе "WASM.BEGINNERS", создана пользователем _nic, 4 июн 2009.

  1. _nic

    _nic New Member

    Публикаций:
    0
    Регистрация:
    4 фев 2007
    Сообщения:
    372
    Как можно это реализовать?
     
  2. Clerk

    Clerk Забанен

    Публикаций:
    0
    Регистрация:
    4 янв 2008
    Сообщения:
    6.689
    Адрес:
    РБ, Могилёв
    http://wasm.ru/forum/viewtopic.php?id=28952&p=1
    http://wasm.ru/forum/viewtopic.php?id=22211
    Или удалённо проделать туже работу, что делает лодер при выгрузке(очистить базу данных, выгрузить импорт и пр.)
     
  3. wasm_test

    wasm_test wasm test user

    Публикаций:
    0
    Регистрация:
    24 ноя 2006
    Сообщения:
    5.582
    LibraryPath = VirtualAllocEx (hProcess, .....
    WriteProcessMemory (hProcess, LibraryPath, "yourlib.dll", ...
    CreateRemoteThread (..., FreeLibrary, LibraryPath, ....

    м?
     
  4. _nic

    _nic New Member

    Публикаций:
    0
    Регистрация:
    4 фев 2007
    Сообщения:
    372
    А указатель hProcess получать через OpenProcess?
     
  5. _nic

    _nic New Member

    Публикаций:
    0
    Регистрация:
    4 фев 2007
    Сообщения:
    372
    Чего я не так понял????
    Код (Text):
    1. typedef LONG KPRIORITY;
    2. typedef int NTSTATUS;
    3. typedef enum _SYSTEMINFOCLASS
    4. {
    5. SystemBasicInformation, // 0x002C
    6. SystemProcessorInformation, // 0x000C
    7. SystemPerformanceInformation, // 0x0138
    8. SystemTimeInformation, // 0x0020
    9. SystemPathInformation, // not implemented
    10. SystemProcessInformation, // 0x00C8+ per process
    11. SystemCallInformation, // 0x0018 + (n * 0x0004)
    12. SystemConfigurationInformation, // 0x0018
    13. SystemProcessorCounters, // 0x0030 per cpu
    14. SystemGlobalFlag, // 0x0004 (fails if size != 4)
    15. SystemCallTimeInformation, // not implemented
    16. SystemModuleInformation, // 0x0004 + (n * 0x011C)
    17. SystemLockInformation, // 0x0004 + (n * 0x0024)
    18. SystemStackTraceInformation, // not implemented
    19. SystemPagedPoolInformation, // checked build only
    20. SystemNonPagedPoolInformation, // checked build only
    21. SystemHandleInformation, // 0x0004 + (n * 0x0010)
    22. SystemObjectTypeInformation, // 0x0038+ + (n * 0x0030+)
    23. SystemPageFileInformation, // 0x0018+ per page file
    24. SystemVdmInstemulInformation, // 0x0088
    25. SystemVdmBopInformation, // invalid info class
    26. SystemCacheInformation, // 0x0024
    27. SystemPoolTagInformation, // 0x0004 + (n * 0x001C)
    28. SystemInterruptInformation, // 0x0000, or 0x0018 per cpu
    29. SystemDpcInformation, // 0x0014
    30. SystemFullMemoryInformation, // checked build only
    31. SystemLoadDriver, // 0x0018, set mode only
    32. SystemUnloadDriver, // 0x0004, set mode only
    33. SystemTimeAdjustmentInformation, // 0x000C, 0x0008 writeable
    34. SystemSummaryMemoryInformation, // checked build only
    35. SystemNextEventIdInformation, // checked build only
    36. SystemEventIdsInformation, // checked build only
    37. SystemCrashDumpInformation, // 0x0004
    38. SystemExceptionInformation, // 0x0010
    39. SystemCrashDumpStateInformation, // 0x0004
    40. SystemDebuggerInformation, // 0x0002
    41. SystemContextSwitchInformation, // 0x0030
    42. SystemRegistryQuotaInformation, // 0x000C
    43. SystemAddDriver, // 0x0008, set mode only
    44. SystemPrioritySeparationInformation,// 0x0004, set mode only
    45. SystemPlugPlayBusInformation, // not implemented
    46. SystemDockInformation, // not implemented
    47. SystemPowerInfo, // 0x0060 (XP only!)
    48. SystemProcessorSpeedInformation, // 0x000C (XP only!)
    49. SystemTimeZoneInformation, // 0x00AC
    50. SystemLookasideInformation, // n * 0x0020
    51. SystemSetTimeSlipEvent,
    52. SystemCreateSession, // set mode only
    53. SystemDeleteSession, // set mode only
    54. SystemInvalidInfoClass1, // invalid info class
    55. SystemRangeStartInformation, // 0x0004 (fails if size != 4)
    56. SystemVerifierInformation,
    57. SystemAddVerifier,
    58. SystemSessionProcessesInformation, // checked build only
    59. MaxSystemInfoClass
    60. } SYSTEMINFOCLASS, *PSYSTEMINFOCLASS;
    61.  
    62. typedef enum
    63. {
    64. StateInitialized,
    65. StateReady,
    66. StateRunning,
    67. StateStandby,
    68. StateTerminated,
    69. StateWait,
    70. StateTransition,
    71. StateUnknown
    72. } THREAD_STATE;
    73.  
    74. typedef enum _KWAIT_REASON
    75. {
    76. Executive,
    77. FreePage,
    78. PageIn,
    79. PoolAllocation,
    80. DelayExecution,
    81. Suspended,
    82. UserRequest,
    83. WrExecutive,
    84. WrFreePage,
    85. WrPageIn,
    86. WrPoolAllocation,
    87. WrDelayExecution,
    88. WrSuspended,
    89. WrUserRequest,
    90. WrEventPair,
    91. WrQueue,
    92. WrLpcReceive,
    93. WrLpcReply,
    94. WrVirtualMemory,
    95. WrPageOut,
    96. WrRendezvous,
    97. Spare2,
    98. Spare3,
    99. Spare4,
    100. Spare5,
    101. Spare6,
    102. WrKernel,
    103. MaximumWaitReason
    104. } KWAIT_REASON, *PKWAIT_REASON;
    105.  
    106. typedef struct _CLIENT_ID
    107. {
    108. HANDLE UniqueProcess;
    109. HANDLE UniqueThread;
    110. } CLIENT_ID, *PCLIENT_ID;
    111.  
    112. typedef struct _UNICODE_STRING
    113. {
    114. USHORT Length;
    115. USHORT MaximumLength;
    116. PWSTR Buffer;
    117. } UNICODE_STRING, *PUNICODE_STRING;
    118.  
    119. typedef struct _SYSTEM_THREAD
    120. {
    121. LARGE_INTEGER liKernelTime; // 100 nsec units
    122. LARGE_INTEGER liUserTime; // 100 nsec units
    123. LARGE_INTEGER liCreateTime; // relative to 01-01-1601
    124. ULONG WaitTime; // ticks
    125. PVOID pStartAddress; // EIP
    126. CLIENT_ID Cid; // process/thread ids
    127. KPRIORITY Priority;
    128. KPRIORITY BasePriority;
    129. ULONG ContextSwitches;
    130. THREAD_STATE ThreadState;
    131. KWAIT_REASON WaitReason;
    132. // DWORD dwUnknown2; // maybe it not exists !!!
    133. } SYSTEM_THREAD, *PSYSTEM_THREAD;
    134.  
    135. typedef struct _VM_COUNTERS
    136. {
    137. ULONG uPeakVirtualSize;
    138. ULONG uVirtualSize;
    139. ULONG uPageFaultCount;
    140. ULONG uPeakWorkingSetSize;
    141. ULONG uWorkingSetSize;
    142. ULONG uQuotaPeakPagedPoolUsage;
    143. ULONG uQuotaPagedPoolUsage;
    144. ULONG uQuotaPeakNonPagedPoolUsage;
    145. ULONG uQuotaNonPagedPoolUsage;
    146. ULONG uPagefileUsage;
    147. ULONG uPeakPagefileUsage;
    148. } VM_COUNTERS, *PVM_COUNTERS;
    149.  
    150. typedef struct _IOCOUNTERS
    151. {
    152. ULONG uReadOperationCount;
    153. ULONG uWriteOperationCount;
    154. ULONG uOtherOperationCount;
    155. LARGE_INTEGER liReadTransferCount;
    156. LARGE_INTEGER liWriteTransferCount;
    157. LARGE_INTEGER liOtherTransferCount;
    158. } IOCOUNTERS, *PIOCOUNTERS;
    159.  
    160. typedef struct _SYSTEM_PROCESS_INFORMATION
    161. {
    162. ULONG uNext; // relative offset
    163. ULONG uThreadCount;
    164. LARGE_INTEGER liUnknown1;
    165. LARGE_INTEGER liUnknown2;
    166. LARGE_INTEGER liUnknown3;
    167. LARGE_INTEGER liCreateTime; // relative to 01-01-1601
    168. LARGE_INTEGER liUserTime; // 100 nsec units
    169. LARGE_INTEGER liKernelTime; // 100 nsec units
    170. UNICODE_STRING usName;
    171. KPRIORITY BasePriority;
    172. ULONG uUniqueProcessId;
    173. ULONG uInheritedFromUniqueProcessId;
    174. ULONG uHandleCount;
    175. ULONG uSessionId; // W2K Only!
    176. DWORD dwUnknown5;
    177. VM_COUNTERS VmCounters;
    178. ULONG uCommitCharge; // bytes
    179. SYSTEM_THREAD aST[];
    180. } SYSTEM_PROCESS_INFORMATION, *PSYSTEM_PROCESS_INFORMATION;
    181.  
    182. typedef NTSTATUS (NTAPI *PZwQuerySystemInformation)(
    183. SYSTEMINFOCLASS SystemInformationClass,
    184. PVOID pSystemInformation,
    185. ULONG uSystemInformationLength,
    186. PULONG puReturnLength
    187. );
    188. typedef BOOL (WINAPI *PWinStationGetProcessSid)(HANDLE hServer,DWORD ProcessId,FILETIME ProcessStartTime,PBYTE pProcessUserSid,PDWORD dwSidSize);
    189. typedef void (WINAPI *PCachedGetUserFromSid)(PSID pSid , PWCHAR pUserName, PULONG cbUserName);
    190. PZwQuerySystemInformation ZwQuerySystemInformation;
    191. PWinStationGetProcessSid WinStationGetProcessSid;
    192. PCachedGetUserFromSid CachedGetUserFromSid;
    193. PSYSTEM_PROCESS_INFORMATION SPI=NULL;
    194. ULONG memlen,bw;
    195. char PrcName[1024];
    196. DWORD nameSize;
    197. wchar_t OwnerName[1024];
    198. char buf[2048];
    199. char buff[1024*70];strcpy(buff,"PID:Threads:\tUser:\t\tName:\n");
    200. ULONG  reqSize = 0;
    201. ULONG  sidSize;
    202. PSID    pSid;
    203. HMODULE winsta = NULL;
    204. HMODULE utildll = NULL;
    205. winsta = LoadLibrary("winsta.dll");
    206. WinStationGetProcessSid = (PWinStationGetProcessSid)GetProcAddress(winsta, "WinStationGetProcessSid");
    207. utildll = LoadLibrary("utildll.dll");
    208. CachedGetUserFromSid = (PCachedGetUserFromSid)GetProcAddress(utildll, "CachedGetUserFromSid");
    209. (int(__stdcall*)())ZwQuerySystemInformation=GetProcAddress(GetModuleHandle("ntdll.dll"),"ZwQuerySystemInformation");
    210. ZwQuerySystemInformation(SystemProcessInformation,SPI,0,&memlen);
    211. (void*)SPI=VirtualAlloc(NULL,memlen,MEM_COMMIT,PAGE_READWRITE);
    212. if(!ZwQuerySystemInformation(SystemProcessInformation,SPI,memlen,&bw))
    213. while(SPI->uNext>0)
    214. {
    215. (void*)SPI=(PVOID)(SPI->uNext+(ULONG)SPI);
    216. if((SPI->usName.Length / 2)>=sizeof(PrcName)-1)continue;
    217. sidSize = 0;
    218. pSid = NULL;
    219. nameSize = MAX_PATH;
    220. WinStationGetProcessSid(NULL, (DWORD)SPI->uUniqueProcessId,*((FILETIME *)&SPI->liCreateTime), (PBYTE)pSid, &sidSize);
    221. if ((pSid = malloc(sidSize)) != NULL)
    222. {
    223. WinStationGetProcessSid(NULL,(DWORD)SPI->uUniqueProcessId, *((FILETIME *)&SPI->liCreateTime),(PBYTE)pSid, &sidSize);
    224. CachedGetUserFromSid(pSid,OwnerName,&nameSize);
    225. free(pSid);
    226. }
    227. /*wcstombs(PrcName,SPI->usName.Buffer,SPI->usName.Length);
    228. wsprintf(buf,"%u     \t%u\t\t%ws\t\t%s\n",SPI->uUniqueProcessId,SPI->uThreadCount,OwnerName,PrcName);   */
    229. HANDLE hproc=OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION |PROCESS_VM_WRITE | SYNCHRONIZE,FALSE,SPI->uUniqueProcessId);
    230. LPVOID lib=VirtualAllocEx( hproc, 0, 0x1000, MEM_COMMIT, PAGE_EXECUTE_READWRITE );
    231. WriteProcessMemory(hproc,lib,"ntdll.dll",0x1000,0);
    232. CreateRemoteThread(hproc,0,0,FreeLibrary,lib,0,0,0);
    233. strcat(buff,buf);
    234. }
    235. VirtualFree(SPI,memlen,MEM_DECOMMIT);
     
  6. wasm_test

    wasm_test wasm test user

    Публикаций:
    0
    Регистрация:
    24 ноя 2006
    Сообщения:
    5.582
    _nic
    ОЯЕ***! про CreateToolhelp32Snapshot не слышали?