コード例 #1
0
def test_wipe(basicteststr):
    """
    Basic test of the wipe function
    """
    len_prewipe = len(basicteststr)
    memwiper.wipeit(basicteststr)
    assert len_prewipe == len(basicteststr)
コード例 #2
0
def test_huge_string_wipe(widetestchar):
    """
    Test HUGE (1M) string wipe
    """
    # Make s1 size 1M besides the len of s1
    s1 = widetestchar * int((2**3) / len(widetestchar))
    len_prewipe = len(s1)
    memwiper.wipeit(s1)
    scmp = make_str(widetestchar, len_prewipe)
    assert type(s1) == type(scmp)
    assert len(s1) == len_prewipe
    assert s1 == scmp
    assert hash(s1) == hash(scmp)
    del s1
コード例 #3
0
def test_long_string_wipe(widetestchar):
    """
    Test long (32k) string wipe
    """
    # Make s1 fixed side besides the len of s1
    s1 = widetestchar * int((2**2) / len(widetestchar))
    len_prewipe = len(s1)
    memwiper.wipeit(s1)
    scmp = make_str(widetestchar, len_prewipe)
    assert type(s1) == type(scmp)
    assert len(s1) == len_prewipe
    assert s1 == scmp
    assert hash(s1) == hash(scmp)
    del s1
コード例 #4
0
def test_multiple_references(basicteststr):
    """
    Test with multiple references to the same string
    """
    s1 = basicteststr
    s2 = s1
    lenbasicteststr = len(basicteststr)
    memwiper.wipeit(s1)
    assert s1 == basicteststr
    assert len(s1) == lenbasicteststr
    assert s2 == basicteststr
    assert len(s2) == lenbasicteststr
    assert s1 == s2
    assert len(s1) == len(s2)
コード例 #5
0
ファイル: _coretest.py プロジェクト: qlixed/python-memwiper
def main():
    if platform.system().lower() != "linux":
        print("Sorry, currently this work only on linux.")
        sysexit(-1)
    sfromfile = None
    mypid = os.getpid()
    if shutil.which("gdb") is None:
        print("There is no gdb to use for this example! :()")
        sysexit(-1)
    # Generating the secret file:
    print("Generating the supersecretinfo.txt file:")
    p = multiprocessing.Process(target=supersecretinfogenerator)
    p.start()
    p.join()
    # Reading the contents of the file:
    with open("supersecretinfo.txt", "r") as f:
        sfromfile = f.read()
    if sfromfile is None:
        print("Well, did you write nothing? Or maybe cancel the input?")
        sysexit(-1)
    # Showing the secret:
    print("The super secret info is:", sfromfile)
    # "Decoding" the file:
    s1 = codecs.encode(sfromfile, "rot_13")
    # Generating pre-core
    print("Generating {f}.{pid}:".format(f=corefn.format(when="pre"),
                                         pid=mypid))
    cmd = gdb_cmds
    corename = corefn.format(when="pre")
    print(cmd.format(filename=corename, pid=mypid))
    subprocess.run(shlex.split(cmd.format(filename=corename, pid=mypid)))
    print("Now we're going to overwrite the memory,")
    memwiper.wipeit(s1)
    # Generating pos-core
    print("Generating {f}.{pid}:".format(f=corefn.format(when="pos"),
                                         pid=mypid))
    corename = corefn.format(when="pos")
    print(cmd.format(filename=corename, pid=mypid))
    subprocess.run(shlex.split(cmd.format(filename=corename, pid=mypid)))
    s1 = codecs.encode(sfromfile, "rot_13")
    print("""Well, all done now you can check the files using:

# strings core-pre.{pid} | grep '{ssi}'
# strings core-pos.{pid} | grep '{ssi}'

The core-pre.{pid} contains the secret, as object was active in memory.
The core-pos.{pid} don't contains the secret, because we wipeit() from memory.
""".format(pid=mypid, ssi=s1))