Skip to content

Commit 03068a3

Browse files
committed
Add small tool to decrypt community auth sessions
If the url is retreived from the other end (the auth_receive url), one can paste in the querystring and get the details out, using the crypto key from the database.
1 parent 2b59c9c commit 03068a3

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

pgweb/account/management/__init__.py

Whitespace-only changes.

pgweb/account/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dump interesting information out of django sessions
2+
#
3+
# (This is particarly interesting when digging through old stack trace emails..)
4+
#
5+
from django.core.management.base import BaseCommand, CommandError
6+
7+
import base64
8+
from urllib.parse import parse_qs
9+
10+
from Cryptodome.Cipher import AES
11+
12+
from pgweb.account.models import CommunityAuthSite
13+
14+
15+
class Command(BaseCommand):
16+
help = 'Decrypt a community authentication session'
17+
18+
def add_arguments(self, parser):
19+
parser.add_argument('siteid', help='Community auth site id')
20+
parser.add_argument('querystring', help='Query string, including d=')
21+
22+
def handle(self, *args, **options):
23+
cs = CommunityAuthSite.objects.get(pk=options['siteid'])
24+
reqvars = parse_qs(options['querystring'].lstrip('?'))
25+
26+
decryptor = AES.new(base64.b64decode(cs.cryptkey), AES.MODE_SIV, base64.urlsafe_b64decode(reqvars['n'][0]))
27+
r = decryptor.decrypt_and_verify(base64.urlsafe_b64decode(reqvars['d'][0]), base64.urlsafe_b64decode(reqvars['t'][0])).decode()
28+
vals = parse_qs(r)
29+
30+
print("User: {}".format(vals['u'][0]))
31+
print("Firstname: {}".format(vals['f'][0]))
32+
print("Lastname: {}".format(vals['l'][0]))
33+
print("Email: {}".format(vals['e'][0]))

0 commit comments

Comments
 (0)