sqlmap简介

sqlmap是一个开源的渗透测试工具,可以用来探测sql注入漏洞。

sqlmap的源码

sqlmap源码就像是九阴真经一样,梅超风只是偷看了九阴真经的皮毛,就可以在江湖上掀起一阵腥风血雨,哪怕只是掌握sqlmap的一点点精髓,也是可以益寿延年。sqlmap和九阴真经最大的不同是,sqlmap是开源的,学了sqlmap没有人会打断你的腿,只要你想要去学习,并付出努力就能够有收获。

我依然记得,当初看mycli的一小部分代码,学到click这个包的使用,然后自己写了一个基于click的命令行切换注册表工具,着实不错。

通过sqlmap这个工具的使用,结合sqlmap的源码,学习下sql是怎么注入的?这个工具又是如何实现的。

记得一次面试,我提到使用sqlmap来进行sql注入的尝试,面试官听到这里气色为之一振,我想这应该也是加分点吧。

言归正传,下面就是我阅读sqlmap源码的过程。

从sqlmap.py的main函数开始,往下阅读。

在banner函数中看到了如下的代码,给我看迷糊了

1、if not any 和 any的使用

两个列表,A和B,你想看看,A中的元素是否在B中出现过

if not any(_ in sys.argv for _ in ("--version", "--api"))
any(_ in sys.argv for _ in ("--disable-coloring", "--disable-colouring"))

2、globals()的使用
提升成为全局变量

        for _ in ("cmdLineOptions", "conf", "kb"):globals()[_] = getattr(sys.modules["lib.core.data"], _)

sqlmap是如何解析命令行参数的?

cmdLineParser这个函数是回答此问题的关键, This function parses the command line parameters and arguments
sys.argv

对应的解析这块
命令行的输出

对应的源码

如何使用 sqlmap的gui界面?

在没有看源码之前,我有想过,写个GUI界面,内部调用sqlmap,可是当我看到这里的时候,我笑了,原来sqlmap是自带gui界面的,差点就做了重复工作。

init()函数中做了哪些操作?

_useWizardInterface() 对应于sqlmap --wizard模式

sqlmap中的数据类型AttribDict

lib.core.datatype.py中定义了AttribDict,几十行代码。。。

class AttribDict(dict):"""This class defines the dictionary with added capability to access members as attributes>>> foo = AttribDict()>>> foo.bar = 1>>> foo.bar1"""def __init__(self, indict=None, attribute=None, keycheck=True):if indict is None:indict = {}# Set any attributes here - before initialisation# these remain as normal attributesself.attribute = attributeself.keycheck = keycheckdict.__init__(self, indict)self.__initialised = True# After initialisation, setting attributes# is the same as setting an itemdef __getattr__(self, item):"""Maps values to attributesOnly called if there *is NOT* an attribute with this name"""try:return self.__getitem__(item)except KeyError:if self.keycheck:raise AttributeError("unable to access item '%s'" % item)else:return Nonedef __setattr__(self, item, value):"""Maps attributes to valuesOnly if we are initialised"""# This test allows attributes to be set in the __init__ methodif "_AttribDict__initialised" not in self.__dict__:return dict.__setattr__(self, item, value)# Any normal attributes are handled normallyelif item in self.__dict__:dict.__setattr__(self, item, value)else:self.__setitem__(item, value)def __getstate__(self):return self.__dict__def __setstate__(self, dict):self.__dict__ = dictdef __deepcopy__(self, memo):retVal = self.__class__()memo[id(self)] = retValfor attr in dir(self):if not attr.startswith('_'):value = getattr(self, attr)if not isinstance(value, (types.BuiltinFunctionType, types.FunctionType, types.MethodType)):setattr(retVal, attr, copy.deepcopy(value, memo))for key, value in self.items():retVal.__setitem__(key, copy.deepcopy(value, memo))return retVal

sqlmap的logger是怎么使用的?

命令行中的-v参数,会决定logger的级别。

logger的定义在lib.core.data和lib.core.log中。
日志格式
FORMATTER = logging.Formatter("\r[%(asctime)s] [%(levelname)s] %(message)s", “%H:%M:%S”)
LOGGER = logging.getLogger(“sqlmapLog”)
LOGGER_HANDLER = logging.StreamHandler(sys.stdout)
LOGGER_HANDLER.setFormatter(FORMATTER)
LOGGER.addHandler(LOGGER_HANDLER)
LOGGER.setLevel(logging.INFO)
logger = LOGGER
这段代码看下来还是比较简单的,是一个比较基本的logging的使用。


参考文章
https://zhuanlan.zhihu.com/p/391930824
https://www.freebuf.com/column/232047.html
https://cloud.tencent.com/developer/article/1040203

sqlmap源码入门笔记系列相关推荐

  1. .NetCore源码阅读笔记系列之Security (一) Authentication AddCookie

    如果你使用过.NetCore开发过程序,你会很清楚,在其中我们经常会用到一些如下的代码 services.AddAuthentication(options =>{options.Default ...

  2. sqlmap源码阅读系列检查是否满足依赖

    sqlmap --dependencies 可以用来检查sqlmap需要使用的一些依赖是否满足. 通过阅读源码我们知道了,核心是__import__()函数. 异常:ImportError __imp ...

  3. 【大数据入门笔记系列】第六节 分布式计算框架MapReduce的工作流程

    [大数据入门笔记系列]第六节 分布式计算框架MapReduce的工作流程 前言 MapReduce分布式运算 MapReduceApplication MapTask ReduceTask split ...

  4. 深度学习入门笔记系列(三)——感知器模型和 tensorboard 的使用方法

    本系列将分为 8 篇 .今天是第三篇 .主要讲讲感知器模型和 tensorboard 的基本使用方法 . 1. 感知器模型 因为小詹之前写过一篇感知器模型的介绍 ,这里就不赘述了 .有需要巩固的点击如 ...

  5. 深度学习入门笔记系列 ( 二 )——基于 tensorflow 的一些深度学习基础知识

    本系列将分为 8 篇 .今天是第二篇 .主要讲讲 TensorFlow 框架的特点和此系列笔记中涉及到的入门概念 . 1.Tensor .Flow .Session .Graphs TensorFlo ...

  6. Android Dialer,Mms,Contacts源码修改笔记,移动端混合开发经验

    ②在AndroidManifest.xml中修改相应Activity的theme <activity android:name=".HomeActivity" android ...

  7. logback源码解读笔记(springboot)

    logback源码解读笔记(springboot) 一.Logfactory初始化 StaticLoggerBinder的初始化 二.springboot与logback整合 三.logger的执行与 ...

  8. syzkaller 源码阅读笔记1(syz-extract syz-sysgen)

    文章目录 1. syz-extract 1-0 总结 1-1. `main()` 1-2 `archList()` - `1-1 (3)` 获取架构 name list 1-3 `createArch ...

  9. Clamav杀毒软件源码分析笔记[九]

    Clamav杀毒软件源码分析笔记[九] 刺猬@http://blog.csdn.net/littlehedgehog [数据流病毒扫描] 数据流病毒扫描,听上去貌似很牛逼的称呼,其实就是一个传送数据流 ...

最新文章

  1. linux上安全狗的安装
  2. warning:partition X does not end on cylinder boundary
  3. Science:人类在实验室创建了微型“大脑”,含祖先基因的那种
  4. 2018批量打印开关_新品上市,震撼来袭!买UV平板打印机,一定看过这款后再定!...
  5. Flink 1.12 资源管理新特性回顾
  6. AliOS Things基于USB通道外接4G模组的方案
  7. tomcat运行模式(bio,aio,apr)
  8. redis主线程阻塞的情形
  9. 【慢慢学算法】:八进制(vector练习)
  10. day078_鼠标动起来
  11. oc宏定义的简单理解
  12. MariaDB—— 14.存储引擎
  13. 10个在工作中常用的表格函数
  14. matplotlib pyqt4
  15. 怎么把ogg转成mp3格式?
  16. 电脑iphone,如何从 iPhone 传输图片到电脑
  17. aix查看lv_AIX中的硬盘、PP、VG、LV、文件系统
  18. 汽车行业部件IPX9K高温高压喷水试验测试
  19. html中数字效果,使用css实现电子数字效果
  20. 3.3.9 反相积分电路

热门文章

  1. Linux tail命令:显示文件结尾的内容
  2. 【笔试面试题】腾讯2013实习生面试算法题及参考答案
  3. pptx给幻灯片添加内容
  4. python-json模块
  5. 新手零基础入门小程序之万达电影
  6. 面对微信小程序的威胁,支付宝可以考虑安心做B2C的社交了
  7. 因政府禁令 微软 Windows 9 将作出重大调整
  8. 2015 年出现的十大流行 Python 库
  9. 2014 中华架构师大会 回想
  10. TypeScript BigInt