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

Python寫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 方法啟動應用程序的事件循環。

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。