Understanding PATH(√)

简介: Understanding PATH(√)

export修改环境变量:

  1. export PATH=/home/hacker/win 直接覆盖PATH环境变量
  2. export PATH=$PATH:/home/hacker/win 表示在原来环境变量基础上增加。


如果想要使用加入环境变量的sh脚本作为新命令,记得添加可执行权限!:

chmod +x /home/hacker/win/win

PATH变量

描述

  事实证明,“贝壳是如何找到的?”的答案相当简单。 有一个特殊的 shell 变量,称为 ,它存储了一堆目录路径,shell 将在其中搜索与命令对应的程序。 如果你把变量留空,事情就会变得很糟糕:lsPATH
hacker@dojo:~$ ls
Desktop    Downloads  Pictures  Templates
Documents  Music      Public    Videos
hacker@dojo:~$ PATH=""
hacker@dojo:~$ ls
bash: ls: No such file or directory
hacker@dojo:~$

如果没有 PATH,bash 将找不到该命令。ls

在此级别中,您将中断程序的运行。 该程序将使用命令删除标志文件。 但是,如果找不到命令,则不会删除标志,挑战会将其交给您! 因此,您必须使它也找不到命令!/challenge/runrmrm/challenge/runrm

请记住:将是 shell 的_子进程_,因此您必须应用您在 Shell 变量中学到的概念来弄乱其变量! 如果您没有成功,并且标志被删除,您将需要重新开始挑战才能重试!/challenge/runPATH

bypass

hacker@path~the-path-variable:~$ PATH=""
hacker@path~the-path-variable:~$ echo $PATH

hacker@path~the-path-variable:~$ /challenge/run
Trying to remove /flag...
/challenge/run: line 4: rm: Is a directory
The flag is still there! I might as well give it to you!
pwn.college{EgZYoM11mHS0MOMMKFLxt_zyd0n.dZzNwUDLwYTM2QzW}

#将PATH置空即可,run脚本检测到flag依然存在后,会直接调用cat程序来打印flag
# /bin/cat /flag

设置PATH变量

描述

例如,让我们探讨一下如何将新的程序目录添加到我们的命令库中。
回想一下,它存储了一个目录列表,用于查找命令,对于非标准位置的命令,
我们通常必须通过它们的路径执行它们:PATH

hacker@dojo:~$ ls /home/hacker/scripts
goodscript  badscript okayscript
hacker@dojo:~$ goodscript
bash: goodscript: command not found
hacker@dojo:~$ /home/hacker/scripts/goodscript
YEAH! This is the best script!
hacker@dojo:~l
如果您维护有用的脚本,希望能够以裸名称启动,这很烦人。 但是,
通过在此列表中添加目录或替换目录,您可以公开这些程序,以使用它们的裸名称启动! 例如:

hacker@dojo:~$ PATH=/home/hacker/scripts
hacker@dojo:~$ goodscript
YEAH! This is the best script!
hacker@dojo:~$
让我们练习一下。 此级别将通过其裸名称运行命令,但此命令存在于目录中,
该目录最初不在 PATH 中。 该命令是唯一需要的,因此您可以用该目录覆盖。 
祝你好运!/challenge/runwin/challenge/more_commands/win/challenge/runPATH

bypass

hacker@path~setting-path:~$ PATH=/challenge/more_commands
hacker@path~setting-path:~$ /challenge/run
Invoking 'win'....
Congratulations! You properly set the flag and 'win' has launched!
pwn.college{YlGlUhizRIiMQizSFo6wdhUP34k.dVzNyUDLwYTM2QzW}

添加命令

描述

回想一下上一关的示例:

hacker@dojo:~$ ls /home/hacker/scripts
goodscript  badscript okayscript
hacker@dojo:~$ PATH=/home/hacker/scripts
hacker@dojo:~$ goodscript
YEAH! This is the best script!
hacker@dojo:~$
当然,我们在这里看到的是通过将自己的命令带到派对上来使外壳对自己更有用。 
随着时间的流逝,您可能会积累自己的优雅工具。 让我们从开始吧!hackerwin

以前,执行的命令存储在 . 这一次,不存在了! 回想一下 Chaining Commands 的最后一关,
并制作一个名为 的 shell 脚本,将其位置添加到 中,并启用以找到它!

的功能很简单:作为 运行,所以可以简单地将标志文件。 同样,该命令是唯一需要的,
因此您可以用该目录覆盖。 但请记住,如果这样做,您的命令将无法找到 
您有三种选择可以避免它:

1.弄清楚程序在文件系统上的位置。它必须位于变量中的目录中,因此您可以打印出变量
(请参阅 Shell 变量以记住如何!),并遍历其中的目录(回想一下,不同的条目是分隔的),
找到其中的条目,并按其绝对路径调用。catPATH:catcat

2.设置一个包含旧目录和新条目的任意位置。$PATH:win

3.使用(再次,请参阅 Shell 变量)读取 。由于是 的内置功能,因此不受恶作剧的影响。
read/flagreadbashPATH  现在,去吧!win

概要:新建shell脚本命名为win,用于打印flag;赋予可执行权限并加入环境变量PATH,接着启动run程序,调用win命令得到flag。

Tips:环境变量问题

1. 如果选择覆盖PATH变量,则无法调用cat命令【会查不到】,但是可以使用read命令读取【不受环境变量影响】

2. 如果选择在原始PATH后面添加,则可以正常调用命令。

bypass

hacker@path~adding-commands:~$ chmod+x /home/hacker/win/win
hacker@path~adding-commands:~$ export PATH=$PATH:/home/hacker/win
hacker@path~adding-commands:~$ cat /home/hacker/win/win

#!/bin/bash
cat /flag
#exec 3</flag
#read -r flag <&3
#eho "$flag"
#exec 3<&-c

hacker@path~adding-commands:~$ which win
/home/hacker/win/win
hacker@path~adding-commands:~$ /challenge/run
Invoking 'win'....
pwn.college{I-cz9xg8Pvtt3yfjkgnEJu2iOAG.dZzNyUDLwYTM2QzW}

劫持命令

描述

有了你的知识,你现在可以进行一些恶作剧了。 此挑战与本模块中的第一个挑战几乎相同。 同样,此质询将使用命令删除标志。 
但与以前不同的是,它不会为您打印任何东西。rm

你怎么能解决这个问题? 您知道在变量中列出的目录中搜索它。 
您具有在上一个挑战需要时创建命令的经验。 你还能创造什么?rmPATHwin

bypass

hacker@path~hijacking-commands:~/rm$ cat rm

#!/bin/sh
cat /flag
                                       # 首先编写rm的shell脚本打印/flag,然后赋予可执行权限,加入环境变量
hacker@path~hijacking-commands:~/rm$ chmod +x /home/hacker/rm/rm
hacker@path~hijacking-commands:~/rm$ export PATH=$PATH:/home/hacker/rm/rm
hacker@path~hijacking-commands:~/rm$ which rm
/run/current-system/sw/bin/rm

hacker@path~hijacking-commands:~/rm$ which rm
/usr/bin/rm
hacker@path~hijacking-commands:~/rm$ which rm
/bin/rm

# 接着查看rm命令命中位置,依次删除相应的环境变量
 
hacker@path~hijacking-commands:~/rm$ which rm
bash: which: command not found

# 发现删除了/usr/bin后bash也不能命中,尝试选择将该环境变量放在末尾

hacker@path~hijacking-commands:~/rm$ PATH="
nix/store/7qh3vj8xvp66kslcy9q3zkl8jna2wfhm-code-service/libexec/code-server/lib/vscode/bin/remote-cli:
/run/challenge/bin:
/usr/local/sbin:
/usr/local/bin:
/usr/sbin:/sbin:
/home/hacker/rm:
/usr/bin/
"

hacker@path~hijacking-commands:~/rm$ which rm           # 命中编写的rm命令,方法可行。运行run程序即可
/home/hacker/rm/rm

hacker@path~hijacking-commands:~/rm$ /challenge/run
Trying to remove /flag...
Found 'rm' command at /home/hacker/rm/rm. Executing!
pwn.college{wS4H73j6by7oFV3cfkCQGC8fay2.ddzNyUDLwYTM2QzW}


目录
相关文章
|
机器学习/深度学习 编解码 测试技术
UPerNet:Unified Perceptual Parsing for Scene Understanding论文解读
人类在多个层面上识别视觉世界:我们毫不费力地对场景进行分类并检测内部物体,同时还识别物体的纹理和表面及其不同的组成部分。
202 0
Understanding the Conditions for Deadlock Formation
Deadlock formation in concurrent systems can be a challenging problem to identify and resolve. By understanding the conditions for deadlock formation and adopting appropriate prevention and handling strategies, developers can ensure the smooth execution of concurrent applications while minimizing th
48 0
《NATURAL LANGUAGE UNDERSTANDING WITH MACHINE ANNOTATORS & DEEP LEARNED ONTOLOGIES AT SCALE》电子版地址
NATURAL LANGUAGE UNDERSTANDING WITH MACHINE ANNOTATORS & DEEP LEARNED ONTOLOGIES AT SCALE
88 0
《NATURAL LANGUAGE UNDERSTANDING WITH MACHINE ANNOTATORS & DEEP LEARNED ONTOLOGIES AT SCALE》电子版地址
|
搜索推荐 PyTorch 算法框架/工具
Re30:读论文 LegalGNN: Legal Information Enhanced Graph Neural Network for Recommendation
Re30:读论文 LegalGNN: Legal Information Enhanced Graph Neural Network for Recommendation
Re30:读论文 LegalGNN: Legal Information Enhanced Graph Neural Network for Recommendation
|
机器学习/深度学习 自然语言处理 PyTorch
Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro
|
JavaScript 前端开发 vr&ar
Use Augmented Reality technology to bring enhanced customer experience
Use Augmented Reality technology to bring enhanced customer experience
110 0
Use Augmented Reality technology to bring enhanced customer experience
|
Linux Windows
6 Effective Methods to Learn New Technologies Faster
Technology is always evolving, and developers need to learn new products and languages faster to cope with these changes.
6275 0
6 Effective Methods to Learn New Technologies Faster
|
Java 关系型数据库 Linux