mirror of https://github.com/pwndbg/pwndbg.git
fix(tempdir): use safe and unpredictable cachedir location
The typeinfo module used a static global tempdir location of /tmp/pwndbg that an attacker may control and prepare symlinks of the predictable files that are then written to.pull/972/head
parent
1c633829de
commit
3583b5704e
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Common helper and cache for pwndbg tempdir
|
||||
"""
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import pwndbg.memoize
|
||||
|
||||
|
||||
@pwndbg.memoize.forever
|
||||
def tempdir():
|
||||
"""
|
||||
Returns a safe and unpredictable temporary directory with pwndbg prefix.
|
||||
"""
|
||||
return tempfile.mkdtemp(prefix='pwndbg-')
|
||||
|
||||
|
||||
@pwndbg.memoize.forever
|
||||
def cachedir(namespace=None):
|
||||
"""
|
||||
Returns and potentially creates a persistent safe cachedir location
|
||||
based on XDG_CACHE_HOME or ~/.cache
|
||||
|
||||
Optionally creates a sub namespace inside the pwndbg cache folder.
|
||||
"""
|
||||
cachehome = os.getenv('XDG_CACHE_HOME')
|
||||
if not cachehome:
|
||||
cachehome = os.path.join(os.getenv('HOME'), '.cache')
|
||||
cachedir = os.path.join(cachehome, 'pwndbg')
|
||||
if namespace:
|
||||
cachedir = os.path.join(cachedir, namespace)
|
||||
os.makedirs(cachedir, exist_ok=True)
|
||||
return cachedir
|
||||
Loading…
Reference in new issue