0

我正在尝试在 python 中解析一个 pwdump 文件。pwdump 文件的内容如下所示:

...[snip]

Domain\TESTIN$::aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

Guest(current):501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

Guest(hist_01):501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

Guest(hist_02):501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

...[snip]

我想从中得到两件事:

Domain\USER (So first string before the ":")

和实际的哈希:

"aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0"

我在想这样的事情:

import sys

infile, outfile = sys.argv[1], sys.argv[2]

with open(infile) as inf, open(outfile,"w") as outf:
    line_words = (line.split('::') for line in inf)
    outf.writelines(words[1].strip() + '\n' for words in line_words if len(words)>1)

但不知何故,我只解析了第一个哈希。

任何帮助将不胜感激 !

谢谢

4

1 回答 1

1

问题是你正在分裂"::"。尝试拆分":"。只有第一行符合这种格式。第 2 行及以后的行在两个:s 之间有一个数字,这与您的算法不符。

试试这个(更详细的可读性):

with open(infile) as inf, open(outfile,"w") as outf:
    for line in inf:
        splits = line.split(":")
        user, hash = splits[0], ":".join(splits[2:4])
        outf.write(hash + '\n')

希望有帮助

于 2012-07-04T02:39:22.350 回答