SQLite 通过 Python 有多快
我只是好奇是否有人可以告诉我使用 SQLite 存储字典(如暴力破解)以在 Python 脚本中使用是否是一种有效的方法。虽然我对 Python 比较陌生,但我对其他编程语言确实有相当多的经验,并且目前正在开发一个用于 Backtrack 的渗透测试工具。到目前为止,Python 的速度和简单性给我留下了深刻的印象,而且我的 SQL 查询似乎非常理想地返回了我的暴力工具所需的前缀。然而,我想我想知道Python中存储大数据文件的标准是什么?我是否仅仅因为熟悉 SQL 而忽略了更好(更快)的前缀存储方式?请记住,我没有使用 Python 来查询 ID 0 到 n 并使用它们,而是使用 Python 来缩小可能性并查询那些符合条件的字典条目。任何帮助或意见将不胜感激!
I was just curious if anyone could tell me if using SQLite to store a dictionary (as in brute force) for use in a Python script was an efficient method. While I am relatively new to Python I do have quite a bit of experience with other programming languages and am currently working on a pentesting tool to use in Backtrack. So far I am quite impressed with the speed and simplicity of Python, and my SQL queries seem to be working pretty ideally to return the needed prefixes for my brute force tool. However, I guess what I'm wondering is what is the standard for storing large data files in Python? Am I overlooking a better (faster) way of storing my prefixes simply because of my comfort with SQL? Please bear in mind that I am not using Python to query IDs 0 through n and use them, rather I am using Python to narrow down the possibilities and query those dictionary entries that match the criteria. Any help or opinions would be much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,sqlite 是实现字典的合理选择。为了提高速度,请使用 :memory: 选项并确保为您的查找和查询创建适当的索引。
对于大型、持久性数据库,它也能很好地工作。为了速度,请注意提交大型事务而不是每个键。
他们的网站介绍了 sqlite 作为数据存储的建议和适当用途: http://www.sqlite.org /features.html
Yes, sqlite is a reasonable choice for implementing a dictionary. For speed, use the :memory: option and make sure to create the appropriate indexes for your lookups and queries.
For large, persistent databases it also works well. For speed, take care to commit large transactions instead of per-key.
The suggested and appropriate uses for sqlite as a datastore is covered at their website: http://www.sqlite.org/features.html
如果 Raymond Hettinger 也推荐 SQLite,那么这可能是您最好的选择。
但原生 Python 解决方案是使用“pickle”文件。您将构建一个保存数据的 Python
dict
,然后“pickle”该字典;稍后你可以“unpickle”这个字典。如果您只有一个键需要搜索,那么这可能是一个好方法。对于 Python 2.x,您可能需要使用
cPickle
模块。对于Python 3.x,只有pickle
,但我相信它和cPickle
一样快。http://docs.python.org/library/pickle.html
另一方面如果你的数据集确实很大,大到 SQLite 开始窒息,那么与其将其分割成多个较小的 SQLite 文件并管理它们,不如将所有内容转储到真正的数据库(例如 PostgreSQL)中可能是有意义的。
If Raymond Hettinger also recommends SQLite, then that's probably your best bet.
But a native Python solution would be to use a "pickle" file. You would build a Python
dict
that holds the data, then "pickle" the dict; later you could "unpickle" the dict. If you only have one key you need to search on, then this might possibly be a good way to go.For Python 2.x you would likely want to use the
cPickle
module. For Python 3.x, there is onlypickle
, but I believe it is as fast ascPickle
.http://docs.python.org/library/pickle.html
On the other hand if your data set is truly large, so large that SQLite is starting to choke on it, then instead of splitting it up into multiple smaller SQLite files and managing them, it might make sense to just dump everything into a real database such as PostgreSQL.
半题外话,这里有一些有用的链接。
THC-Hydra :P
这里还有一个关于密码策略和使用暴力破解的精彩视频。
http://www.irongeek .com/i.php?page=videos/hack3rcon2/martin-bos-your-password-policy-sucks
Semi off-topic, here are some useful links.
THC-Hydra :P
Also here is a great video on password policies and using then to brute force.
http://www.irongeek.com/i.php?page=videos/hack3rcon2/martin-bos-your-password-policy-sucks