Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlmapApi学习 #69

Open
PyxYuYu opened this issue Dec 20, 2016 · 5 comments
Open

SqlmapApi学习 #69

PyxYuYu opened this issue Dec 20, 2016 · 5 comments

Comments

@PyxYuYu
Copy link
Owner

PyxYuYu commented Dec 20, 2016

With the wonder of your love, the sun above always shines.

0x01 DSScan

  • 开始填第一个坑,之前一直想结合 SqlmapApiDjango 来做个小工具进行批量扫描检测
  • SqlmapApi 简介
    • 利用 sqlmapapi.py 开启服务端口,只要向 sqlmapapi 发送请求就可以进行 sql 注入检测
    • 查看 sqlmapapi.py 文件
       from lib.utils.api import server
       
       # ...
       
       if args.server is True:
           server(args.host, args.port, adapter=args.adapter)
    • 和服务端交互的方法,需要查看 lib/utils/api.py 文件
        # Users' methods  用户方法
        @get("/task/new") 创建新的任务
        @get("/task/<taskid>/delete") 删除指定任务
        
        # Admin functions 管理函数
        @get("/admin/<taskid>/list") 查看所有任务列表并显示扫描状态
        @get("/admin/<taskid>/flush") 刷新删除所有任务
        
        # sqlmap core interact functions 核心交互函数
        @get("/option/<taskid>/list") 列出指定任务列表的选项和各参数
        @post("/option/<taskid>/get") 获取指定任务的选项
        @post("/option/<taskid>/set") 设置指定任务的选项
        @post("/scan/<taskid>/start") 指定任务开始扫描
        @get("/scan/<taskid>/stop") 指定任务停止扫描
        @get("/scan/<taskid>/kill") 结束指定任务
        @get("/scan/<taskid>/status") 查看指定任务的状态
        @get("/scan/<taskid>/data") 查看指定任务的扫描数据data有内容说明存在注入
        @get("/scan/<taskid>/log/<start>/<end>") 查看指定任务的扫描日志从start到end
        @get("/scan/<taskid>/log") 查看指定任务的扫描日志
        @get("/download/<taskid>/<target>/<filename:path>") 下载任务文件
    • python sqlmapapi.py -h 查看帮助
    • python sqlmapapi.py -s 运行服务端 (s -- server
       C:\Python27\sqlmap>python sqlmapapi.py -s
       [17:08:35] [INFO] Running REST-JSON API server at '127.0.0.1:8775'..
       [17:08:35] [INFO] Admin ID: 8340df43d7b579a961813c10c8140922
       [17:08:35] [DEBUG] IPC database: c:\users\admini~1\appdata\local\temp\sqlmapipc-i_s50s
       [17:08:35] [DEBUG] REST-JSON API server connected to IPC database
       [17:08:35] [DEBUG] Using adapter 'wsgiref' to run bottle
    • 通过 sqlmapapi.py 文件可以得到, -s 命令后面还可以接 -H -P 命令
      • -H : host 自定义域名
      • -P : port 自定义端口
    • 上面没有接任何其他命令,默认运行在 127.0.0.1:8775sqlmapapi 用的后端依赖于 Bottle (一个非常小巧但高效的微型 Python Web 框架)
    • Admin ID 用于管理 sqlmapapi 的使用,即管理 taskid ,在新建 sqlmap 任务的时候,这个 Admin ID 没有什么作用,只是在查看任务和删除任务的时候才有用
    • 运行服务端后,使用上面的交互方式,查看一下基本用法
      • 创建任务
        • 用户方法: @get("/task/new")
        • 打开另一个 cmd 窗口,输入
           C:\Users\Administrator>python
           Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32
           Type "help", "copyright", "credits" or "license" for more information.
           >>> import json
           >>> import requests
           >>> resp = requests.get('http://127.0.0.1:8775/task/new')
           >>> resp.json
           <bound method Response.json of <Response [200]>>
           >>> resp.json()
           {u'success': True, u'taskid': u'ee0433a686f236a5'}
           >>>
        • 成功创建任务, 任务idtaskid ,之前打开 cmd 窗口(开启服务端)中会返回成功创建的信息
           [17:52:19] [DEBUG] Created new task: 'ee0433a686f236a5'
      • 任务创建完成,需要设置指定选项( url 等,之后就可以展开扫描)
        • 核心交互函数: @post("/option/<taskid>/set")
        • 注意是 post 方法
           >>> resp = requests.post('http://127.0.0.1:8775/option/ee0433a686f236a5/set', data=json.dumps({'url': 'http://xxx.xxx.xxx/xxx/?id=1'}), headers={'Content-Type': 'application/json'})
           >>> resp.json()
           {u'success': True}
        • 同样,在服务端的 cmd 窗口会显示
           [17:55:23] [DEBUG] [ee0433a686f236a5] Requested to set options
      • 设置完选项后,开始扫描
        • 核心交互函数: @post("/scan/<taskid>/start")
        • 依旧是 post 方法,函数参数内容同上,只是第一个参数改变内容为 /scan/.../start
           >>> resp = requests.post('http://127.0.0.1:8775/scan/ee0433a686f236a5/start', data=json.dumps({'url': 'http://xxx.xxx.xxx/xxx/?id=1'}), headers={'Content-Type': 'application/json'})
           >>> resp.json()
           {u'engineid:2384', u'success': True}
        • 服务端的 cmd 显示
           [17:58:23] [DEBUG] [ee0433a686f236a5] Started scan
      • 查看任务状态,判断扫描是否结束
        • 核心交互函数: @get("/scan/<taskid>/status")
           >>> resp = requests.get('http://127.0.0.1:8775/scan/ee0433a686f236a5/status')
           >>> resp.json()
           {u'status': u'terminated', u'returncode': 0, u'success': True}
           >>>
        • terminated: 表示扫描结束
        • running: 表示扫描运行中
        • 服务端的 cmd 显示
           [18:03:15] [DEBUG] [ee0433a686f236a5] Retrieved scan status
      • 查看扫描结果
        • 核心交互函数: @get("/scan/<taskid>/data")
           >>> resp = requests.get('http://127.0.0.1:8775/scan/ee0433a686f236a5/data')
           >>> resp.json()
           {u'data': 此处省略 ...}
        • data 有数据返回,说明存在注入,如果没有数据(结果为空),不存在注入
        • 服务端的 cmd 显示
           [18:05:15] [DEBUG] [ee0433a686f236a5] Retrieved scan data and error messages
      • 删除任务
        • 用户方法: @get("/task/<taskid>/delete")
           >>> resp = requests.get('http://127.0.0.1:8775/task/ee0433a686f236a5/delete')
           >>> resp.json()
           {u'success': True}
        • 服务端的 cmd 显示
           [18:07:15] [DEBUG] [ee0433a686f236a5] Deleted task
@tesla4321
Copy link

dump怎么搞?

@needle-wang
Copy link

needle-wang commented Apr 27, 2019

dump怎么搞?

set dump选项就行了.

sqlmapapi本质上是 可以批量运行sqlmap --batch 的工具,
用得最多的是 "批量扫描是否有漏洞".

@needle-wang
Copy link

@get("/admin/<taskid>/list")
@get("/admin/<taskid>/flush")
应该改为:
@get("/admin/<token>/list")
@get("/admin/<token>/flush")

@wangjuelong
Copy link

sqlmapapi只能检测get请求吗?post请求如何进行?get请求中的cookie如何写入?

@needle-wang
Copy link

sqlmapapi只能检测get请求吗?post请求如何进行?get请求中的cookie如何写入?

  1. 也能使用其他请求方式 如post,
  2. 所有支持的选项在 sqlmap/lib/core/optiondict.py中, 跟sqlmap -hh显示的功能一致.
  3. 平时怎么用sqlmap, sqlmapapi也能(不过是后台额外加了个--batch选项),
    将所要的选项写成json, 传给requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants