Python实现密码字典的提取
时间: 2023-11-29 08:35:32 浏览: 163
密码字典是用于猜测或爆破密码的工具,可以从多种数据源中提取。以下是使用Python实现密码字典提取的示例代码:
1. 从常见密码列表中提取
```python
passwords = ['password', '123456', 'qwerty', 'letmein'] # 常见密码列表
with open('passwords.txt', 'w') as f:
for pwd in passwords:
f.write(pwd + '\n') # 写入文件
```
2. 从字典文件中提取
```python
with open('dictionary.txt', 'r') as f:
words = [line.strip() for line in f]
with open('passwords.txt', 'w') as out:
for word in words:
for sep in ['', '.', '-', '_']:
out.write(word + sep + '\n') # 写入文件
```
3. 从网站中提取常用密码
```python
import requests
from bs4 import BeautifulSoup
url = 'http://www.passwordrandom.com/most-popular-passwords'
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
passwords = [elem.text.strip() for elem in soup.find_all('td', class_='txt')]
with open('passwords.txt', 'w') as f:
for pwd in passwords:
f.write(pwd + '\n') # 写入文件
```
注意:使用密码字典进行非授权访问或攻击是违法行为,请勿滥用。
阅读全文