import requests
from bs4 import BeautifulSoup
def test_xss(url):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
input_fields = soup.find_all('input')
for field in input_fields:
data = {field['name']: "<script>alert('XSS')</script>"}
r = requests.post(url, data=data)
if "<script>alert('XSS')</script>" in r.text:
print(f"Potential XSS vulnerability found at {url} for input field {field['name']}")
test_xss('http://example.com/login')
import pandas as pd
import re
# Пример логов
logs = pd.read_csv('/var/log/auth.log', sep=' ', header=None)
failed_attempts = logs[logs[0].str.contains('Failed password', na=False)]
print(failed_attempts)
from scapy.all import sniff
def packet_callback(packet):
if packet.haslayer('IP'):
print(f"Packet captured: {packet[IP].src} -> {packet[IP].dst}")
sniff(prn=packet_callback, filter="ip", store=0)
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
# Генерация ключа
key = get_random_bytes(16)
cipher = AES.new(key, AES.MODE_EAX)
# Шифрование данных
data = b'Hello, this is a secret message!'
ciphertext, tag = cipher.encrypt_and_digest(data)
# Дешифрование
cipher_dec = AES.new(key, AES.MODE_EAX, nonce=cipher.nonce)
decrypted_data = cipher_dec.decrypt_and_verify(ciphertext, tag)
print(f"Decrypted data: {decrypted_data.decode()}")
from passlib.hash import sha256_crypt
# Генерация пароля и его хэширование
password = 'mysecretpassword'
hashed_password = sha256_crypt.hash(password)
print(f"Hashed password: {hashed_password}")
# Проверка пароля
if sha256_crypt.verify(password, hashed_password):
print("Password is correct!")
else:
print("Incorrect password.")
import socket
def check_port(host, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = s.connect_ex((host, port))
if result == 0:
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")
check_port('localhost', 80)
import pyotp
# Генерация секретного ключа для двухфакторной аутентификации
totp = pyotp.TOTP('JBSWY3DPEHPK3PXP')
print("Current OTP:", totp.now()) # Вывод текущего одноразового пароля