Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create cyber security in python #12424

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions cyber security in python
Original file line number Diff line number Diff line change
@@ -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


Loading