How TeamViewer stores passwords


TeamViewer is a popular program for remote access to the desktop. Therefore, it’s quite interesting to see how it stores passwords. In short, passwords are encrypted in the Windows registry. For encryption, the AES-128-CBC algorithm and the secret key 0602000000a400005253413100040000 are used .

This method of saving passwords and the associated privilege escalation were officially registered on February 7, 2020 as the vulnerability CVE-2019-18988 (applies to all versions of TeamViewer up to and including 07/14/1965).

The novice security specialist who unveiled this vulnerability stumbled upon it by accident. He says that he worked for the client and during the backup noticed the TeamViewer registry keys, which were called OptionsPasswordAESand SecurityPasswordAES.

Subsequently, he became interested in what these keys were and how TeamViewer stores passwords in general. He imported them to a fresh system in a virtual machine and launched the BulletPassView scanner , which collects passwords in the system. Scanner gave TeamViewer password in clear text.


Scanner BulletPassView

Then, using the Cheat Engine program (for hacking games under Windows), a specialist searched for this password in RAM - and found it again in plain text. Later it turned out that this vulnerability was already fixed two years ago as CVE-2018-14333 .

Then it’s time to check where the key is taken from in the TeamViewer client’s memory: from the server or from the local host. It turned out that there is no network traffic, but there is still a password in the memory. The reverse engineering of the TeamViewer binary using IDA Pro, API Monitor , procdump and Frida took several weeks, but did not give anything, although the guy mastered several new tools along the way, so the process cannot be called useless.

During the search for information, it turned out that quite a few people already wondered how to find AES keys for Unity games in the resources. It turned out that this is a very simple process, for which it is enough to use a debugger . Six hours later, he found a piece of TeamViewer code responsible for AES encryption:

=================================================
"ServerPasswordAES"=hex:88,44,d7,0a,b2,96,2a,3d,63,16,3c,ff,e4,15,04,fb
=================================================
Takes 8844d70ab2962a3d63163cffe41504fb into xmm0
Takes 5B659253E5E873D26723B7D5EAC06E3B into xmm1
pxor xmm0, xmm1
movdqa xmmword ptr ds:[eax],xmm0
[eax] = D3214559577E59EF04358B2A0ED56AC0

movdqa xmm1,xmmword ptr ds:[esi] | [esi] = 25C8C8BD4298BB32A57EECBDBD045BBB
movdqa xmm0,xmmword ptr ds:[eax] | [eax] = D3214559577E59EF04358B2A0ED56AC0
aesdec xmm0,xmm1 | One round of an AES decryption, using Equivalent Inverse Cipher, 128-bit data (state) from xmm1 with 128-bit round key from xmm2/m128; store the result in xmm1.
movdqa xmmword ptr ds:[eax],xmm0 | [eax] = 6F AA 98 76 DE 11 7D 8D 7E B6 EE 61 2D 3D 15 52
movdqa xmm1,xmmword ptr ds:[esi+10] | [esi+10]=[008FDE10]=79 DC 78 A6 67 50 73 8F E7 E6 57 8F 18 7A B7 06
add esi,20 |
dec ecx | ecx = 3
aesdec xmm0,xmm1 | do the actual decryption
movdqa xmmword ptr ds:[eax],xmm0 | [eax]=[008FDC90]=E3 58 26 46 A7 37 12 40 85 1C C0 43 7D 1F 1E 30

Three more rounds of aesdec then
aesdeclast xmm0, xmm1 .| Last round of AES decryption, using Equivalent Inverse Cipher, 128-bit data (state) from xmm2 with a 128-bit round key from xmm3/m128; store the result in xmm1.

008FDC90 01 00 01 00 67 24 4F 43 6E 67 62 F2 5E A8 D7 04 ....g$OCngbò^¨×.

This code takes a few bytes from the register ServerPasswordAESand decrypts them with the key obtained by XOR'a prescribed value esiand eax. The result is a key 0602000000a400005253413100040000, and the value of IV is equal 0100010067244F436E6762F25EA8D704.

In TeamViewer 14, the new scripting engine allows you to increase privileges by NT AUTHORITY\SYSTEMreading the TeamViewer password in the registry with user rights.

Well, you can also decrypt some other passwords by googling [SecurityPasswordAES], [OptionsPasswordAES], [SecurityPasswordExported] or [PermanentPassword] with the search parameter [filetype: reg].

TeamViewer has closed this vulnerability in recent versions. As the program now encrypts passwords, they have not figured it out yet.

All Articles