Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.00 KB | None | 0 0
  1. # Launch ettercap like this: (run in same directory as shepherd)
  2. # sudo ettercap -Tq -d >> etter.log
  3.  
  4. import threading, json, logging, time
  5.  
  6. from src.comms     import Communication
  7. from src.lib       import log
  8. from src.webserver import HTTPServer
  9. from honeypot      import Honeypot
  10.  
  11. class Shepherd:
  12.  
  13.     def __init__(self):
  14.         self.client_threads = []
  15.         self.clients = []
  16.         self.wall_of_sheep = []
  17.  
  18.     def banner(self):
  19.         print()
  20.         print("        _                _                  _         _   ___  ")
  21.         print("    ___| |__   ___ _ __ | |__   ___ _ __ __| | __   _/ | / _ \ ")
  22.         print("   / __| '_ \ / _ \ '_ \| '_ \ / _ \ '__/ _` | \ \ / / || | | |")
  23.         print("   \__ \ | | |  __/ |_) | | | |  __/ | | (_| |  \ V /| || |_| |")
  24.         print("   |___/_| |_|\___| .__/|_| |_|\___|_|  \__,_|   \_/ |_( )___/ ")
  25.         print("    - Web based - |_| - Deep packet inspection tool  - |/      ")
  26.         print()
  27.  
  28.     def main(self):
  29.         self.banner()
  30.         logging.getLogger('WS-Server').setLevel(logging.CRITICAL)
  31.         logging.getLogger('Communication').setLevel(logging.CRITICAL)
  32.         #logging.getLogger('WS-Server').setLevel(logging.DEBUG)
  33.  
  34.         t = threading.Thread(target = EttercapParser, args = (self,))
  35.         t.start()
  36.  
  37.         t = threading.Thread(target = Honeypot, args = (self,))
  38.         t.start()
  39.  
  40.         listen_address = "127.0.0.1"
  41.         listen_port    = 5555
  42.  
  43.         self.Server = Communication()
  44.         self.Server.start(listen_address, listen_port)
  45.  
  46.         print("Websocket server listening on port %d..." % listen_port)
  47.         print()
  48.  
  49.         #starts web server:
  50.         t = threading.Thread(target = HTTPServer, args = (8080,))
  51.         t.start()
  52.  
  53.         while 1:
  54.             sock = self.Server.accept()
  55.             if not sock: break
  56.  
  57.             t = threading.Thread(target = Client, args = (sock, self))
  58.             self.client_threads.append(t)
  59.             t.start()
  60.  
  61. class Client(threading.Thread):
  62.  
  63.     def __init__(self, Socket, Shepherd):
  64.         threading.Thread.__init__(self)
  65.         Shepherd.clients.append(self)
  66.  
  67.         self.Socket = Socket
  68.         self.Shepherd = Shepherd
  69.         self.ettercap_feed = None
  70.  
  71.         print("WebSocket Client connected from %s" % self.Socket.remote_address)
  72.         self.handle()
  73.  
  74.     def handle(self):
  75.         while 1:
  76.             obj = self.Socket.recv()
  77.             data = obj.data
  78.             if data['type'] == 'close': break
  79.  
  80.             if data['type'] == "get_sheep":
  81.                 obj.send(self.Shepherd.wall_of_sheep)
  82.  
  83.             if data['type'] == "start_ettercap_feed":
  84.                 self.ettercap_feed = obj
  85.  
  86.             if data['type'] == "stop_ettercap_feed":
  87.                 self.ettercap_feed = None
  88.  
  89.         print("WebSocket Client disconnected!")
  90.  
  91.  
  92.  
  93. class EttercapParser(threading.Thread):
  94.  
  95.     def __init__(self, Shepherd):
  96.         threading.Thread.__init__(self)
  97.         self.Shepherd = Shepherd
  98.         self.parse("etter.log")
  99.  
  100.     def parse(self, file):
  101.  
  102.         print("Ettercap parser started!")
  103.  
  104.         with open(file, "r") as f:
  105.             lines = f.readlines()
  106.             for line in lines:
  107.                 #print(line, end="")
  108.                 self.parse_line(line)
  109.  
  110.             while 1:
  111.                 lines = f.readlines()
  112.                 if lines:
  113.                     for line in lines:
  114.                         #print(line, end="")
  115.                         self.parse_line(line)
  116.                 time.sleep(0.1)
  117.  
  118.     def parse_line(self, line):
  119.         if line.startswith("HTTP"):
  120.             self.parse_HTTP_cred(line)
  121.  
  122.     def parse_HTTP_cred(self, line):
  123.  
  124.         #HTTP : 162.13.83.46:80 -> USER: cats  PASS: secretpass  INFO: http://www.copyscape.com/login.php
  125.  
  126.         i = 7
  127.         line = line[7:]
  128.         i = line.find(" ")
  129.         ip = line[:i]
  130.         line = line[i:]
  131.         line = line[10:]
  132.         i = line.find(" ")
  133.         user = line[:i]
  134.         line = line[i:]
  135.         line = line[8:]
  136.         i = line.find(" ")
  137.         password = line[:i]
  138.         line = line[i:]
  139.         line = line[8:]
  140.         i = line.find("\n")
  141.         info = line[:i]
  142.  
  143.         if len(info) >= 40:
  144.             info = info[:40] + "..."5
  145.  
  146.         if not password: return
  147.  
  148.         data = {
  149.             'protocol': "HTTP",
  150.             'login': user,
  151.             'password': password,
  152.             'ip': ip,
  153.             'info': info
  154.         }
  155.         self.Shepherd.wall_of_sheep.append(data)
  156.         self.notify_clients(data)
  157.  
  158.     def notify_clients(self, data):
  159.         for client in self.Shepherd.clients:
  160.             if client.ettercap_feed:
  161.                 client.ettercap_feed.send(data)
  162.  
  163. herd = Shepherd()
  164. try:
  165.     herd.main()
  166. except KeyboardInterrupt:
  167.     pass
  168.     print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement