MySQL注入 常用逻辑 学习 CentOS7
1.启动sqli-labs
[root@localhost ~]# docker run -dt --name sqli -p 80:80 --rm c0ny1/sqli-labs:0.1
2.进入mysql 容器
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e25df6506e31 c0ny1/sqli-labs:0.1 "/run.sh" 5 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp, 3306/tcp sqli
[root@localhost ~]# docker exec -it e25df6506e31 /bin/bash
root@e25df6506e31:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.47-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
3.开始练习
| system_user() | 系统用户名 |
|---|

| user | 用户名 |
|---|

| current_user() | 当前用户名 |
|---|

| session_user() | 连接数据库的用户名 |
|---|

| database() | 数据库名 |
|---|
mysql> select database();
±-----------+
| database() |
±-----------+
| NULL |
±-----------+
1 row in set (0.00 sec)
因为我们是通过系统直接进入的,并没有选择库,所以显示 Null
通过下面语句我们可以选择库
[root@localhost ~]#use 数据库名

| version() | 数据库版本号 |
|---|

| @@datadir | 数据库路径 |
|---|

| @@basedir | 数据库安装路径 |
|---|

| @@version_compile_os | 操作系统 |
|---|

| count | 返回执行结果数量 |
|---|

| concat | 没有分隔符连接字符串 |
|---|

| concat_ws() | 有分隔符连接字符串 |
|---|
0x7e 是~的十六进制

| group_concat() | 连接一个组的所有字符串,并以逗号分隔每一条数据 |
|---|

| into outfile | 写文件 |
|---|

| load_file() | 读取文件 |
|---|

| ascii () | 返回字符串的ASCII代码值 |
|---|

| ord | 返回字符串第一个字符的ASCII代码值 |
|---|

| mid() | 返回一个字符串的一部分 |
|---|
1.字符串
2.起始位置
3.长度


| substr() | 返回一个字符串的一部分 |
|---|
和 mid 相似

| length() | 返回字符串的长度 |
|---|

| left() | 返回字符串最左边几个字符 |
|---|

| floor() | 返回小于等于x的最大整数 |
|---|

| rand() | 返回0到1之间的一个随机数 |
|---|

| extrachvalue() | 第一个参数: XML_document是String格式,为XML文档对象的名称,文中为Doc |
|---|---|
| 第二个参数:XPath string(Xpath格式的字符串 | |
| 作用:从目标XML中返回所包含所查询的字符串) |
| updatexml | 第一个参数: XML_document是String格式,为XML文档对象的名称,文中为Doc |
|---|---|
| 第二个参数:XPath string(Xpath格式的字符串 | |
| 第三个参数:new_value,String格式,替换查找到的符合条件的数据 | |
| 作用:改变文档中符合条件节点的值 |
参考资料:
https://www.w3school.com.cn/xpath/index.asp
| sleep | 让语句运行N秒钟 |
|---|

| if() | > SELECT IF(1>2,2,3)–>3 |
|---|---|
1.表达式
2.若表达式为真,返回第二个参数
3.若表达式为假,返回第三个参数

| char | 返回整数ASCII代码字符组成的字符串 |
|---|

| strcmp() | 比较字符串大小 |
|---|

| ifnull() | 若参数1不为null则返回参数1,否则返回参数2 |
|---|

| exp() | 返回e的N次方 |
|---|

更多学习可以到这里继续:
https://dev.mysql.com/doc/refman/5.7/en/dynindex-function.html
本文详细介绍了在CentOS7环境下使用sqli-labs进行MySQL注入练习的方法,包括启动和进入sqli-labs容器、基本SQL函数如system_user(), user(), current_user(), session_user(), database(), version(), @@datadir, @@basedir等的使用,以及如何利用count(), concat(), group_concat(), into outfile, load_file(), ascii(), mid(), substr(), length(), left(), floor(), rand(), extrachvalue(), updatexml(), sleep(), if(), char(), strcmp(), ifnull(), exp()等函数进行数据库信息的获取和操作。
2026

被折叠的 条评论
为什么被折叠?



