From 03cf227c05e9542f0cea840b079d729b6ac2191e Mon Sep 17 00:00:00 2001 From: Vijay Yadav <135238089+vijayleo31@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:37:46 +0530 Subject: [PATCH] Create cyber security in python --- cyber security in python | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cyber security in python diff --git a/cyber security in python b/cyber security in python new file mode 100644 index 000000000000..79e5e7c22b17 --- /dev/null +++ b/cyber security in python @@ -0,0 +1,78 @@ +import scapy.all as scapy +import paramiko +import nmap +import requests +from bs4 import BeautifulSoup +from sklearn.model_selection import train_test_split +from sklearn.tree import DecisionTreeClassifier +import tensorflow as tf + + +def scan_ports(target): + nm = nmap.PortScanner() + nm.scan(target, '1-1024') # Scanning ports 1 to 1024 + return nm.all_hosts() + + +def sniff_packets(interface): + scapy.sniff(iface=interface, store=False, prn=process_packet) + +def process_packet(packet): + print(packet.summary()) + + +def scrape_website(url): + response = requests.get(url) + soup = BeautifulSoup(response.text, 'html.parser') + return [a['href'] for a in soup.find_all('a', href=True)] + + +def ssh_connect(host, username, password): + client = paramiko.SSHClient() + client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + client.connect(host, username=username, password=password) + stdin, stdout, stderr = client.exec_command('ls') + print(stdout.read().decode()) + client.close() + +def train_malware_classifier(data, labels): + X_train, X_test, y_train, y_test = train_test_split(data, labels, test_size=0.2) + clf = DecisionTreeClassifier() + clf.fit(X_train, y_train) + return clf.score(X_test, y_test) + +def build_model(): + model = tf.keras.Sequential([ + tf.keras.layers.Flatten(input_shape=(28, 28)), + tf.keras.layers.Dense(128, activation='relu'), + tf.keras.layers.Dense(10, activation='softmax') + ]) + model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) + return model + + +if __name__ == "__main__": + target = "192.168.1.1" + print("Scanning ports...") + print(scan_ports(target)) + + print("Sniffing packets...") + sniff_packets("eth0") + + print("Scraping website...") + print(scrape_website("http://example.com")) + + print("Connecting via SSH...") + ssh_connect("192.168.1.2", "user", "password") + + # Example data for malware detection + data = [[...]] # Replace with actual data + labels = [...] # Replace with actual labels + print("Training malware classifier...") + print(train_malware_classifier(data, labels)) + + print("Building and training deep learning model...") + model = build_model() + # Add code to train the model with data + +