banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

Pyhon写sqlmap注入批量检测工具

SQLMap 是一款功能强大的开源自动化 SQL 注入工具,旨在帮助渗透测试工程师快速发现和利用 SQL 注入漏洞。它具备自动化探测、漏洞利用和数据提取等功能。SQLMap 的主要功能是扫描、发现并利用给定 URL 中的 SQL 注入漏洞。它还内置了许多绕过插件,同时支持多种数据库,包括 MySQL、Oracle、PostgreSQL、Microsoft SQL Server、Microsoft Access、IBM DB2、SQLite、Firebird、Sybase 和 SAPMaxDB。通过使用 SQLMap,渗透测试工程师可以更高效地进行 SQL 注入漏洞的检测和利用。

下面基于 Python 写的批量检测工具,可以一次性导入多个网站的 URL 列表,并自动进行扫描。这样可以大大提高漏洞扫描的效率,节省时间和精力。
运行效果:

image
运行本程序前请确保已经在本机安装了 SQLMap,并将其添加到环境变量中, 这样可以方便您在任何目录下都能够使用此工具进行 SQL 注入检测。

import tkinter as tk
from tkinter import ttk
import tkinter.filedialog as fd
import subprocess
import threading


class Application(tk.Tk):
    def __init__(self, title, geometry):
        super().__init__()
        self.title(title)
        self.geometry(geometry)

        self.columns = ("URL", "Injection", "Payload")
        self.tree = ttk.Treeview(self, columns=self.columns, show="headings")

        for col in self.columns:
            self.tree.heading(col, text=col)
            self.tree.column(col, width=200, anchor="center")

        self.tree.pack(fill="both", expand=True)

        self.text_widget = tk.Text(self, height=20)
        self.text_widget.pack(fill="x")

        buttons_frame = tk.Frame(self)
        buttons_frame.pack(fill="x", pady=10)

        import_data_btn = tk.Button(buttons_frame, text="导入URL", command=self.import_data)
        import_data_btn.pack(side="left", padx=10)

        tk.Label(buttons_frame, text="sqlmap -u url --batch").pack(side="left")
        self.params_entry = tk.Entry(buttons_frame, width=50)
        self.params_entry.pack(side="left", padx=10)
        self.params_entry.insert(0, "--level 3")

        self.run_btn = tk.Button(buttons_frame, text="运行", command=self.run)
        self.run_btn.pack(side="left", padx=10)
        self.pause_btn = tk.Button(buttons_frame, text="暂停", command=self.pause)
        self.pause_btn.pack(side="left", padx=10)
        clear_btn = tk.Button(buttons_frame, text="清空", command=self.clear_content)
        clear_btn.pack(side="left", padx=10)

        self.is_paused = False
        self.thread = None

    def import_data(self):
        file_path = fd.askopenfilename(defaultextension=".txt", filetypes=[("Text Files", "*.txt")])
        if file_path:
            self.tree.delete(*self.tree.get_children())
            with open(file_path, "r") as file:
                for line in file:
                    line = line.strip().split(",")
                    self.tree.insert("", "end", values=line)

    def run(self):
        params = self.params_entry.get()
        self.run_btn.config(text="正在运行", state="disabled")
        self.pause_btn.config(state="normal")
        self.is_paused = False
        self.thread = threading.Thread(target=self._run_scan, args=(params,))
        self.thread.start()

    def pause(self):
        self.is_paused = True

    def _run_scan(self, params):
        for index, item in enumerate(self.tree.get_children()):
            if self.is_paused:
                self.run_btn.config(text="继续", state="normal")
                return

            url = self.tree.item(item)["values"][0]
            result = subprocess.run(['sqlmap', '-u', url] + params.split() + ['--batch'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8")
            result_output = result.stdout + result.stderr
            self.text_widget.insert(tk.END, result_output)
            self.text_widget.update_idletasks()
            if "Parameter: " in result_output:
                self.tree.set(item, "Injection", "Yes")
                payload_start = result_output.index("Payload:") + len("Payload:")
                payload_end = result_output.index("\n", payload_start)
                self.tree.set(item, "Payload", result_output[payload_start:payload_end].strip())
            else:
                self.tree.set(item, "Injection", "No")
        self.run_btn.config(text="运行", state="normal")
        self.pause_btn.config(state="disabled")

    def clear_content(self):
        self.text_widget.delete("1.0", "end")
        for item in self.tree.get_children():
            for column in self.columns:
                self.tree.set(item, column, "")


if __name__ == "__main__":
    app = Application("SQLMAP - 注入批量检测 ", "900x750")
    app.mainloop()

代码使用了 tkinter 库创建的 GUI 应用程序,用于批量检测 SQL 注入漏洞。它提供了一个用户界面,用户可以导入 URL 列表并运行检测,程序将自动检测每个 URL 是否存在 SQL 注入漏洞,并显示检测结果。

代码中的 Application 类继承自 tkinter 库的 Tk 类,代表了整个应用程序的窗口。在初始化方法中,设置了窗口的标题和大小,并创建了一个 Treeview 控件用于显示 URL、注入状态和 Payload 信息,以及一个 Text 控件用于显示检测结果。

应用程序的主要功能包括导入 URL 列表、运行检测、暂停检测和清空结果。其中,导入 URL 列表的方法 (import_data) 使用文件对话框选择一个文本文件,读取其中的 URL 列表,并将其插入到 Treeview 控件中。

运行检测的方法 (run) 获取用户输入的参数,并将运行按钮设置为不可用状态,暂停按钮设置为可用状态。然后创建一个新的线程,在该线程中调用_run_scan 方法进行检测。

在_run_scan 方法中,遍历 Treeview 控件中的每个 URL,如果暂停标志为 True,则停止检测。否则,使用 subprocess 库调用 sqlmap 命令进行检测,并将结果输出到 Text 控件中。根据检测结果,更新 Treeview 控件中的注入状态和 Payload 信息。最后,将运行按钮设置为可用状态,暂停按钮设置为不可用状态。

清空结果的方法 (clear_content) 用于清空 Text 控件和 Treeview 控件中的内容。

在主程序中,创建一个 Application 实例,并调用 mainloop 方法启动应用程序的事件循环,

最后,在主程序中创建一个 Application 实例,并调用 mainloop 方法启动应用程序的事件循环。

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。