Table of Contents
回复内容:
Home Backend Development Python Tutorial 为什么 sqlmap 源码看起来那么费劲?

为什么 sqlmap 源码看起来那么费劲?

Jun 06, 2016 pm 04:22 PM
python sqlmap

最近在看sqlmap的源码,参考了乌云上的源码分析,可是越看越混乱,想提升在python编程方面的能力,该怎么办?

回复内容:

谢邀,是这样的:

1. 首先你应该搞懂它的架构体系,模块与分层,设计模式等。说白了,你得懂软件工程。

我为什么会在技能表里特别推荐读它的源码,绝不仅它的 SQL 注射能力一流,还因为它的软件工程牛逼到不行。你可以想象下,能打造如此稳定的框架工具已经不是件简单的事。如果你深入下去就会发现里面处处是软件工程那些优秀思想,关于这点比起曾经的 w3af 不知道要牛逼多少倍,后来 w3af 卧薪尝胆搞了次重写,才有现在的地位。

这个软件工程举些具体的点吧,比如并发,如果你连什么是并发,什么是线程、锁、条件、信号、超时、异常等概念都不懂;再复杂点并发里进程、线程、协程的差异是什么;再再复杂点 Python GIL、垃圾回收、性能陷阱;再再再复杂点 Python 那些内置模块、第三方模块的 ugly 点的 hack,看到这些源码你估计会哭死…哦,对了,如果你并不熟 Python,那么那些 Pythonic 的技巧估计也会让你怀疑自己、怀疑世界…

说的题外话:如果你把 sqlmap 当产品来读,还能读出更多东西;如果你把 sqlmap 当作开源社区运作模式来读,又能读出更多东西。如果不是因为它的开源运作、产品、软件工程、SQL 注射的一流,我们也不会持续用它并提交贡献代码与 Bugs 反馈。

正因为这种优秀,你要读的东西可多了,当然难!

2. 要吃透 sqlmap,还有一个非常关键的是,熟练 SQL 注射各类技术与技巧,熟练基于 SQL 的后续渗透技巧,sqlmap 支持几乎所有主流数据库的注射。

这又是一大难题。如果你不熟悉,你绝对想不到它为什么那样发包,为什么那样处理…

哦,对了,如果你并不是一名渗透手,你绝对难以思考到为什么 sqlmap 集成了那一堆技巧。

3. 虽然有人写了些小而美的工具来比拼 sqlmap 的一些不足,但还是向 sqlmap 致敬,他们在不断改进。

以上是我从事黑客工程化数年经验的一些回馈。不用怕,啃久了自然熟。

最后,./sqlmap.py -h 开启一个纵深知识领域吧:)

-----------

补充下,这就是为什么我们有些源码风格类似 sqlmap,吸收好的。

计划在我公众号(lazy-thought)里展开写写 sqlmap 和一些优秀的 Python 黑客工具,仅计划而已,感兴趣那关注吧。 最近,一直在做内部的分布式集群扫描器,有机会集中精力的阅读了一下SQLMap代码,在完全兼容SQLMap Payloads的基础上重新实现了SQL扫描器。
SQLMap做为一款工具是非常优秀的,但不适合做集群并发,所以要重写。

从软件设计上来说,层次是很清晰的,但具体的代码实现上有不太优雅的地方,尤其是regex用的太多(我不太喜欢用regex)。

包括几个方面:

1、和所有的程序一样,启动的时候要先装在配置和初始化系统变量,其中重要的两个配置是payloads 和 dbms相关的信息;
payloads中分为两部分: boundary 和 testing 。。很重要
2、对payloads的管理,当给出一个url,如何获得污染的url,这个过程比较复杂
3、网络控制部分;
4、http 响应分析,这个部分和 如何污染关系很大;
5、逻辑判断,涉及到很多算法

一般过程:

1、先猜测dbms,具体实现就是用一段可以导致Database出错的参数注入进去,根据响应输出来找到对应的dbms,很可能找不到,就盲注入。。。
2、进行不同的payloads注入,主要包括以下几个:
payload的注入很有意思,根据参数值的类型(数值,字符串),有些请求还要进行SQL转意,比如: Error-Based/UNION Query,原因很简单,避免干扰对输出的分析。比如 :CONCAT(0x20,,)这样的函数,如果被执行了,就是一个字符串。
2.1 Error-based : 一般分析不到dbms,基本上也无法实现Error-based,分析原理很简单,看响应输出是否有特定的字符串;
2.2 Boolean-based: 通过成对的逻辑真和逻辑假(仅是可能)构造请求,根据每次的响应输出,对比内容的差异范围。。。
2.3 QUNION Query: 在枚举列的时候那个算法很精妙;
2.4 Timer-based: 根据多次的rt,经过方差算法,推断,这个受网络影响比较大,在获取dbname 处的算法和Boolean-based一样,算法也是很精妙的,其实就是枚举+二分法。


随便简单写了一些,希望对你有帮助。SQLMap是个很好的工具,但没有那么复杂,只要花点时间阅读代码,可以搞懂的。

对了,还需要了解各种数据库知识,里面涉及到很多数据库相关的知识。。。 @余弦 副总裁的答案已经很详细了,老夫虽常偏责他,但也颇为认同他的回答并已赞之。

总的来说,如果你只是想用 sqlmap,那么多看看多试试
python sqlmap.py -hh
Copy after login
不懂架构和oo方面的东西,看一千行以上的代码绝对费劲。而且你可以或许大概之前并没有读过这种量级的代码。 越难得越有价值,当然,这得符合你的价值尺度,通俗地说,就是对你现在或者以后有没有用,如果你是一个做应用的那么没啥用,如果你是一个py程序员那么可用,再或者你是信息安全爱好者那么好用,再或者你是黑帽py那么很适合,嗯,你既然都想读了,那就是你承认了它的价值,那么就静下心来吧,其实吧,我感觉难是浮躁表现的一种形式,拿出决心来要得就是那种不到黄河不死心的决心,好吧,其实我不懂py-_-#,只是路过。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the conversion speed fast when converting XML to PDF on mobile phone? Is the conversion speed fast when converting XML to PDF on mobile phone? Apr 02, 2025 pm 10:09 PM

The speed of mobile XML to PDF depends on the following factors: the complexity of XML structure. Mobile hardware configuration conversion method (library, algorithm) code quality optimization methods (select efficient libraries, optimize algorithms, cache data, and utilize multi-threading). Overall, there is no absolute answer and it needs to be optimized according to the specific situation.

How to convert XML files to PDF on your phone? How to convert XML files to PDF on your phone? Apr 02, 2025 pm 10:12 PM

It is impossible to complete XML to PDF conversion directly on your phone with a single application. It is necessary to use cloud services, which can be achieved through two steps: 1. Convert XML to PDF in the cloud, 2. Access or download the converted PDF file on the mobile phone.

What is the function of C language sum? What is the function of C language sum? Apr 03, 2025 pm 02:21 PM

There is no built-in sum function in C language, so it needs to be written by yourself. Sum can be achieved by traversing the array and accumulating elements: Loop version: Sum is calculated using for loop and array length. Pointer version: Use pointers to point to array elements, and efficient summing is achieved through self-increment pointers. Dynamically allocate array version: Dynamically allocate arrays and manage memory yourself, ensuring that allocated memory is freed to prevent memory leaks.

Is there a mobile app that can convert XML into PDF? Is there a mobile app that can convert XML into PDF? Apr 02, 2025 pm 09:45 PM

There is no APP that can convert all XML files into PDFs because the XML structure is flexible and diverse. The core of XML to PDF is to convert the data structure into a page layout, which requires parsing XML and generating PDF. Common methods include parsing XML using Python libraries such as ElementTree and generating PDFs using ReportLab library. For complex XML, it may be necessary to use XSLT transformation structures. When optimizing performance, consider using multithreaded or multiprocesses and select the appropriate library.

How to convert XML to PDF on your phone? How to convert XML to PDF on your phone? Apr 02, 2025 pm 10:18 PM

It is not easy to convert XML to PDF directly on your phone, but it can be achieved with the help of cloud services. It is recommended to use a lightweight mobile app to upload XML files and receive generated PDFs, and convert them with cloud APIs. Cloud APIs use serverless computing services, and choosing the right platform is crucial. Complexity, error handling, security, and optimization strategies need to be considered when handling XML parsing and PDF generation. The entire process requires the front-end app and the back-end API to work together, and it requires some understanding of a variety of technologies.

How to convert xml into pictures How to convert xml into pictures Apr 03, 2025 am 07:39 AM

XML can be converted to images by using an XSLT converter or image library. XSLT Converter: Use an XSLT processor and stylesheet to convert XML to images. Image Library: Use libraries such as PIL or ImageMagick to create images from XML data, such as drawing shapes and text.

How to convert XML to PDF on your phone with high quality? How to convert XML to PDF on your phone with high quality? Apr 02, 2025 pm 09:48 PM

Convert XML to PDF with high quality on your mobile phone requires: parsing XML in the cloud and generating PDFs using a serverless computing platform. Choose efficient XML parser and PDF generation library. Handle errors correctly. Make full use of cloud computing power to avoid heavy tasks on your phone. Adjust complexity according to requirements, including processing complex XML structures, generating multi-page PDFs, and adding images. Print log information to help debug. Optimize performance, select efficient parsers and PDF libraries, and may use asynchronous programming or preprocessing XML data. Ensure good code quality and maintainability.

How to convert XML to PDF on Android phone? How to convert XML to PDF on Android phone? Apr 02, 2025 pm 09:51 PM

Converting XML to PDF directly on Android phones cannot be achieved through the built-in features. You need to save the country through the following steps: convert XML data to formats recognized by the PDF generator (such as text or HTML); convert HTML to PDF using HTML generation libraries such as Flying Saucer.

See all articles