Hacking Windows Internals Cesar Cerrudo Argeniss Hacking Shared
- Slides: 31
Hacking Windows Internals Cesar Cerrudo Argeniss
Hacking Shared Sections Shared Section definition Using Shared Sections Tools Problems Searching for holes Exploitation Microsoft vulnerabilities Other vendors vulnerabilities Solutions Conclusions References
Shared Section Basically a Shared Section is a portion of memory shared by a process, mostly used as an IPC (Inter Process Communication) mechanism. Shared Memory. File Mapping. Named or Unnamed.
Using Shared Sections Loading binary images by OS. Process creation. Dll loading. Mapping kernel mode memory into user address space !? . Used to avoid kernel transitions. Sharing data between processes. GDI and GUI data, pointers !? , counters, any data.
Using Shared Sections Creating a shared section HANDLE Create. File. Mapping( HANDLE h. File, // handle to file (file mapping) //or 0 x. FFFF (shared memory) LPSECURITY_ATTRIBUTES lp. Attributes, // security DWORD fl. Protect, // protection DWORD dw. Maximum. Size. High, // high-order DWORD of size DWORD dw. Maximum. Size. Low, // low-order DWORD of size LPCTSTR lp. Name // object name (named) //or NULL (unnamed) ); //returns a shared section handle
Using Shared Sections Opening an existing shared section HANDLE Open. File. Mapping( DWORD dw. Desired. Access, // access mode (FILE_MAP_WRITE // FILE_MAP_READ, etc. ) BOOL b. Inherit. Handle, // inherit flag LPCTSTR lp. Name // shared section name ); //returns a shared section handle
Using Shared Sections Mapping a shared section LPVOID Map. View. Of. File( HANDLE h. File. Mapping. Object, // handle to created/opened // shared section DWORD dw. Desired. Access, // access mode(FILE_MAP_WRITE // FILE_MAP_READ, etc. ) DWORD dw. File. Offset. High, // high-order DWORD of offset DWORD dw. File. Offset. Low, // low-order DWORD of offset SIZE_T dw. Number. Of. Bytes. To. Map // number of bytes to map ); //returns a pointer to begining of shared section memory
Using Shared Sections Ntdll. dll Native API Nt. Create. Section() Nt. Open. Section() Nt. Map. View. Of. Section() Nt. Unmap. View. Of. Section() Nt. Query. Section() Nt. Extend. Section() Creates a new section Opens an existing section Map a section on memory Unmap a section from memory Returns section size Change section size
Using Shared Sections Mapping unnamed Shared Sections. Need to know shared section handle on target process. Need permissions on target process. Open. Process(PROCESS_DUP_HANDLE, . . . ) Duplicate. Handle(. . . ) Map. View. Of. File(. . . )
Using Shared Sections Demo
Tools Process Explorer Shows information about processes (dlls, handles, etc. ). Win. Obj Shows Object Manager Namespace information (objects info, permissions, etc. ) List. SS Lists Shared Sections names (local and TS sessions). Dump. SS Dumps Shared Section data. Test. SS Overwrites Shared Section data (to detect bugs)
Problems Input validation Weak permissions Synchronization
Problems Input validation Applications don't perform data validation before using the data. Applications trust data on shared sections. When applications read modified data from shared sections They will crash. They will perform unexpected actions.
Problems Weak permissions Low privileged users can access (read/write/change permissions) shared sections on high privileged processes (services). Terminal Services (maybe Citrix) users can access (read/write/change permissions) shared sections on local logged on user processes, services and also on other user sessions.
Problems Synchronization Not built-in synchronization. Synchronization must be done by processes in order to not corrupt data. There isn't a mechanism to force processes to synchronize or to block shared section access. Any process (with proper rights) can alter a shared section data while another process is using it.
Problems Synchronization Communication between Process A and B
Searching for holes Look for shared sections using Process Explorer, Win. Obj or List. SS. Attach a process using the shared section to a debugger. Run Test. SS on shared section. Interact with process in order to make it use (read/write) the shared section. Look at debugger for crashes : ).
Searching for holes Windows HTML Help Demo.
Exploitation Elevating privileges. Reading data. Altering data. Shared section exploits. Using shared sections on virus/rootkits/etc.
Exploitation Reading data. From high privileged processes (services). From local logged on user processes, services and other sessions on Terminal Services. This leads to unauthorized access to data.
Exploitation Altering data. On high privileged processes (services). On local logged on user processes, services and other sessions on Terminal Services. This leads to arbitrary code execution, unauthorized access, processes or kernel crashing (DOS).
Exploitation Shared section exploits. When overwriting shared section data allow us to take control of code execution. Some shared sections start addresses are pretty static on same OS and Service Pack. Put shellcode on shared section. Build exploit to jump to shellcode on shared section at static location.
Exploitation Shared section exploits. MS 05 -012 - COM Structured Storage Vulnerability Weak permission on shared section. Structures saved on shared section can be overwriten. By overwriting these structures is possible to execute arbitrary code. POC Exploit Demo.
Exploitation Using shared sections on virus/rootkits/etc. Some shared sections are used by many processes (Internat. SHData used for Language Settings on W 2 k) others sections are used by all processes : ). Write code to shared section and the code will be instantly mapped on processes memory and also on new created processes. Use Set. Thread. Context() or Create. Remote. Thread() to start executing code. Similar to Write. Process. Memory() - Set. Thread. Context() technique or DLL Injection.
Exploitation Using shared sections on virus/rootkits/etc. Some shared sections have execute access. It would be possible to avoid Win. XP sp 2 NX and third party protections.
Microsoft vulnerabilities Vulnerabilities on next Microsoft products have been reported and are being fixed: Internet Explorer vulnerability. Office vulnerabilities. Windows 2 k and Windows XP sp 2 Kernel vulnerability. IIS 5 vulnerabiliity. Windows COM vulnerability.
Other vendors vulnerabilities NOD 32 antivirus vulnerability. Norton Antivirus (old versions) vulnerability. Veritas software vulnerabilities. Etc.
Solutions Set proper permissions Set only current user (also service account if application running as service) permissions on shared sections unless another user should access them. Use some synchronization mechanism Remember that when working with shared sections there isn't built in synchronization. Validate the data before using it Data on shared sections can be easily manipulated.
Conclusions Windows and 3 rd. party applications have a bunch of Shared Section related holes. These kind of holes will lead to new kind of attacks “SSAtacks” (Shared Section Attacks) ; ) Microsoft forgot to include a Shared Sections audit on the trustworthy computing initiative : ). Windows guts seem rotten: ).
References MSDN Programming Applications for MS Windows - Fourth Edition Process Explorer (www. sysinternals. com) Win. Obj (www. sysinternals. com) Rattle - Using Process Infection to Bypass Windows Software Firewalls (PHRACK #62) Crazylord - Playing with Windows /dev/(k)mem (PHRACK #59) http: //www. microsoft. com/technet/security/bulletin/MS 05 -012. mspx
FIN • Questions? • Thanks. • Contact: cesar>at<argeniss>dot<com Argeniss – Information Security Get vulnerability information before anyone! http: //www. argeniss. com/services. html
- Createfilemapping
- Aldy bug
- Ntos kernel
- Windows kernel internals
- Windows internals tutorial
- Windows kernel internals
- Advapi
- Ndis.sys latency
- Windows kernel internals
- Ntfs internals
- Zfs dnode
- Operating system internals and design principles
- Azure internals
- Jvm internals
- Operating systems: internals and design principles
- Mfc
- Vnode unix
- Unix internals
- Sql server internals and architecture
- Mfc internals
- Shivaram venkataraman
- Android internals
- Mfc 프로그래밍
- Operating system internals and design principles
- Operating systems: internals and design principles
- Azure internals
- Operating systems: internals and design principles
- Operating systems internals and design principles
- Namei algorithm
- Linux kernel internals
- Operating systems: internals and design principles
- Operating systems: internals and design principles